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
defun form), the
documentation string is specified after the argument list, and is
normally stored directly in the function object. See Documentation Strings of Functions. 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 Defining Global Variables. The string is stored in the variable’s
Sometimes, Emacs does not keep documentation strings in memory.
There are two such circumstances. Firstly, to save memory, the
documentation for primitive functions (see What Is a Function?) 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 Documentation Strings and Compilation). 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 Autoload), 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.)