我在emacs的配置文件中写了一个elisp宏,但是就像,(intern (format "%s-display-table" name))
所示的东西被多次使用一样,如何使用类似变量的东西来表示它呢?
;; Change the glyphs of "wrap", "truncation" and "vertical-border" in the display table specified by
;; parameter "name", obviously "↩", "…" and "ǁ" is better choice than the default values "\", "$"
;; and "|".
(defmacro change-glyphs-of-display-table (name)
`(lambda ()
(interactive)
(unless ,(intern (format "%s-display-table" name))
(setq ,(intern (format "%s-display-table" name)) (make-display-table)))
(set-display-table-slot ,(intern (format "%s-display-table" name)) 'wrap ?\↩)
(set-display-table-slot ,(intern (format "%s-display-table" name)) 'truncation ?\…)
(set-display-table-slot ,(intern (format "%s-display-table" name)) 'vertical-border ?\ǁ)))
答案 0 :(得分:2)
使用name
作为宏的参数,您知道它在扩展时始终可用,因此您可以在反引号形式之外对其进行处理:
;; Change the glyphs of "wrap", "truncation" and "vertical-border" in the display table specified by
;; parameter "name", obviously "↩", "…" and "ǁ" is better choice than the default values "\", "$"
;; and "|".
(defmacro change-glyphs-of-display-table (name)
(let ((namedisplaytable (intern (format "%s-display-table" name))))
`(lambda ()
(interactive)
(unless ,namedisplaytable
(setq ,namedisplaytable (make-display-table)))
(set-display-table-slot ,namedisplaytable 'wrap ?\↩)
(set-display-table-slot ,namedisplaytable 'truncation ?\…)
(set-display-table-slot ,namedisplaytable 'vertical-border ?\ǁ))))