我注意到我的代码中有一种(with-current-buffer ....
一遍又一遍地重复相同内容的趋势,所以我决定根据该宏定义定义一个宏with-current-buffer
——这就是我目前所拥有的:
(defmacro with-assembla-buffer(asm-buffer-name heading-str &rest body)
"Create buffer with name of ASM-BUFFER-NAME, or uses it if exists,
preps it with readonly/erase/heading - executes `body' - then puts
readonly back on, goes to beginning of buffer, and switches to it."
(with-current-buffer (get-buffer-create asm-buffer-name)
(assembla-mode)
(toggle-read-only -1)
(erase-buffer)
(insert (format "-- %s --------------------" heading-str))
(newline)
`(progn ,@body)
(toggle-read-only 1)
(goto-char (point-min))
(switch-to-buffer (current-buffer))))
this 的主体永远不会被执行,但是当它切换到defun
而不是defmacro
is 时,它确实可以完美地工作。因此,除了为什么 body 从未执行之外,我的另一个问题是 -这作为宏比 defun 更有意义吗?