命令组成
由于emacs本身就是emacs lisp编写的,所以在emacs中一个命令其实就是一个函数。
(defun helm-M-x (_arg &optional command-name)
"Preconfigured `helm' for Emacs commands.
It is `helm' replacement of regular `M-x' `execute-extended-command'.
Unlike regular `M-x' emacs vanilla `execute-extended-command' command,
the prefix args if needed, can be passed AFTER starting `helm-M-x'.
When a prefix arg is passed BEFORE starting `helm-M-x', the first `C-u'
while in `helm-M-x' session will disable it.
You can get help on each command by persistent action."
快捷键 | 命令 | 说明 |
---|---|---|
M-! | shell-command |
使用系统shell 运行命令并输出到buffer "Shell Command Output" |
M- | shell-command-on-region |
运行Shell命令并输出到编辑区域 |
M-x | helm-M-x |
运行emacs命令 |
- | term |
打开buffer "terminal",运行终端 |
- | eshell |
创建一个交互式的Elisp shell。 |
可以通过设置shell-file-name
变量的值来改变默认shell
(setq shell-file-name "/bin/bash")
elisp
掌握基本语法规则后就应该多看人家写的代码!
利用edebug更好更快地理解代码
假如想要知道打开文件是怎么操作的。
-
首先定位函数的代码。
已知快捷键
C-x C-f
。依次键入C-h k C-x C-f
。
然后就会显示函数的信息,点击helm-files.el
就能看到代码。如果不知道快捷键,则键入
C-h a
,利用命令的名称来搜索可能的选项。
(defun helm-find-files (arg) "Preconfigured `helm' for helm implementation of `find-file'. Called with a prefix arg show history if some. Don't call it from programs, use `helm-find-files-1' instead. This is the starting point for nearly all actions you can do on files." (interactive "P") (let* ((hist (and arg helm-ff-history (helm-find-files-history))) (smart-input (or hist (helm-find-files-initial-input))) (default-input (expand-file-name (helm-current-directory))) (input (cond (helm-find-file-ignore-thing-at-point default-input) ((and (eq major-mode 'org-agenda-mode) org-directory (not smart-input)) (expand-file-name org-directory)) ((and (eq major-mode 'dired-mode) smart-input) (file-name-directory smart-input)) ((and (not (string= smart-input "")) smart-input)) (t default-input))) (input-as-presel (null (nth 0 (file-attributes input)))) (presel (helm-aif (or hist (and input-as-presel input) (buffer-file-name (current-buffer)) (and (eq major-mode 'dired-mode) smart-input)) (if helm-ff-transformer-show-only-basename (helm-basename it) it)))) (set-text-properties 0 (length input) nil input) (helm-find-files-1 input (and presel (null helm-ff-no-preselect) (concat "^" (regexp-quote presel))))))
将光标放到函数名上,键入
C-u C-M-x
可添加中断入口。M-x edebug-mod
开启后会在菜单栏多出edebug的选项。使用命令
C-x C-f
便会触发中断。n
可单步执行
IELM
这是一个很方便的工具。不同于M-x
只能调用命令,IELM可以使用lisp语言,对于实现emacs扩展实在是太便捷了!
更多更详细的内容还是得看文档!!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。