19.2.15.4 规范示例

通过研究下面的示例,能更容易理解 Edebug 规范。

假设有一个宏 my-test-generator,用于对提供的数据列表执行测试。 虽然由 edebug-eval-macro-args 控制(see 宏调用插桩), Edebug 默认不会将参数当作代码插桩,但显式说明这些参数是数据会更清晰:

(def-edebug-spec my-test-generator (&rest sexp))

特殊形式 let 包含一系列绑定和一个代码体。 每个绑定可以是一个符号,或是一个包含符号与可选表达式的子列表。 在下面的规范中,注意子列表内部的 gate,用于在找到子列表后禁止回溯。

(def-edebug-spec let
  ((&rest
    &or symbolp (gate symbolp &optional form))
   body))

Edebug 为 defun 及其关联的参数列表和 interactive 规范使用下面的定义。 必须特殊处理 interactive 形式,因为它的表达式参数实际在函数体之外求值。 (defmacro 的规范与 defun 非常相似,只是多支持 declare 语句。)

(def-edebug-spec defun
  (&define name lambda-list
           [&optional stringp]   ; Match the doc string, if present.
           [&optional ("interactive" interactive)]
           def-body))

(def-edebug-elem-spec 'lambda-list
  '(([&rest arg]
     [&optional ["&optional" arg &rest arg]]
     &optional ["&rest" arg]
     )))

(def-edebug-elem-spec 'interactive
  '(&optional &or stringp def-form))    ; Notice: def-form

下面的反引号规范展示了如何匹配点分列表,以及如何用 nil 终止递归。 它还展示了如何匹配向量的各个成分。 (Edebug 实际定义的规范略有不同,并不支持点分列表,因为那样会导致可能失败的深层递归。)

(def-edebug-spec \` (backquote-form))   ; Alias just for clarity.

(def-edebug-elem-spec 'backquote-form
  '(&or ([&or "," ",@"] &or ("quote" backquote-form) form)
        (backquote-form . [&or nil backquote-form])
        (vector &rest backquote-form)
        sexp))

emacs

Emacs

org-mode

Orgmode

Donations

打赏

Copyright

© 2025 Jasper Hsu

Creative Commons

Creative Commons

Attribute

Attribute

Noncommercial

Noncommercial

Share Alike

Share Alike