eval-after-load

当我使用wl-install-elisp-from-emacswiki更新anythinganything-config之后,发现我对它们做的定制不见了。

解决方法是使用eval-after-load,在每次加载一个文件的时候运行一段代码,如下:

(eval-after-load 'anything
  '(progn
     (setq anything-enable-digit-shortcuts t)
     (global-set-key (kbd "<f9>") 'anything)))

(eval-after-load 'anything-config
  '(add-to-list 'anything-sources anything-c-source-file-cache))

注意,第二个参数是个list,一定要quote,不然他们会立刻执行。

Find elisp function definition

使用find-func,可以快速定位emacs lisp函数定义,配置如下:

(require 'find-func)
(find-function-setup-keys)

快捷键如下:

(defun find-function-setup-keys ()
  "Define some key bindings for the find-function family of functions."
  (define-key ctl-x-map "F" 'find-function)
  (define-key ctl-x-4-map "F" 'find-function-other-window)
  (define-key ctl-x-5-map "F" 'find-function-other-frame)
  (define-key ctl-x-map "K" 'find-function-on-key)
  (define-key ctl-x-map "V" 'find-variable)
  (define-key ctl-x-4-map "V" 'find-variable-other-window)
  (define-key ctl-x-5-map "V" 'find-variable-other-frame))

以前都是傻傻地使用C-h f,然后把光标移到*Help* buffer里面的相应链接上,最后按回车。有了find-func,无需移动光标了。摘一段注释

The funniest thing about this is that I can’t imagine why a package so obviously useful as this hasn’t been written before!!