with-emacs: 在独立的 Emacs 进程中运行 elisp 代码

1. with-emacs 增加了 with-emacs-define-partially-applied

用这个宏来固定部分参数,免去每次都填写长参数的烦恼,例如:

(with-emacs-define-partially-applied
 (t      nil t)
 (24.3   \"/path/to/emacs-24.3\")
 (24.4-t \"/path/to/emacs-24.4\" t))

将生成以下宏定义,每个宏的参数列表都有些不同,因为有些参数已经固化了:

(with-emacs-t      &rest BODY &key PATH)
(with-emacs-24.3   &rest BODY &key LEXICAL)
(with-emacs-24.4-t &rest BODY)

使用时分别等效于:


(with-emacs :lexical t ...)
(with-emacs :path "/path/to/emacs-24.3" ...)
(with-emacs :path "/path/to/emacs-24.4" :lexical t ...)

2. 发布了新的包 ob-with-emacs

虽说可以直接在代码块中用 with-emacs,但由于 with-emacs 没有区分 print 和 message 输出,全部都显示在 *Message* 中了:

#+BEGIN_SRC emacs-lisp :results output
(with-emacs
  (print emacs-version))
#+END_SRC

#+RESULTS:
: print 没有输出

这点与 orgmode 默认行为是不同的。

所以还是要一个 ob-with-emacs,处理一下 print 输出结果。其实也正是之前写 with-emacs 的初衷:用来隔离 orgmode 中的 elisp block,防止污染当前 Emacs。

使用方法:

在 block 头部加上参数 :with-emacs "/path/to/{version}/emacs" (path 可选)

#+BEGIN_SRC emacs-lisp :results output :with-emacs
(print emacs-version)
#+END_SRC

如果定义了 partially applied 函数 (详见 with-emacs-define-partially-applied 文档),

#+BEGIN_SRC emacs-lisp :results output :with-emacs-24.3
(print emacs-version)
#+END_SRC
1 个赞