21 天学会 Emacs 之第 19 天:Elisp 技巧

优酷视频地址:

百度网盘地址:

Spacemacs Rocks Season 2 (Day 19)

Topic: Elisp Hacking Tips

Generic tips

  1. hooks
  2. write elisp functions

Advice

;;mimic "nzz" behaviou in vim
(defadvice evil-search-next (after advice-for-evil-search-next activate)
  (evil-scroll-line-to-center (line-number-at-pos)))

(defadvice evil-search-previous (after advice-for-evil-search-previous activate)
  (evil-scroll-line-to-center (line-number-at-pos)))

Debug elisp functions

http://www.jianshu.com/p/f509c9a9cac0?hmsr=toutiao.io&utm_medium=toutiao.io&utm_source=toutiao.io

(defun aborn/debug-demo ()
  "debug demo function"
  (interactive)
  (let ((a "a")
        (b "value b")
        (c 1))
    (message "middle")
    (setq c (+ 1 c))
    (xyz "a")
    (message "ggg")
    ))

Write your own minor mode

http://nullprogram.com/blog/2013/02/06/

(define-minor-mode
  shadowsocks-proxy-mode
  :global t
  :init-value nil
  :lighter " SS"
  (if shadowsocks-proxy-mode
      (setq url-gateway-method 'socks)
    (setq url-gateway-method 'native)))


(define-global-minor-mode
  global-shadowsocks-proxy-mode shadowsocks-proxy-mode shadowsocks-proxy-mode
  :group 'shadowsocks-proxy)

旧的用 defadvice Advice 的方法从 24.4 起被新加入 nadvice.el 的代替了,后者更轻量级。我从 24.4 才开始用 Emacs 并且 ELisp manual 中没有 defadvice 的用法介绍,所以我一直都不会用 defadvice。好在也不必学了。

恩,多谢提醒,我后面也把我的配置中的 defadvice 换成 nadvice.el

求教如何debug啊。。。两个例子我都没成功,是因为改建了嘛。。。 还有edebug-instrument-defun-on如何使用呢?

最后一个SS已收藏