emacs:如何在宏中定义的代码上使用edebug?
我甚至不知道这个lisp语法的正确术语,所以我不知道我用来提问的单词是否有意义。但我相信这个问题是有道理的 让我给你看看。cc模式(cc fonts.el)有一种称为“匹配器”的东西,它是运行以决定如何为一个代码区域设置字体的代码位。这听起来很简单,但matcher代码的形式我不完全理解,有backticks和逗号atsign,还有逗号等等,而且它嵌入了一个c-lang-defcost,它本身就是一个宏。我不知道该怎么称呼这些,但我想在代码上运行edebug 看:emacs:如何在宏中定义的代码上使用edebug?,emacs,lisp,Emacs,Lisp,我甚至不知道这个lisp语法的正确术语,所以我不知道我用来提问的单词是否有意义。但我相信这个问题是有道理的 让我给你看看。cc模式(cc fonts.el)有一种称为“匹配器”的东西,它是运行以决定如何为一个代码区域设置字体的代码位。这听起来很简单,但matcher代码的形式我不完全理解,有backticks和逗号atsign,还有逗号等等,而且它嵌入了一个c-lang-defcost,它本身就是一个宏。我不知道该怎么称呼这些,但我想在代码上运行edebug 看: (c-lang-defcon
(c-lang-defconst c-basic-matchers-after
"Font lock matchers for various things that should be fontified after
generic casts and declarations are fontified. Used on level 2 and
higher."
t `(;; Fontify the identifiers inside enum lists. (The enum type
;; name is handled by `c-simple-decl-matchers' or
;; `c-complex-decl-matchers' below.
,@(when (c-lang-const c-brace-id-list-kwds)
`((,(c-make-font-lock-search-function
(concat
"\\<\\("
(c-make-keywords-re nil (c-lang-const c-brace-id-list-kwds))
"\\)\\>"
;; Disallow various common punctuation chars that can't come
;; before the '{' of the enum list, to avoid searching too far.
"[^\]\[{}();,/#=]*"
"{")
'((c-font-lock-declarators limit t nil)
(save-match-data
(goto-char (match-end 0))
(c-put-char-property (1- (point)) 'c-type
'c-decl-id-start)
(c-forward-syntactic-ws))
(goto-char (match-end 0)))))))
(c-lang-defcont c-basic-matchers-after
“字体锁定匹配器,用于在
泛型强制转换和声明被格式化。用于级别2和
更高。”
t`(;;为枚举列表中的标识符设置字体。(枚举类型
;名称由“c-simple-decl-matchers”或
;“c-complex-decl-matchers”如下。
,@(当(c-lang-const c-brace-id-list-kwds)
`(,(c-make-font-lock-search-function)
(康卡特)
"\\"
不允许使用各种不能使用的常用标点符号
;在枚举列表的“{”之前,以避免搜索过远。
"[^\]\[{}();,/#=]*"
"{")
“((c-font-lock-declarators limit t nil)
(保存匹配数据
(转到字符(匹配结束0))
(c-put-char-property(1-(点))'c-type
‘c-decl-id-start)
(c-forward-syntatic-ws))
(转到字符(匹配结束0(()()()))))
我正在阅读lisp语法,以了解这些东西是什么以及如何调用它们,但除此之外,如何在注释后面的代码上运行edebug,该注释读取;;方化枚举列表中的标识符。
我知道如何在defun上运行edebug-只需在函数的定义中调用edebug defun
,然后我就可以了。我需要做什么来对cc模式匹配器代码表单进行edebug
def edebug spec
有什么作用,我会在这里使用它吗?如果是,如何使用?使用macroexpand
或macroexpand all
将其转换为无宏代码并像往常一样调试
Backticks&co可以通过一个例子来最好地说明:
(let ((a 1)
(b (list 2 3)))
`(a ,a ,b ,@b))
-> (a 1 (2 3) 2 3)
反勾号(或反引号`
)与引号(”
)类似,因为它阻止求值,只是它的效果可以用逗号(,
)有选择地撤消;,@
类似于,
,只是它的参数必须是列表,被拼接到结果列表中。根据(elisp)Top>Debugg>Edebug>Edebug和宏
您必须通过使用debug
语句定义宏或使用def Edebug spec
来告诉Edebug如何调试宏。这告诉它应该评估哪些参数,哪些不应该。这样就可以完成。事实上,看起来好像c-lang-defconst
已经完成了为edebug
安装。以下是您感兴趣时的定义:
(def-edebug-spec c-lang-defconst
(&define name [&optional stringp] [&rest sexp def-form]))
但是,如果您只想查看主体的计算结果,那么方法是使用下面的macro expand last sexp
查看结果。将光标定位在要展开的sexp之后(与C-x C-e
一样)然后运行M-x宏expand last sexp RET
。这将显示它被扩展到的内容。如果您尝试扩展类似、(..)
的内容,则可能会遇到问题,因此您可能必须将该sexp复制到其他地方并删除、
或、@
(defun macro-expand-last-sexp (p)
"Macro expand the previous sexp. With a prefix argument
insert the result into the current buffer and pretty print it."
(interactive "P")
(let*
((sexp (preceding-sexp))
(expanded (macroexpand sexp)))
(cond ((eq sexp expanded)
(message "No changes were found when macro expanding"))
(p
(insert (format "%S" expanded))
(save-excursion
(backward-sexp)
(indent-pp-sexp 1)
(indent-pp-sexp)))
(t
(message "%S" expanded)))))
我想这完全取决于您要做什么。已经有一段时间了,但我相信edebug可以处理backtick宏(`),以及它用于内联(、和@)的特殊构造正确地说。没有一种方法可以仅在定义中的子表达式上使用edebug。相反,您必须插入整个defun或顶级表达式。