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