]> code.delx.au - gnu-emacs/blobdiff - lispref/help.texi
(Searching and Matching): Move node.
[gnu-emacs] / lispref / help.texi
index 7e5697c03fbdfe88ddd0de55ead343ed05a7d1a5..c7c99fa89870ade969c7162d3354157d3889dd72 100644 (file)
@@ -1,6 +1,7 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc. 
+@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2002, 2003,
+@c   2004, 2005 Free Software Foundation, Inc.
 @c See the file elisp.texi for copying conditions.
 @setfilename ../info/help
 @node Documentation, Files, Modes, Top
@@ -46,28 +47,34 @@ of a function or variable.  In a function definition, the documentation
 string follows the argument list.  In a variable definition, the
 documentation string follows the initial value of the variable.
 
-  When you write a documentation string, make the first line a complete
-sentence (or two complete sentences) since some commands, such as
-@code{apropos}, show only the first line of a multi-line documentation
-string.  Also, you should not indent the second line of a documentation
-string, if it has one, because that looks odd when you use @kbd{C-h f}
-(@code{describe-function}) or @kbd{C-h v} (@code{describe-variable}) to
-view the documentation string.  @xref{Documentation Tips}.
+  When you write a documentation string, make the first line a
+complete sentence (or two complete sentences) since some commands,
+such as @code{apropos}, show only the first line of a multi-line
+documentation string.  Also, you should not indent the second line of
+a documentation string, if it has one, because that looks odd when you
+use @kbd{C-h f} (@code{describe-function}) or @kbd{C-h v}
+(@code{describe-variable}) to view the documentation string.  There
+are many other conventions for doc strings; see @ref{Documentation
+Tips}.
 
   Documentation strings can contain several special substrings, which
 stand for key bindings to be looked up in the current keymaps when the
 documentation is displayed.  This allows documentation strings to refer
 to the keys for related commands and be accurate even when a user
-rearranges the key bindings.  (@xref{Accessing Documentation}.)
+rearranges the key bindings.  (@xref{Keys in Documentation}.)
 
   In Emacs Lisp, a documentation string is accessible through the
 function or variable that it describes:
 
 @itemize @bullet
 @item
-The documentation for a function is stored in the function definition
-itself (@pxref{Lambda Expressions}).  The function @code{documentation}
-knows how to extract it.
+@kindex function-documentation
+The documentation for a function is usually stored in the function
+definition itself (@pxref{Lambda Expressions}).  The function
+@code{documentation} knows how to extract it.  You can also put
+function documentation in the @code{function-documentation} property
+of the function name.  That is useful with definitions such as
+keyboard macros that can't hold a documentation string.
 
 @item
 @kindex variable-documentation
@@ -106,11 +113,15 @@ use to print nice-looking hardcopy for the file
 @section Access to Documentation Strings
 
 @defun documentation-property symbol property &optional verbatim
-This function returns the documentation string that is recorded
-in @var{symbol}'s property list under property @var{property}.  It
-retrieves the text from a file if necessary, and runs
-@code{substitute-command-keys} to substitute actual key bindings.  (This
-substitution is not done if @var{verbatim} is non-@code{nil}.)
+This function returns the documentation string that is recorded in
+@var{symbol}'s property list under property @var{property}.  It
+retrieves the text from a file if the value calls for that.  If the
+property value isn't @code{nil}, isn't a string, and doesn't refer to
+text in a file, then it is evaluated to obtain a string.
+
+The last thing this function does is pass the string through
+@code{substitute-command-keys} to substitute actual key bindings,
+unless @var{verbatim} is non-@code{nil}.
 
 @smallexample
 @group
@@ -126,10 +137,19 @@ substitution is not done if @var{verbatim} is non-@code{nil}.)
 @end defun
 
 @defun documentation function &optional verbatim
-This function returns the documentation string of @var{function}.  It
-reads the text from a file if necessary.  Then (unless @var{verbatim} is
-non-@code{nil}) it calls @code{substitute-command-keys}, to return a
-value containing the actual (current) key bindings.
+This function returns the documentation string of @var{function}.
+
+If @var{function} is a symbol, this function first looks for the
+@code{function-documentation} property of that symbol; if that has a
+non-@code{nil} value, the documentation comes from that value (if the
+value is not a string, it is evaluated).  If @var{function} is not a
+symbol, or if it has no @code{function-documentation} property, then
+@code{documentation} extracts the documentation string from the actual
+function definition, reading it from a file if called for.
+
+Finally, unless @var{verbatim} is non-@code{nil}, it calls
+@code{substitute-command-keys} so as to return a value containing the
+actual (current) key bindings.
 
 The function @code{documentation} signals a @code{void-function} error
 if @var{function} has no function definition.  However, it is OK if
@@ -142,6 +162,7 @@ Here is an example of using the two functions, @code{documentation} and
 @code{documentation-property}, to display the documentation strings for
 several symbols in a @samp{*Help*} buffer.
 
+@anchor{describe-symbols example}
 @smallexample
 @group
 (defun describe-symbols (pattern)
@@ -150,7 +171,7 @@ All symbols that have PATTERN in their name are described
 in the `*Help*' buffer."
   (interactive "sDescribe symbols matching: ")
   (let ((describe-func
-         (function 
+         (function
           (lambda (s)
 @end group
 @group
@@ -158,30 +179,30 @@ in the `*Help*' buffer."
             (if (fboundp s)             ; @r{It is a function.}
                 (princ
                  (format "%s\t%s\n%s\n\n" s
-                   (if (commandp s) 
+                   (if (commandp s)
                        (let ((keys (where-is-internal s)))
                          (if keys
                              (concat
                               "Keys: "
-                              (mapconcat 'key-description 
+                              (mapconcat 'key-description
                                          keys " "))
                            "Keys: none"))
                      "Function")
 @end group
 @group
-                   (or (documentation s) 
+                   (or (documentation s)
                        "not documented"))))
-            
+
             (if (boundp s)              ; @r{It is a variable.}
 @end group
 @group
                 (princ
                  (format "%s\t%s\n%s\n\n" s
-                   (if (user-variable-p s) 
+                   (if (user-variable-p s)
                        "Option " "Variable")
 @end group
 @group
-                   (or (documentation-property 
+                   (or (documentation-property
                          s 'variable-documentation)
                        "not documented")))))))
         sym-list)
@@ -189,7 +210,7 @@ in the `*Help*' buffer."
 
 @group
     ;; @r{Build a list of symbols that match pattern.}
-    (mapatoms (function 
+    (mapatoms (function
                (lambda (sym)
                  (if (string-match pattern (symbol-name sym))
                      (setq sym-list (cons sym sym-list))))))
@@ -211,7 +232,7 @@ but provides more information.
 (describe-symbols "goal")
 
 ---------- Buffer: *Help* ----------
-goal-column     Option 
+goal-column     Option
 *Semipermanent goal column for vertical motion, as set by @dots{}
 @end group
 @c Do not blithely break or fill these lines.
@@ -240,7 +261,13 @@ When the `track-eol' feature is doing its job, the value is 9999.
 @end group
 @end smallexample
 
+The asterisk @samp{*} as the first character of a variable's doc string,
+as shown above for the @code{goal-column} variable, means that it is a
+user option; see the description of @code{defvar} in @ref{Defining
+Variables}.
+
 @defun Snarf-documentation filename
+@anchor{Definition of Snarf-documentation}
 This function is used only during Emacs initialization, just before
 the runnable Emacs is dumped.  It finds the file offsets of the
 documentation strings stored in the file @var{filename}, and records
@@ -261,8 +288,7 @@ built-in and preloaded functions and variables.
 
 In most cases, this is the same as @code{data-directory}.  They may be
 different when you run Emacs from the directory where you built it,
-without actually installing it.  See @code{data-directory} in @ref{Help
-Functions}.
+without actually installing it.  @xref{Definition of data-directory}.
 
 In older Emacs versions, @code{exec-directory} was used for this.
 @end defvar
@@ -287,11 +313,11 @@ can also call that function yourself.
 stands for a key sequence that will invoke @var{command}, or @samp{M-x
 @var{command}} if @var{command} has no key bindings.
 
-@item \@{@var{mapvar}@} 
+@item \@{@var{mapvar}@}
 stands for a summary of the keymap which is the value of the variable
 @var{mapvar}.  The summary is made using @code{describe-bindings}.
 
-@item \<@var{mapvar}> 
+@item \<@var{mapvar}>
 stands for no text itself.  It is used only for a side effect: it
 specifies @var{mapvar}'s value as the keymap for any following
 @samp{\[@var{command}]} sequences in this documentation string.
@@ -316,13 +342,13 @@ user's own customized key bindings.
 
 @smallexample
 @group
-(substitute-command-keys 
+(substitute-command-keys
    "To abort recursive edit, type: \\[abort-recursive-edit]")
 @result{} "To abort recursive edit, type: C-]"
 @end group
 
 @group
-(substitute-command-keys 
+(substitute-command-keys
    "The keys that are defined for the minibuffer here are:
   \\@{minibuffer-local-must-match-map@}")
 @result{} "The keys that are defined for the minibuffer here are:
@@ -354,27 +380,47 @@ convert non-printing and whitespace characters to sequences of printing
 characters.  The description of a non-whitespace printing character is
 the character itself.
 
-@defun key-description sequence
+@defun key-description sequence &optional prefix
 @cindex Emacs event standard notation
 This function returns a string containing the Emacs standard notation
-for the input events in @var{sequence}.  The argument @var{sequence} may
-be a string, vector or list.  @xref{Input Events}, for more information
-about valid events.  See also the examples for
-@code{single-key-description}, below.
+for the input events in @var{sequence}.  If @var{prefix} is
+non-@code{nil}, it is a sequence of input events leading up to
+@var{sequence} and is included in the return value.  Both arguments
+may be strings, vectors or lists.  @xref{Input Events}, for more
+information about valid events.
+
+@smallexample
+@group
+(key-description [?\M-3 delete])
+     @result{} "M-3 <delete>"
+@end group
+@group
+(key-description [delete] "\M-3")
+     @result{} "M-3 <delete>"
+@end group
+@end smallexample
+
+  See also the examples for @code{single-key-description}, below.
 @end defun
 
-@defun single-key-description event
+@defun single-key-description event &optional no-angles
 @cindex event printing
 @cindex character printing
 @cindex control character printing
 @cindex meta character printing
 This function returns a string describing @var{event} in the standard
-Emacs notation for keyboard input.  A normal printing character appears
-as itself, but a control character turns into a string starting with
-@samp{C-}, a meta character turns into a string starting with @samp{M-},
-and space, tab, etc.@: appear as @samp{SPC}, @samp{TAB}, etc.  A
-function key symbol appears as itself.  An event that is a list appears
-as the name of the symbol in the @sc{car} of the list.
+Emacs notation for keyboard input.  A normal printing character
+appears as itself, but a control character turns into a string
+starting with @samp{C-}, a meta character turns into a string starting
+with @samp{M-}, and space, tab, etc.@: appear as @samp{SPC},
+@samp{TAB}, etc.  A function key symbol appears inside angle brackets
+@samp{<@dots{}>}.  An event that is a list appears as the name of the
+symbol in the @sc{car} of the list, inside angle brackets.
+
+If the optional argument @var{no-angles} is non-@code{nil}, the angle
+brackets around function keys and event symbols are omitted; this is
+for compatibility with old versions of Emacs which didn't use the
+brackets.
 
 @smallexample
 @group
@@ -386,7 +432,15 @@ as the name of the symbol in the @sc{car} of the list.
      @result{} "C-x SPC M-y SPC C-j SPC TAB SPC RET SPC C-l 1 2 3"
 @end group
 @group
+(single-key-description 'delete)
+     @result{} "<delete>"
+@end group
+@group
 (single-key-description 'C-mouse-1)
+     @result{} "<C-mouse-1>"
+@end group
+@group
+(single-key-description 'C-mouse-1 t)
      @result{} "C-mouse-1"
 @end group
 @end smallexample
@@ -397,7 +451,10 @@ This function returns a string describing @var{character} in the
 standard Emacs notation for characters that appear in text---like
 @code{single-key-description}, except that control characters are
 represented with a leading caret (which is how control characters in
-Emacs buffers are usually displayed).
+Emacs buffers are usually displayed).  Another difference is that
+@code{text-char-description} recognizes the 2**7 bit as the Meta
+character, whereas @code{single-key-description} uses the 2**27 bit
+for Meta.
 
 @smallexample
 @group
@@ -406,22 +463,31 @@ Emacs buffers are usually displayed).
 @end group
 @group
 (text-char-description ?\M-m)
-     @result{} "M-m"
+     @result{} "\xed"
 @end group
 @group
 (text-char-description ?\C-\M-m)
+     @result{} "\x8d"
+@end group
+@group
+(text-char-description (+ 128 ?m))
+     @result{} "M-m"
+@end group
+@group
+(text-char-description (+ 128 ?\C-m))
      @result{} "M-^M"
 @end group
 @end smallexample
 @end defun
 
-@defun read-kbd-macro string
+@defun read-kbd-macro string &optional need-vector
 This function is used mainly for operating on keyboard macros, but it
 can also be used as a rough inverse for @code{key-description}.  You
 call it with a string containing key descriptions, separated by spaces;
 it returns a string or vector containing the corresponding events.
 (This may or may not be a single valid key sequence, depending on what
-events you use; @pxref{Keymap Terminology}.)
+events you use; @pxref{Keymap Terminology}.)  If @var{need-vector} is
+non-@code{nil}, the return value is always a vector.
 @end defun
 
 @node Help Functions
@@ -433,29 +499,20 @@ about them, see @ref{Help, , Help, emacs, The GNU Emacs Manual}.  Here
 we describe some program-level interfaces to the same information.
 
 @deffn Command apropos regexp &optional do-all
-This function finds all symbols whose names contain a match for the
-regular expression @var{regexp}, and returns a list of them
-(@pxref{Regular Expressions}).  It also displays the symbols in a buffer
-named @samp{*Help*}, each with a one-line description taken from the
-beginning of its documentation string.
+This function finds all ``meaningful'' symbols whose names contain a
+match for the regular expression @var{regexp}, and returns a list of
+them, with associated documentation (@pxref{Regular Expressions}).  It
+also displays the symbols in a buffer named @samp{*Apropos*}, each
+with a one-line description taken from the beginning of its
+documentation string.  A symbol is ``meaningful'' if it has a
+definition as a function, variable, or face, or has properties.
 
 @c Emacs 19 feature
-If @var{do-all} is non-@code{nil}, then @code{apropos} also shows key
-bindings for the functions that are found; it also shows all symbols,
-even those that are neither functions nor variables.
-
-In the first of the following examples, @code{apropos} finds all the
-symbols with names containing @samp{exec}.  (We don't show here the
-output that results in the @samp{*Help*} buffer.)
-
-@smallexample
-@group
-(apropos "exec")
-     @result{} (Buffer-menu-execute command-execute exec-directory
-    exec-path execute-extended-command execute-kbd-macro
-    executing-kbd-macro executing-macro)
-@end group
-@end smallexample
+If @var{do-all} is non-@code{nil}, or if the user option
+@code{apropos-do-all} is non-@code{nil}, then @code{apropos} also
+shows key bindings for the functions that are found; it also shows
+@emph{all} interned symbols, not just meaningful ones (and it lists
+them in the return value as well).
 @end deffn
 
 @defvar help-map
@@ -470,7 +527,7 @@ follows:
 
 @smallexample
 @group
-(define-key global-map "\C-h" 'help-command)
+(define-key global-map (char-to-string help-char) 'help-command)
 (fset 'help-command help-map)
 @end group
 @end smallexample
@@ -526,7 +583,7 @@ some other meaning.)  Evaluating this expression should result in a
 string that explains what the input is for and how to enter it properly.
 
 Entry to the minibuffer binds this variable to the value of
-@code{minibuffer-help-form} (@pxref{Minibuffer Misc}).
+@code{minibuffer-help-form} (@pxref{Definition of minibuffer-help-form}).
 @end defvar
 
 @defvar prefix-help-command
@@ -565,6 +622,7 @@ This can be customized by changing the map @code{Helper-help-map}.
 
 @c Emacs 19 feature
 @defvar data-directory
+@anchor{Definition of data-directory}
 This variable holds the name of the directory in which Emacs finds
 certain documentation and text files that come with Emacs.  In older
 Emacs versions, @code{exec-directory} was used for this.
@@ -572,7 +630,7 @@ Emacs versions, @code{exec-directory} was used for this.
 
 @c Emacs 19 feature
 @defmac make-help-screen fname help-line help-text help-map
-This macro defines a help command named @var{fname} that acts like a 
+This macro defines a help command named @var{fname} that acts like a
 prefix key that shows a list of the subcommands it offers.
 
 When invoked, @var{fname} displays @var{help-text} in a window, then
@@ -602,3 +660,7 @@ If this variable is non-@code{nil}, commands defined with
 echo area at first, and display the longer @var{help-text} strings only
 if the user types the help character again.
 @end defopt
+
+@ignore
+   arch-tag: ba36b4c2-e60f-49e2-bc25-61158fdcd815
+@end ignore