该函数返回记录在 symbol 属性列表中、对应 property 属性下的文档字符串。它最常用于查找变量的文档字符串,此时 property 为 variable-documentation。此外,它也可用于查找其他类型的文档,例如自定义组的文档(但函数文档请使用下文的 documentation 函数)。
若属性值指向存储在 DOC 文件或字节编译文件中的文档字符串,该函数会查找并返回该字符串。
若属性值不为 nil、不是字符串,且不指向文件中的文本,则会将其作为 Lisp 表达式求值以得到字符串。
最后,该函数会通过 substitute-command-keys 处理字符串,替换其中的按键绑定(see 文档中的按键绑定替换)。若 verbatim 非 nil,则跳过此步骤。
(documentation-property 'command-line-processed
'variable-documentation)
⇒ "Non-nil once command line has been processed"
(symbol-plist 'command-line-processed)
⇒ (variable-documentation 188902)
(documentation-property 'emacs 'group-documentation)
⇒ "Customization of the One True Editor."
该函数返回 function 的文档字符串。它支持普通函数、宏、命名键盘宏以及特殊形式。
若 function 为符号,该函数会先查找该符号的 function-documentation 属性;若该属性值非 nil,则文档取自该值(若值不是字符串,则对其求值)。
若 function 不是符号,或没有 function-documentation 属性,则 documentation 会从实际的函数定义中提取文档字符串,必要时从文件中读取。
最后,除非 verbatim 非 nil,否则该函数会调用 substitute-command-keys。处理结果即为要返回的文档字符串。
若 function 无函数定义,documentation 会触发 void-function 错误。但函数定义没有文档字符串是允许的,此时 documentation 返回 nil。
documentation 使用的泛化函数,用于从函数对象中提取原始文档字符串。你可以为特定类型的函数添加对应的方法,以指定其文档字符串的获取方式。
该函数以面孔的形式返回 face 的文档字符串。
下面是一个使用 documentation 与 documentation-property 两个函数,在 *Help* 框架中显示多个符号文档字符串的示例。
(defun describe-symbols (pattern)
"Describe the Emacs Lisp symbols matching PATTERN.
All symbols that have PATTERN in their name are described
in the *Help* buffer."
(interactive "sDescribe symbols matching: ")
(let ((describe-func
(lambda (s)
;; Print description of symbol. (if (fboundp s) ; It is a function. (princ (format "%s\t%s\n%s\n\n" s (if (commandp s) (let ((keys (where-is-internal s))) (if keys (concat "Keys: " (mapconcat 'key-description keys " ")) "Keys: none")) "Function")
(or (documentation s)
"not documented"))))
(if (boundp s) ; It is a variable.
(princ
(format "%s\t%s\n%s\n\n" s
(if (custom-variable-p s)
"Option " "Variable")
(or (documentation-property
s 'variable-documentation)
"not documented"))))))
sym-list)
;; Build a list of symbols that match pattern.
(mapatoms (lambda (sym)
(if (string-match pattern (symbol-name sym))
(setq sym-list (cons sym sym-list)))))
;; Display the data.
(help-setup-xref (list 'describe-symbols pattern)
(called-interactively-p 'interactive))
(with-help-window (help-buffer)
(mapcar describe-func (sort sym-list)))))
describe-symbols 函数的功能与 apropos 类似,但提供的信息更详细。
(describe-symbols "goal") ---------- Buffer: *Help* ---------- goal-column Option Semipermanent goal column for vertical motion, as set by ...
minibuffer-temporary-goal-position Variable not documented
set-goal-column Keys: C-x C-n Set the current horizontal position as a goal for C-n and C-p.
Those commands will move to this position in the line moved to rather than trying to keep the same horizontal position. With a non-nil argument ARG, clears out the goal column so that C-n and C-p resume vertical motion. The goal column is stored in the variable ‘goal-column’. (fn ARG)
temporary-goal-column Variable Current goal column for vertical motion. It is the column where point was at the start of the current run of vertical motion commands. When moving by visual lines via the function ‘line-move-visual’, it is a cons cell (COL . HSCROLL), where COL is the x-position, in pixels, divided by the default column width, and HSCROLL is the number of columns by which window is scrolled from left margin. When the ‘track-eol’ feature is doing its job, the value is ‘most-positive-fixnum’. ---------- Buffer: *Help* ----------
该函数用于构建 Emacs 的过程中,即在可执行 Emacs 转储之前。它会查找存储在文件 filename 中的文档字符串位置,并将这些位置记录到函数定义与变量属性列表的内存中。See Building Emacs。
Emacs 从 emacs/etc 目录读取文件 filename。当转储后的 Emacs 后续运行时,会在 doc-directory 目录下查找同一文件。通常 filename 为 "DOC"。
该变量保存目录名称,该目录应包含文件 "DOC",其中存储了内置函数与变量的文档字符串。
多数情况下,该目录与 data-directory 相同。若你从构建目录直接运行 Emacs 而未执行安装,则二者可能不同。See Definition of data-directory。