Pretty print macro expansion

*scratch* buffer里面运行macroexpand展开宏后的程序全在一行,不好读,使用pp可以获得更好的效果。

(defun wl-pp-macroexpand-at-point ()
  (interactive)
  (pp-eval-expression '(macroexpand (read (thing-at-point 'sexp)))))

(define-key emacs-lisp-mode-map (kbd "C-c C-c") 'wl-pp-macroexpand-at-point)

将光标放在想要展开的宏调用的左括号前,调用该程序,宏展开的结果显示在*Pp Eval Output* buffer里。

如果想看宏调用执行后的结果,可以使用下面的函数。

(defun wl-pp-evaluate-at-point ()
  (interactive)
  (pp-eval-expression (macroexpand (read (thing-at-point 'sexp)))))

(define-key emacs-lisp-mode-map (kbd "C-c C-e") 'wl-pp-evaluate-at-point)

Emacs lisp unit test framework

几经修改,终于让evil eval里面提到的Emacs lisp单元测试框架成形了。你可以通过http://www.wanglianghome.org/svn/test/test.el查看或下载,也可以通过subversion。

$ svn co http://www.wanglianghome.org/svn/test

里面还有一个小例子和一张截屏

test和其它单元测试框架有两点不同,首先是抛弃了suite概念,而改用tag,同一个case可以属于多个tag;其次是通过一个test-assert-compare函数包含了所以已经实现和还没有实现的、二元assert功能,这使得整个代码无需很长(除去开头的文档,250行左右),却可以提供更多的功能,而且接口很一致。除此之外,还给用户提供了一定的扩展能力,使其能够编写更复杂的assert函数。

第一次在emacswiki上添加了属于自己的一笔,在UnitTest页面Automated testing frameworks一节的末尾。:-)