我甚至不知道这个lisp语法的正确术语,所以我不知道我用来问这个问题的词是否有意义.但这个问题很有道理,我敢肯定.
所以,让我告诉你.cc-mode(cc-fonts.el)有一些称为"匹配器"的东西,它们是用来决定如何形成代码区域的代码.这听起来很简单,但匹配器代码的形式我并不完全理解,带有反引号和逗号,只有逗号等等,而且它嵌入在c-lang-defcost中,它本身就是一个宏.我不知道该怎么称呼它,但我想在该代码上运行edebug.
看:
(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)))))))
Run Code Online (Sandbox Code Playgroud)
我正在读lisp语法来弄清楚那些东西是什么以及它们叫什么,但除此之外,我如何在读取的注释后面的代码上运行edebug ;; Fontify the identifiers inside enum lists. ?
我知道如何在defun上运行edebug - 只需edebug-defun在函数的定义中调用,然后关闭.我需要做些相应的事情才能对cc模式匹配器代码表进行edebug吗?
做了def-edebug-spec什么,我会在这里使用它吗?如果是这样,怎么样?
使用macroexpand或macroexpand-all将其转换为无宏代码并照常调试?
反引号 &co 可以通过一个例子来最好地说明:
(let ((a 1)
(b (list 2 3)))
`(a ,a ,b ,@b))
-> (a 1 (2 3) 2 3)
Run Code Online (Sandbox Code Playgroud)
反引号(或反引号`)与 quote( ) 类似',因为它可以阻止求值,但可以使用逗号 ( ,) 有选择地撤消其效果;和,@类似,,只不过它的参数必须是一个列表,并且被拼接到结果列表中。
根据(elisp)Top > Debugging > Edebug > Edebug and Macros你必须告诉 Edebug 如何通过使用语句定义宏debug或使用def-edebug-spec. 这告诉它哪些参数应该被评估,哪些不应该被评估。所以这是可以做到的。事实上,它看起来好像c-lang-defconst已经安装好了edebug。如果您感兴趣的话,这是定义:
(def-edebug-spec c-lang-defconst
(&define name [&optional stringp] [&rest sexp def-form]))
Run Code Online (Sandbox Code Playgroud)
但是,如果您只想查看主体的评估结果,那么方法是使用如下所示的内容macro-expand-last-sexp来查看结果。将光标放在要扩展的 sexp 之后(就像您所做的那样C-x C-e)并运行M-x macro-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)))))
Run Code Online (Sandbox Code Playgroud)
我想这取决于你想要做什么。