C-h S (info-lookup-symbol
) 可以查找某个符号在 info manual 中位置,是我常用的命令之一,尤其是在写 Emacs Lisp 的时候。它能工作在很多 major mode 下(其实主要取决于有没有相关的 info manual),在 Emacs 相关的 major mode 下,默认只用 emacs 和 elisp 这两个 manual [1],因此其它 manual 上的符号就找不到了,比如 C-h S cl-loop 就没效果。
透过参考 info.look.el
,我用下面的方法添加了 cl-lib、org-mode 和 magit 的 manual:
(use-package info-look
:defer t
:config
(info-lookup-add-help
:mode 'emacs-lisp-mode
:regexp "[^][()`'‘’,\" \t\n]+"
:doc-spec '(("(emacs)Command Index" nil "['`‘]\\(M-x[ \t\n]+\\)?" "['’]") ;
("(emacs)Variable Index" nil "['`‘]" "['’]")
("(elisp)Index" nil "^ -+ .*: " "\\( \\|$\\)")
;; cl-lib
("(cl) Function Index" nil "^ -+ .*: " "\\( \\|$\\)")
("(cl) Variable Index" nil "^ -+ .*: " "\\( \\|$\\)")
;; Org
("(org) Variable Index" nil "['`‘]" "['’]")
("(org) Command and Function Index" nil "['`‘(]" "['’)]")
;; Magit
("(magit) Command Index" nil "(['`‘]" "['’])")
("(magit) Variable Index" nil "^ -+ .*: " "\\( \\|$\\)"))))
如果还需要添加其它 manual 的话,只需要添加元素至 :doc-spec
,其格式是:
(INFO-NODE TRANS-FUNC PREFIX SUFFIX)
所以需要关注相应 Index 节点的名称,以及符号在 manual 中的格式。以 magit 的变量为例:"(magit) Variable Index"
是节点名,而前缀 "^ -+ .*: "
和后缀"\\( \\|$\\)"
则匹配了格式,比如,magit manual 中的变量都有这个的格式:
-- User Option: magit-git-debug
另外,如果你不用 use-package 的话,把 (use-package info-look :defer t :config ...)
换成 (with-eval-after-load ...)
即可。
1: 最近添加了 cl-lib 的 manual,Emacs 25.1 应该会包含这个修改。