Some minor fixes of Elisp manual.
[bpt/emacs.git] / doc / lispref / help.texi
CommitLineData
b8d4c8d0
GM
1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual.
acaf905b 3@c Copyright (C) 1990-1995, 1998-1999, 2001-2012
e9bffc61 4@c Free Software Foundation, Inc.
b8d4c8d0 5@c See the file elisp.texi for copying conditions.
6336d8c3 6@setfilename ../../info/help
b8d4c8d0
GM
7@node Documentation, Files, Modes, Top
8@chapter Documentation
9@cindex documentation strings
10
8376d7c2
CY
11 GNU Emacs has convenient built-in help facilities, most of which
12derive their information from documentation strings associated with
13functions and variables. This chapter describes how to access
14documentation strings in Lisp programs. @xref{Documentation Tips},
15for how to write good documentation strings.
b8d4c8d0
GM
16
17 Note that the documentation strings for Emacs are not the same thing
18as the Emacs manual. Manuals have their own source files, written in
19the Texinfo language; documentation strings are specified in the
20definitions of the functions and variables they apply to. A collection
21of documentation strings is not sufficient as a manual because a good
22manual is not organized in that fashion; it is organized in terms of
23topics of discussion.
24
25 For commands to display documentation strings, see @ref{Help, ,
8376d7c2 26Help, emacs, The GNU Emacs Manual}.
b8d4c8d0
GM
27
28@menu
8376d7c2 29* Documentation Basics:: Where doc strings are defined and stored.
b8d4c8d0
GM
30* Accessing Documentation:: How Lisp programs can access doc strings.
31* Keys in Documentation:: Substituting current key bindings.
32* Describing Characters:: Making printable descriptions of
33 non-printing characters and key sequences.
34* Help Functions:: Subroutines used by Emacs help facilities.
35@end menu
36
37@node Documentation Basics
38@comment node-name, next, previous, up
39@section Documentation Basics
40@cindex documentation conventions
41@cindex writing a documentation string
42@cindex string, writing a doc string
43
44 A documentation string is written using the Lisp syntax for strings,
45with double-quote characters surrounding the text of the string. This
46is because it really is a Lisp string object. The string serves as
47documentation when it is written in the proper place in the definition
48of a function or variable. In a function definition, the documentation
49string follows the argument list. In a variable definition, the
50documentation string follows the initial value of the variable.
51
52 When you write a documentation string, make the first line a
8376d7c2
CY
53complete sentence (or two complete sentences) that briefly describes
54what the function or variable does. Some commands, such as
55@code{apropos}, show only the first line of a multi-line documentation
56string. Also, you should not indent the second line of a
57documentation string, if it has one, because that looks odd when you
b8d4c8d0
GM
58use @kbd{C-h f} (@code{describe-function}) or @kbd{C-h v}
59(@code{describe-variable}) to view the documentation string. There
8376d7c2
CY
60are many other conventions for documentation strings; see
61@ref{Documentation Tips}.
b8d4c8d0
GM
62
63 Documentation strings can contain several special substrings, which
64stand for key bindings to be looked up in the current keymaps when the
65documentation is displayed. This allows documentation strings to refer
66to the keys for related commands and be accurate even when a user
67rearranges the key bindings. (@xref{Keys in Documentation}.)
68
69@vindex emacs-lisp-docstring-fill-column
70 Emacs Lisp mode fills documentation strings to the width
71specified by @code{emacs-lisp-docstring-fill-column}.
72
8376d7c2
CY
73 Exactly where a documentation string is stored depends on how its
74function or variable was defined or loaded into memory:
b8d4c8d0
GM
75
76@itemize @bullet
77@item
78@kindex function-documentation
8376d7c2
CY
79When you define a function (@pxref{Lambda Expressions}, and
80@pxref{Function Documentation}), the documentation string is stored in
81the function definition itself. You can also put function
82documentation in the @code{function-documentation} property of a
83function name. That is useful for function definitions which can't
84hold a documentation string, such as keyboard macros.
b8d4c8d0
GM
85
86@item
87@kindex variable-documentation
8376d7c2
CY
88When you define a variable with a @code{defvar} or related form
89(@pxref{Defining Variables}), the documentation is stored in the
90variable's @code{variable-documentation} property.
b8d4c8d0
GM
91
92@cindex @file{DOC-@var{version}} (documentation) file
8376d7c2
CY
93@item
94To save memory, the documentation for preloaded functions and
95variables (including primitive functions and autoloaded functions) is
96not kept in memory, but in the file
97@file{emacs/etc/DOC-@var{version}}, where @var{version} is the Emacs
98version number (@pxref{Version Info}).
99
100@item
101When a function or variable is loaded from a byte-compiled file during
102the Emacs session, its documentation string is not loaded into memory.
103Instead, Emacs looks it up in the byte-compiled file as needed.
104@xref{Docs and Compilation}.
105@end itemize
106
107@noindent
108Regardless of where the documentation string is stored, you can
109retrieve it using the @code{documentation} or
110@code{documentation-property} function, described in the next section.
b8d4c8d0 111
b8d4c8d0
GM
112@node Accessing Documentation
113@section Access to Documentation Strings
114
115@defun documentation-property symbol property &optional verbatim
8376d7c2
CY
116This function returns the documentation string recorded in
117@var{symbol}'s property list under property @var{property}. It is
118most often used to look up the documentation strings of variables, for
119which @var{property} is @code{variable-documentation}. However, it
120can also be used to look up other kinds of documentation, such as for
121customization groups (but for function documentation, use the
122@code{documentation} command, below).
123
124If the value recorded in the property list refers to a documentation
125string stored in a @file{DOC-@var{version}} file or a byte-compiled
126file, it looks up that string and returns it. If the property value
127isn't @code{nil}, isn't a string, and doesn't refer to text in a file,
128then it is evaluated as a Lisp expression to obtain a string.
b8d4c8d0
GM
129
130The last thing this function does is pass the string through
8376d7c2
CY
131@code{substitute-command-keys} to substitute actual key bindings
132(@pxref{Keys in Documentation}). However, it skips this step if
133@var{verbatim} is non-@code{nil}.
b8d4c8d0
GM
134
135@smallexample
136@group
137(documentation-property 'command-line-processed
138 'variable-documentation)
139 @result{} "Non-nil once command line has been processed"
140@end group
141@group
142(symbol-plist 'command-line-processed)
143 @result{} (variable-documentation 188902)
144@end group
145@group
146(documentation-property 'emacs 'group-documentation)
147 @result{} "Customization of the One True Editor."
148@end group
149@end smallexample
150@end defun
151
152@defun documentation function &optional verbatim
049bcbcb
CY
153This function returns the documentation string of @var{function}. It
154handles macros, named keyboard macros, and special forms, as well as
155ordinary functions.
b8d4c8d0
GM
156
157If @var{function} is a symbol, this function first looks for the
158@code{function-documentation} property of that symbol; if that has a
159non-@code{nil} value, the documentation comes from that value (if the
160value is not a string, it is evaluated). If @var{function} is not a
161symbol, or if it has no @code{function-documentation} property, then
162@code{documentation} extracts the documentation string from the actual
163function definition, reading it from a file if called for.
164
165Finally, unless @var{verbatim} is non-@code{nil}, it calls
166@code{substitute-command-keys} so as to return a value containing the
167actual (current) key bindings.
168
169The function @code{documentation} signals a @code{void-function} error
170if @var{function} has no function definition. However, it is OK if
171the function definition has no documentation string. In that case,
172@code{documentation} returns @code{nil}.
173@end defun
174
175@defun face-documentation face
176This function returns the documentation string of @var{face} as a
177face.
178@end defun
179
180@c Wordy to prevent overfull hboxes. --rjc 15mar92
181Here is an example of using the two functions, @code{documentation} and
182@code{documentation-property}, to display the documentation strings for
2bb0eca1 183several symbols in a @file{*Help*} buffer.
b8d4c8d0
GM
184
185@anchor{describe-symbols example}
186@smallexample
187@group
188(defun describe-symbols (pattern)
189 "Describe the Emacs Lisp symbols matching PATTERN.
190All symbols that have PATTERN in their name are described
191in the `*Help*' buffer."
192 (interactive "sDescribe symbols matching: ")
193 (let ((describe-func
194 (function
195 (lambda (s)
196@end group
197@group
198 ;; @r{Print description of symbol.}
199 (if (fboundp s) ; @r{It is a function.}
200 (princ
201 (format "%s\t%s\n%s\n\n" s
202 (if (commandp s)
203 (let ((keys (where-is-internal s)))
204 (if keys
205 (concat
206 "Keys: "
207 (mapconcat 'key-description
208 keys " "))
209 "Keys: none"))
210 "Function")
211@end group
212@group
213 (or (documentation s)
214 "not documented"))))
215
216 (if (boundp s) ; @r{It is a variable.}
217@end group
218@group
219 (princ
220 (format "%s\t%s\n%s\n\n" s
221 (if (user-variable-p s)
222 "Option " "Variable")
223@end group
224@group
225 (or (documentation-property
226 s 'variable-documentation)
227 "not documented")))))))
228 sym-list)
229@end group
230
231@group
232 ;; @r{Build a list of symbols that match pattern.}
233 (mapatoms (function
234 (lambda (sym)
235 (if (string-match pattern (symbol-name sym))
236 (setq sym-list (cons sym sym-list))))))
237@end group
238
239@group
240 ;; @r{Display the data.}
b2a77f6d
CY
241 (help-setup-xref (list 'describe-symbols pattern) (interactive-p))
242 (with-help-window (help-buffer)
243 (mapcar describe-func (sort sym-list 'string<)))))
b8d4c8d0
GM
244@end group
245@end smallexample
246
247 The @code{describe-symbols} function works like @code{apropos},
248but provides more information.
249
250@smallexample
251@group
252(describe-symbols "goal")
253
254---------- Buffer: *Help* ----------
255goal-column Option
f5c63335 256Semipermanent goal column for vertical motion, as set by @dots{}
b8d4c8d0
GM
257@end group
258@c Do not blithely break or fill these lines.
259@c That makes them incorrect.
260
261@group
262set-goal-column Keys: C-x C-n
263Set the current horizontal position as a goal for C-n and C-p.
264@end group
265@c DO NOT put a blank line here! That is factually inaccurate!
266@group
267Those commands will move to this position in the line moved to
268rather than trying to keep the same horizontal position.
269With a non-nil argument, clears out the goal column
270so that C-n and C-p resume vertical motion.
271The goal column is stored in the variable `goal-column'.
272@end group
273
274@group
275temporary-goal-column Variable
276Current goal column for vertical motion.
277It is the column where point was
278at the start of current run of vertical motion commands.
279When the `track-eol' feature is doing its job, the value is 9999.
280---------- Buffer: *Help* ----------
281@end group
282@end smallexample
283
b8d4c8d0 284@anchor{Definition of Snarf-documentation}
8376d7c2
CY
285@defun Snarf-documentation filename
286This function is used when building Emacs, just before the runnable
287Emacs is dumped. It finds the positions of the documentation strings
288stored in the file @var{filename}, and records those positions into
289memory in the function definitions and variable property lists.
290@xref{Building Emacs}.
b8d4c8d0
GM
291
292Emacs reads the file @var{filename} from the @file{emacs/etc} directory.
293When the dumped Emacs is later executed, the same file will be looked
294for in the directory @code{doc-directory}. Usually @var{filename} is
295@code{"DOC-@var{version}"}.
296@end defun
297
b8d4c8d0
GM
298@defvar doc-directory
299This variable holds the name of the directory which should contain the
300file @code{"DOC-@var{version}"} that contains documentation strings for
301built-in and preloaded functions and variables.
302
303In most cases, this is the same as @code{data-directory}. They may be
304different when you run Emacs from the directory where you built it,
305without actually installing it. @xref{Definition of data-directory}.
b8d4c8d0
GM
306@end defvar
307
308@node Keys in Documentation
309@section Substituting Key Bindings in Documentation
310@cindex documentation, keys in
311@cindex keys in documentation strings
312@cindex substituting keys in documentation
313
314 When documentation strings refer to key sequences, they should use the
315current, actual key bindings. They can do so using certain special text
316sequences described below. Accessing documentation strings in the usual
317way substitutes current key binding information for these special
318sequences. This works by calling @code{substitute-command-keys}. You
319can also call that function yourself.
320
321 Here is a list of the special sequences and what they mean:
322
323@table @code
324@item \[@var{command}]
325stands for a key sequence that will invoke @var{command}, or @samp{M-x
326@var{command}} if @var{command} has no key bindings.
327
328@item \@{@var{mapvar}@}
329stands for a summary of the keymap which is the value of the variable
330@var{mapvar}. The summary is made using @code{describe-bindings}.
331
332@item \<@var{mapvar}>
333stands for no text itself. It is used only for a side effect: it
334specifies @var{mapvar}'s value as the keymap for any following
335@samp{\[@var{command}]} sequences in this documentation string.
336
337@item \=
4baf28e6
AS
338quotes the following character and is discarded; thus, @samp{\=\[} puts
339@samp{\[} into the output, and @samp{\=\=} puts @samp{\=} into the
340output.
b8d4c8d0
GM
341@end table
342
343@strong{Please note:} Each @samp{\} must be doubled when written in a
344string in Emacs Lisp.
345
346@defun substitute-command-keys string
347This function scans @var{string} for the above special sequences and
348replaces them by what they stand for, returning the result as a string.
349This permits display of documentation that refers accurately to the
350user's own customized key bindings.
21ffa320
CY
351
352@cindex advertised binding
353If a command has multiple bindings, this function normally uses the
354first one it finds. You can specify one particular key binding by
355assigning an @code{:advertised-binding} symbol property to the
356command, like this:
357
358@smallexample
359(put 'undo :advertised-binding [?\C-/])
360@end smallexample
361
362@noindent
363The @code{:advertised-binding} property also affects the binding shown
364in menu items (@pxref{Menu Bar}). The property is ignored if it
365specifies a key binding that the command does not actually have.
b8d4c8d0
GM
366@end defun
367
368 Here are examples of the special sequences:
369
370@smallexample
371@group
372(substitute-command-keys
373 "To abort recursive edit, type: \\[abort-recursive-edit]")
374@result{} "To abort recursive edit, type: C-]"
375@end group
376
377@group
378(substitute-command-keys
379 "The keys that are defined for the minibuffer here are:
380 \\@{minibuffer-local-must-match-map@}")
381@result{} "The keys that are defined for the minibuffer here are:
382@end group
383
384? minibuffer-completion-help
385SPC minibuffer-complete-word
386TAB minibuffer-complete
387C-j minibuffer-complete-and-exit
388RET minibuffer-complete-and-exit
389C-g abort-recursive-edit
390"
391
392@group
393(substitute-command-keys
394 "To abort a recursive edit from the minibuffer, type\
395\\<minibuffer-local-must-match-map>\\[abort-recursive-edit].")
396@result{} "To abort a recursive edit from the minibuffer, type C-g."
397@end group
398@end smallexample
399
400 There are other special conventions for the text in documentation
401strings---for instance, you can refer to functions, variables, and
402sections of this manual. @xref{Documentation Tips}, for details.
403
404@node Describing Characters
405@section Describing Characters for Help Messages
406@cindex describe characters and events
407
408 These functions convert events, key sequences, or characters to
409textual descriptions. These descriptions are useful for including
410arbitrary text characters or key sequences in messages, because they
411convert non-printing and whitespace characters to sequences of printing
412characters. The description of a non-whitespace printing character is
413the character itself.
414
415@defun key-description sequence &optional prefix
416@cindex Emacs event standard notation
417This function returns a string containing the Emacs standard notation
418for the input events in @var{sequence}. If @var{prefix} is
419non-@code{nil}, it is a sequence of input events leading up to
420@var{sequence} and is included in the return value. Both arguments
421may be strings, vectors or lists. @xref{Input Events}, for more
422information about valid events.
423
424@smallexample
425@group
426(key-description [?\M-3 delete])
427 @result{} "M-3 <delete>"
428@end group
429@group
430(key-description [delete] "\M-3")
431 @result{} "M-3 <delete>"
432@end group
433@end smallexample
434
435 See also the examples for @code{single-key-description}, below.
436@end defun
437
438@defun single-key-description event &optional no-angles
439@cindex event printing
440@cindex character printing
441@cindex control character printing
442@cindex meta character printing
443This function returns a string describing @var{event} in the standard
444Emacs notation for keyboard input. A normal printing character
445appears as itself, but a control character turns into a string
446starting with @samp{C-}, a meta character turns into a string starting
447with @samp{M-}, and space, tab, etc.@: appear as @samp{SPC},
448@samp{TAB}, etc. A function key symbol appears inside angle brackets
449@samp{<@dots{}>}. An event that is a list appears as the name of the
450symbol in the @sc{car} of the list, inside angle brackets.
451
452If the optional argument @var{no-angles} is non-@code{nil}, the angle
453brackets around function keys and event symbols are omitted; this is
454for compatibility with old versions of Emacs which didn't use the
455brackets.
456
457@smallexample
458@group
459(single-key-description ?\C-x)
460 @result{} "C-x"
461@end group
462@group
463(key-description "\C-x \M-y \n \t \r \f123")
464 @result{} "C-x SPC M-y SPC C-j SPC TAB SPC RET SPC C-l 1 2 3"
465@end group
466@group
467(single-key-description 'delete)
468 @result{} "<delete>"
469@end group
470@group
471(single-key-description 'C-mouse-1)
472 @result{} "<C-mouse-1>"
473@end group
474@group
475(single-key-description 'C-mouse-1 t)
476 @result{} "C-mouse-1"
477@end group
478@end smallexample
479@end defun
480
481@defun text-char-description character
482This function returns a string describing @var{character} in the
483standard Emacs notation for characters that appear in text---like
484@code{single-key-description}, except that control characters are
485represented with a leading caret (which is how control characters in
486Emacs buffers are usually displayed). Another difference is that
487@code{text-char-description} recognizes the 2**7 bit as the Meta
488character, whereas @code{single-key-description} uses the 2**27 bit
489for Meta.
490
491@smallexample
492@group
493(text-char-description ?\C-c)
494 @result{} "^C"
495@end group
496@group
497(text-char-description ?\M-m)
498 @result{} "\xed"
499@end group
500@group
501(text-char-description ?\C-\M-m)
502 @result{} "\x8d"
503@end group
504@group
505(text-char-description (+ 128 ?m))
506 @result{} "M-m"
507@end group
508@group
509(text-char-description (+ 128 ?\C-m))
510 @result{} "M-^M"
511@end group
512@end smallexample
513@end defun
514
0b128ac4 515@deffn Command read-kbd-macro string &optional need-vector
b8d4c8d0
GM
516This function is used mainly for operating on keyboard macros, but it
517can also be used as a rough inverse for @code{key-description}. You
518call it with a string containing key descriptions, separated by spaces;
519it returns a string or vector containing the corresponding events.
520(This may or may not be a single valid key sequence, depending on what
521events you use; @pxref{Key Sequences}.) If @var{need-vector} is
522non-@code{nil}, the return value is always a vector.
0b128ac4 523@end deffn
b8d4c8d0
GM
524
525@node Help Functions
526@section Help Functions
527
528 Emacs provides a variety of on-line help functions, all accessible to
529the user as subcommands of the prefix @kbd{C-h}. For more information
530about them, see @ref{Help, , Help, emacs, The GNU Emacs Manual}. Here
531we describe some program-level interfaces to the same information.
532
533@deffn Command apropos pattern &optional do-all
534This function finds all ``meaningful'' symbols whose names contain a
535match for the apropos pattern @var{pattern}. An apropos pattern is
536either a word to match, a space-separated list of words of which at
537least two must match, or a regular expression (if any special regular
538expression characters occur). A symbol is ``meaningful'' if it has a
539definition as a function, variable, or face, or has properties.
540
541The function returns a list of elements that look like this:
542
543@example
5d55b248 544(@var{symbol} @var{score} @var{function-doc} @var{variable-doc}
b8d4c8d0
GM
545 @var{plist-doc} @var{widget-doc} @var{face-doc} @var{group-doc})
546@end example
547
548Here, @var{score} is an integer measure of how important the symbol
8376d7c2
CY
549seems to be as a match. Each of the remaining elements is a
550documentation string, or @code{nil}, for @var{symbol} as a function,
551variable, etc.
b8d4c8d0 552
2bb0eca1 553It also displays the symbols in a buffer named @file{*Apropos*}, each
b8d4c8d0
GM
554with a one-line description taken from the beginning of its
555documentation string.
556
b8d4c8d0
GM
557If @var{do-all} is non-@code{nil}, or if the user option
558@code{apropos-do-all} is non-@code{nil}, then @code{apropos} also
559shows key bindings for the functions that are found; it also shows
560@emph{all} interned symbols, not just meaningful ones (and it lists
561them in the return value as well).
562@end deffn
563
564@defvar help-map
565The value of this variable is a local keymap for characters following the
566Help key, @kbd{C-h}.
567@end defvar
568
569@deffn {Prefix Command} help-command
570This symbol is not a function; its function definition cell holds the
571keymap known as @code{help-map}. It is defined in @file{help.el} as
572follows:
573
574@smallexample
575@group
3e99b825 576(define-key global-map (string help-char) 'help-command)
b8d4c8d0
GM
577(fset 'help-command help-map)
578@end group
579@end smallexample
580@end deffn
581
01f17ae2 582@defopt help-char
b8d4c8d0
GM
583The value of this variable is the help character---the character that
584Emacs recognizes as meaning Help. By default, its value is 8, which
585stands for @kbd{C-h}. When Emacs reads this character, if
586@code{help-form} is a non-@code{nil} Lisp expression, it evaluates that
587expression, and displays the result in a window if it is a string.
588
589Usually the value of @code{help-form} is @code{nil}. Then the
590help character has no special meaning at the level of command input, and
591it becomes part of a key sequence in the normal way. The standard key
592binding of @kbd{C-h} is a prefix key for several general-purpose help
593features.
594
595The help character is special after prefix keys, too. If it has no
596binding as a subcommand of the prefix key, it runs
597@code{describe-prefix-bindings}, which displays a list of all the
598subcommands of the prefix key.
01f17ae2 599@end defopt
b8d4c8d0 600
01f17ae2 601@defopt help-event-list
b8d4c8d0 602The value of this variable is a list of event types that serve as
16152b76 603alternative ``help characters''. These events are handled just like the
b8d4c8d0 604event specified by @code{help-char}.
01f17ae2 605@end defopt
b8d4c8d0
GM
606
607@defvar help-form
608If this variable is non-@code{nil}, its value is a form to evaluate
609whenever the character @code{help-char} is read. If evaluating the form
610produces a string, that string is displayed.
611
7e2734bc
GM
612A command that calls @code{read-event}, @code{read-char-choice}, or
613@code{read-char} probably should bind @code{help-form} to a
614non-@code{nil} expression while it does input. (The time when you
615should not do this is when @kbd{C-h} has some other meaning.)
616Evaluating this expression should result in a string that explains
617what the input is for and how to enter it properly.
b8d4c8d0
GM
618
619Entry to the minibuffer binds this variable to the value of
620@code{minibuffer-help-form} (@pxref{Definition of minibuffer-help-form}).
621@end defvar
622
623@defvar prefix-help-command
624This variable holds a function to print help for a prefix key. The
625function is called when the user types a prefix key followed by the help
626character, and the help character has no binding after that prefix. The
627variable's default value is @code{describe-prefix-bindings}.
628@end defvar
629
0b128ac4 630@deffn Command describe-prefix-bindings
b8d4c8d0
GM
631This function calls @code{describe-bindings} to display a list of all
632the subcommands of the prefix key of the most recent key sequence. The
633prefix described consists of all but the last event of that key
634sequence. (The last event is, presumably, the help character.)
0b128ac4 635@end deffn
b8d4c8d0
GM
636
637 The following two functions are meant for modes that want to provide
638help without relinquishing control, such as the ``electric'' modes.
639Their names begin with @samp{Helper} to distinguish them from the
640ordinary help functions.
641
642@deffn Command Helper-describe-bindings
643This command pops up a window displaying a help buffer containing a
644listing of all of the key bindings from both the local and global keymaps.
645It works by calling @code{describe-bindings}.
646@end deffn
647
648@deffn Command Helper-help
649This command provides help for the current mode. It prompts the user
650in the minibuffer with the message @samp{Help (Type ? for further
651options)}, and then provides assistance in finding out what the key
652bindings are, and what the mode is intended for. It returns @code{nil}.
653
53a1239b 654@vindex Helper-help-map
b8d4c8d0
GM
655This can be customized by changing the map @code{Helper-help-map}.
656@end deffn
657
b8d4c8d0
GM
658@defvar data-directory
659@anchor{Definition of data-directory}
660This variable holds the name of the directory in which Emacs finds
bbe45ef7 661certain documentation and text files that come with Emacs.
b8d4c8d0
GM
662@end defvar
663
77c7e2e1 664@defun help-buffer
b2a77f6d 665This function returns the name of the help buffer, which is normally
2bb0eca1 666@file{*Help*}; if such a buffer does not exist, it is first created.
77c7e2e1 667@end defun
b2a77f6d
CY
668
669@defmac with-help-window buffer-name body@dots{}
670This macro evaluates the @var{body} forms, inserting any output they
671produce into a buffer named @var{buffer-name} like
672@code{with-output-to-temp-buffer} (@pxref{Temporary Displays}).
673(Usually, @var{buffer-name} should be the value returned by the
674function @code{help-buffer}.) It also puts the specified buffer into
675Help mode and displays a message telling the user how to quit and
676scroll the help window.
677@end defmac
678
77c7e2e1 679@defun help-setup-xref item interactive-p
2bb0eca1 680This function updates the cross reference data in the @file{*Help*}
b2a77f6d
CY
681buffer, which is used to regenerate the help information when the user
682clicks on the @samp{Back} or @samp{Forward} buttons. Most commands
2bb0eca1 683that use the @file{*Help*} buffer should invoke this function before
b2a77f6d 684clearing the buffer. The @var{item} argument should have the form
cd1181db 685@code{(@var{function} . @var{args})}, where @var{function} is a function
b2a77f6d
CY
686to call, with argument list @var{args}, to regenerate the help buffer.
687The @var{interactive-p} argument is non-@code{nil} if the calling
688command was invoked interactively; in that case, the stack of items
2bb0eca1 689for the @file{*Help*} buffer's @samp{Back} buttons is cleared.
77c7e2e1 690@end defun
b2a77f6d
CY
691
692@xref{describe-symbols example}, for an example of using
693@code{help-buffer}, @code{with-help-window}, and
694@code{help-setup-xref}.
695
b8d4c8d0
GM
696@defmac make-help-screen fname help-line help-text help-map
697This macro defines a help command named @var{fname} that acts like a
698prefix key that shows a list of the subcommands it offers.
699
700When invoked, @var{fname} displays @var{help-text} in a window, then
701reads and executes a key sequence according to @var{help-map}. The
702string @var{help-text} should describe the bindings available in
703@var{help-map}.
704
705The command @var{fname} is defined to handle a few events itself, by
706scrolling the display of @var{help-text}. When @var{fname} reads one of
707those special events, it does the scrolling and then reads another
708event. When it reads an event that is not one of those few, and which
709has a binding in @var{help-map}, it executes that key's binding and
710then returns.
711
712The argument @var{help-line} should be a single-line summary of the
713alternatives in @var{help-map}. In the current version of Emacs, this
714argument is used only if you set the option @code{three-step-help} to
715@code{t}.
716
717This macro is used in the command @code{help-for-help} which is the
718binding of @kbd{C-h C-h}.
719@end defmac
720
721@defopt three-step-help
722If this variable is non-@code{nil}, commands defined with
723@code{make-help-screen} display their @var{help-line} strings in the
724echo area at first, and display the longer @var{help-text} strings only
725if the user types the help character again.
726@end defopt
727