25.1 Documentation Basics

A documentation string is written using the Lisp syntax for strings, with double-quote characters surrounding the text. It is, in fact, an actual Lisp string. When the string appears in the proper place in a function or variable definition, it serves as the function’s or variable’s documentation.

In a function definition (a lambda or defun form), the documentation string is specified after the argument list, and is normally stored directly in the function object. See 函数的文档字符串. You can also put function documentation in the function-documentation property of a function name (see Access to Documentation Strings).

In a variable definition (a defvar form), the documentation string is specified after the initial value. See 定义全局变量. The string is stored in the variable’s variable-documentation property.

Sometimes, Emacs does not keep documentation strings in memory. There are two such circumstances. Firstly, to save memory, the documentation for primitive functions (see 什么是函数?) and built-in variables is kept in a file named DOC, in the directory specified by doc-directory (see Access to Documentation Strings). Secondly, when a function or variable is loaded from a byte-compiled file, Emacs avoids loading its documentation string (see 文档字符串与编译). In both cases, Emacs looks up the documentation string from the file only when needed, such as when the user calls C-h f (describe-function) for a function.

Documentation strings can contain special key substitution sequences, referring to key bindings which are looked up only when the user views the documentation. This allows the help commands to display the correct keys even if a user rearranges the default key bindings. See Substituting Key Bindings in Documentation.

In the documentation string of an autoloaded command (see 自动加载), these key-substitution sequences have an additional special effect: they cause C-h f on the command to trigger autoloading. (This is needed for correctly setting up the hyperlinks in the *Help* buffer.)


emacs

Emacs

org-mode

Orgmode

Donations

打赏

Copyright

© 2025 Jasper Hsu

Creative Commons

Creative Commons

Attribute

Attribute

Noncommercial

Noncommercial

Share Alike

Share Alike