emacs 進階:瞭解命令

weixin_33843409發表於2016-08-16

命令組成

由於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")

eshell的用法

elisp

快速入門

掌握基本語法規則後就應該多看人家寫的程式碼!
利用edebug更好更快地理解程式碼
假如想要知道開啟檔案是怎麼操作的。

  1. 首先定位函式的程式碼。

    • 已知快捷鍵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))))))
  2. 將游標放到函式名上,鍵入 C-u C-M-x可新增中斷入口。M-x edebug-mod開啟後會在選單欄多出edebug的選項。

  3. 使用命令C-x C-f便會觸發中斷。

  4. n可單步執行

IELM

這是一個很方便的工具。不同於M-x只能呼叫命令,IELM可以使用lisp語言,對於實現emacs擴充套件實在是太便捷了!

更多更詳細的內容還是得看文件!!

相關文章