(help-argument-name): Default to bold; don't inherit from
[bpt/emacs.git] / lisp / help-fns.el
1 ;;; help-fns.el --- Complex help functions
2
3 ;; Copyright (C) 1985, 86, 93, 94, 98, 1999, 2000, 01, 02, 03, 2004
4 ;; Free Software Foundation, Inc.
5
6 ;; Maintainer: FSF
7 ;; Keywords: help, internal
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; This file contains those help commands which are complicated, and
29 ;; which may not be used in every session. For example
30 ;; `describe-function' will probably be heavily used when doing elisp
31 ;; programming, but not if just editing C files. Simpler help commands
32 ;; are in help.el
33
34 ;;; Code:
35
36 (require 'help-mode)
37
38
39 ;;;###autoload
40 (defun help-with-tutorial (&optional arg)
41 "Select the Emacs learn-by-doing tutorial.
42 If there is a tutorial version written in the language
43 of the selected language environment, that version is used.
44 If there's no tutorial in that language, `TUTORIAL' is selected.
45 With ARG, you are asked to choose which language."
46 (interactive "P")
47 (let ((lang (if arg
48 (let ((minibuffer-setup-hook minibuffer-setup-hook))
49 (add-hook 'minibuffer-setup-hook
50 'minibuffer-completion-help)
51 (read-language-name 'tutorial "Language: " "English"))
52 (if (get-language-info current-language-environment 'tutorial)
53 current-language-environment
54 "English")))
55 file filename)
56 (setq filename (get-language-info lang 'tutorial))
57 (setq file (expand-file-name (concat "~/" filename)))
58 (delete-other-windows)
59 (if (get-file-buffer file)
60 (switch-to-buffer (get-file-buffer file))
61 (switch-to-buffer (create-file-buffer file))
62 (setq buffer-file-name file)
63 (setq default-directory (expand-file-name "~/"))
64 (setq buffer-auto-save-file-name nil)
65 (insert-file-contents (expand-file-name filename data-directory))
66 (hack-local-variables)
67 (goto-char (point-min))
68 (search-forward "\n<<")
69 (beginning-of-line)
70 ;; Convert the <<...>> line to the proper [...] line,
71 ;; or just delete the <<...>> line if a [...] line follows.
72 (cond ((save-excursion
73 (forward-line 1)
74 (looking-at "\\["))
75 (delete-region (point) (progn (forward-line 1) (point))))
76 ((looking-at "<<Blank lines inserted.*>>")
77 (replace-match "[Middle of page left blank for didactic purposes. Text continues below]"))
78 (t
79 (looking-at "<<")
80 (replace-match "[")
81 (search-forward ">>")
82 (replace-match "]")))
83 (beginning-of-line)
84 (let ((n (- (window-height (selected-window))
85 (count-lines (point-min) (point))
86 6)))
87 (if (< n 8)
88 (progn
89 ;; For a short gap, we don't need the [...] line,
90 ;; so delete it.
91 (delete-region (point) (progn (end-of-line) (point)))
92 (newline n))
93 ;; Some people get confused by the large gap.
94 (newline (/ n 2))
95
96 ;; Skip the [...] line (don't delete it).
97 (forward-line 1)
98 (newline (- n (/ n 2)))))
99 (goto-char (point-min))
100 (set-buffer-modified-p nil))))
101
102 ;;;###autoload
103 (defun locate-library (library &optional nosuffix path interactive-call)
104 "Show the precise file name of Emacs library LIBRARY.
105 This command searches the directories in `load-path' like `\\[load-library]'
106 to find the file that `\\[load-library] RET LIBRARY RET' would load.
107 Optional second arg NOSUFFIX non-nil means don't add suffixes `load-suffixes'
108 to the specified name LIBRARY.
109
110 If the optional third arg PATH is specified, that list of directories
111 is used instead of `load-path'.
112
113 When called from a program, the file name is normaly returned as a
114 string. When run interactively, the argument INTERACTIVE-CALL is t,
115 and the file name is displayed in the echo area."
116 (interactive (list (completing-read "Locate library: "
117 'locate-file-completion
118 (cons load-path load-suffixes))
119 nil nil
120 t))
121 (let ((file (locate-file library
122 (or path load-path)
123 (append (unless nosuffix load-suffixes) '("")))))
124 (if interactive-call
125 (if file
126 (message "Library is file %s" (abbreviate-file-name file))
127 (message "No library %s in search path" library)))
128 file))
129
130 \f
131 ;; Functions
132
133 ;;;###autoload
134 (defun describe-function (function)
135 "Display the full documentation of FUNCTION (a symbol)."
136 (interactive
137 (let ((fn (function-called-at-point))
138 (enable-recursive-minibuffers t)
139 val)
140 (setq val (completing-read (if fn
141 (format "Describe function (default %s): " fn)
142 "Describe function: ")
143 obarray 'fboundp t nil nil (symbol-name fn)))
144 (list (if (equal val "")
145 fn (intern val)))))
146 (if (null function)
147 (message "You didn't specify a function")
148 (help-setup-xref (list #'describe-function function) (interactive-p))
149 (save-excursion
150 (with-output-to-temp-buffer (help-buffer)
151 (prin1 function)
152 ;; Use " is " instead of a colon so that
153 ;; it is easier to get out the function name using forward-sexp.
154 (princ " is ")
155 (describe-function-1 function)
156 (print-help-return-message)
157 (with-current-buffer standard-output
158 ;; Return the text we displayed.
159 (buffer-string))))))
160
161 (defun help-split-fundoc (doc def)
162 "Split a function docstring DOC into the actual doc and the usage info.
163 Return (USAGE . DOC) or nil if there's no usage info.
164 DEF is the function whose usage we're looking for in DOC."
165 ;; Functions can get the calling sequence at the end of the doc string.
166 ;; In cases where `function' has been fset to a subr we can't search for
167 ;; function's name in the doc string so we use `fn' as the anonymous
168 ;; function name instead.
169 (when (and doc (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" doc))
170 (cons (format "(%s%s"
171 ;; Replace `fn' with the actual function name.
172 (if (consp def) "anonymous" def)
173 (match-string 1 doc))
174 (substring doc 0 (match-beginning 0)))))
175
176 (defun help-add-fundoc-usage (doc arglist)
177 "Add the usage info to the docstring DOC.
178 If DOC already has a usage info, then just return DOC unchanged.
179 The usage info is built from ARGLIST. DOC can be nil.
180 ARGLIST can also be t or a string of the form \"(fun ARG1 ARG2 ...)\"."
181 (unless (stringp doc) (setq doc "Not documented"))
182 (if (or (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" doc) (eq arglist t))
183 doc
184 (format "%s%s%S" doc
185 (if (string-match "\n?\n\\'" doc)
186 (if (< (- (match-end 0) (match-beginning 0)) 2) "\n" "")
187 "\n\n")
188 (if (and (stringp arglist)
189 (string-match "\\`([^ ]+\\(.*\\))\\'" arglist))
190 (concat "(fn" (match-string 1 arglist) ")")
191 (help-make-usage 'fn arglist)))))
192
193 (defun help-function-arglist (def)
194 ;; Handle symbols aliased to other symbols.
195 (if (and (symbolp def) (fboundp def)) (setq def (indirect-function def)))
196 ;; If definition is a macro, find the function inside it.
197 (if (eq (car-safe def) 'macro) (setq def (cdr def)))
198 (cond
199 ((byte-code-function-p def) (aref def 0))
200 ((eq (car-safe def) 'lambda) (nth 1 def))
201 ((and (eq (car-safe def) 'autoload) (not (eq (nth 4 def) 'keymap)))
202 "[Arg list not available until function definition is loaded.]")
203 (t t)))
204
205 (defun help-make-usage (function arglist)
206 (cons (if (symbolp function) function 'anonymous)
207 (mapcar (lambda (arg)
208 (if (not (symbolp arg))
209 (if (and (consp arg) (symbolp (car arg)))
210 ;; CL style default values for optional args.
211 (cons (intern (upcase (symbol-name (car arg))))
212 (cdr arg))
213 arg)
214 (let ((name (symbol-name arg)))
215 (if (string-match "\\`&" name) arg
216 (intern (upcase name))))))
217 arglist)))
218
219 (defun help-C-file-name (subr-or-var kind)
220 "Return the name of the C file where SUBR-OR-VAR is defined.
221 KIND should be `var' for a variable or `subr' for a subroutine."
222 (let ((docbuf (get-buffer-create " *DOC*"))
223 (name (if (eq 'var kind)
224 (concat "V" (symbol-name subr-or-var))
225 (concat "F" (subr-name subr-or-var)))))
226 (with-current-buffer docbuf
227 (goto-char (point-min))
228 (if (eobp)
229 (insert-file-contents-literally
230 (expand-file-name internal-doc-file-name doc-directory)))
231 (search-forward (concat "\1f" name "\n"))
232 (re-search-backward "\1fS\\(.*\\)")
233 (let ((file (match-string 1)))
234 (if (string-match "\\.\\(o\\|obj\\)\\'" file)
235 (setq file (replace-match ".c" t t file)))
236 (if (string-match "\\.c\\'" file)
237 (concat "src/" file)
238 file)))))
239
240 (defface help-argument-name '((t (:weight bold)))
241 "Face to highlight function arguments in docstrings.")
242
243 (defun help-do-arg-highlight (doc args)
244 (while args
245 (let ((arg (prog1 (car args) (setq args (cdr args)))))
246 (setq doc (replace-regexp-in-string
247 (concat "\\<\\(" arg "\\)\\(?:es\\|s\\|th\\)?\\>")
248 (propertize arg 'face 'help-argument-name)
249 doc t t 1))))
250 doc)
251
252 (defun help-highlight-arguments (usage doc &rest args)
253 (when usage
254 (let ((case-fold-search nil)
255 (next (not args)))
256 ;; Make a list of all arguments
257 (with-temp-buffer
258 (insert usage)
259 (goto-char (point-min))
260 ;; Make a list of all arguments
261 (while next
262 (if (not (re-search-forward " \\([\\[(]?\\)\\([^] &)\.]+\\)" nil t))
263 (setq next nil)
264 (setq args (cons (match-string 2) args))
265 (when (string= (match-string 1) "(")
266 ;; A pesky CL-style optional argument with default value,
267 ;; so let's skip over it
268 (search-backward "(")
269 (goto-char (scan-sexps (point) 1)))))
270 ;; Highlight aguments in the USAGE string
271 (setq usage (help-do-arg-highlight (buffer-string) args)))
272 ;; Highlight arguments in the DOC string
273 (setq doc (and doc (help-do-arg-highlight doc args)))
274 ;; Return value is like the one from help-split-fundoc, but highlighted
275 (cons usage doc))))
276
277 ;;;###autoload
278 (defun describe-function-1 (function)
279 (let* ((def (if (symbolp function)
280 (symbol-function function)
281 function))
282 file-name string
283 (beg (if (commandp def) "an interactive " "a ")))
284 (setq string
285 (cond ((or (stringp def)
286 (vectorp def))
287 "a keyboard macro")
288 ((subrp def)
289 (if (eq 'unevalled (cdr (subr-arity def)))
290 (concat beg "special form")
291 (concat beg "built-in function")))
292 ((byte-code-function-p def)
293 (concat beg "compiled Lisp function"))
294 ((symbolp def)
295 (while (symbolp (symbol-function def))
296 (setq def (symbol-function def)))
297 (format "an alias for `%s'" def))
298 ((eq (car-safe def) 'lambda)
299 (concat beg "Lisp function"))
300 ((eq (car-safe def) 'macro)
301 "a Lisp macro")
302 ((eq (car-safe def) 'autoload)
303 (setq file-name (nth 1 def))
304 (format "%s autoloaded %s"
305 (if (commandp def) "an interactive" "an")
306 (if (eq (nth 4 def) 'keymap) "keymap"
307 (if (nth 4 def) "Lisp macro" "Lisp function"))
308 ))
309 ((keymapp def)
310 (let ((is-full nil)
311 (elts (cdr-safe def)))
312 (while elts
313 (if (char-table-p (car-safe elts))
314 (setq is-full t
315 elts nil))
316 (setq elts (cdr-safe elts)))
317 (if is-full
318 "a full keymap"
319 "a sparse keymap")))
320 (t "")))
321 (princ string)
322 (with-current-buffer standard-output
323 (save-excursion
324 (save-match-data
325 (if (re-search-backward "alias for `\\([^`']+\\)'" nil t)
326 (help-xref-button 1 'help-function def)))))
327 (or file-name
328 (setq file-name (symbol-file function)))
329 (when (equal file-name "loaddefs.el")
330 ;; Find the real def site of the preloaded function.
331 ;; This is necessary only for defaliases.
332 (let ((location
333 (condition-case nil
334 (find-function-search-for-symbol function nil "loaddefs.el")
335 (error nil))))
336 (when location
337 (with-current-buffer (car location)
338 (goto-char (cdr location))
339 (when (re-search-backward
340 "^;;; Generated autoloads from \\(.*\\)" nil t)
341 (setq file-name (match-string 1)))))))
342 (when (and (null file-name) (subrp def))
343 ;; Find the C source file name.
344 (setq file-name (if (get-buffer " *DOC*")
345 (help-C-file-name def 'subr)
346 'C-source)))
347 (when file-name
348 (princ " in `")
349 ;; We used to add .el to the file name,
350 ;; but that's completely wrong when the user used load-file.
351 (princ (if (eq file-name 'C-source) "C source code" file-name))
352 (princ "'")
353 ;; Make a hyperlink to the library.
354 (with-current-buffer standard-output
355 (save-excursion
356 (re-search-backward "`\\([^`']+\\)'" nil t)
357 (help-xref-button 1 'help-function-def function file-name))))
358 (princ ".")
359 (terpri)
360 (when (commandp function)
361 (let* ((remapped (command-remapping function))
362 (keys (where-is-internal
363 (or remapped function) overriding-local-map nil nil))
364 non-modified-keys)
365 ;; Which non-control non-meta keys run this command?
366 (dolist (key keys)
367 (if (member (event-modifiers (aref key 0)) '(nil (shift)))
368 (push key non-modified-keys)))
369 (when remapped
370 (princ "It is remapped to `")
371 (princ (symbol-name remapped))
372 (princ "'"))
373
374 (when keys
375 (princ (if remapped " which is bound to " "It is bound to "))
376 ;; FIXME: This list can be very long (f.ex. for self-insert-command).
377 ;; If there are many, remove them from KEYS.
378 (if (< (length non-modified-keys) 10)
379 (princ (mapconcat 'key-description keys ", "))
380 (dolist (key non-modified-keys)
381 (setq keys (delq key keys)))
382 (if keys
383 (progn
384 (princ (mapconcat 'key-description keys ", "))
385 (princ ", and many ordinary text characters"))
386 (princ "many ordinary text characters"))))
387 (when (or remapped keys non-modified-keys)
388 (princ ".")
389 (terpri))))
390 (let* ((arglist (help-function-arglist def))
391 (doc (documentation function))
392 (usage (help-split-fundoc doc function)))
393 (with-current-buffer standard-output
394 ;; If definition is a keymap, skip arglist note.
395 (unless (keymapp def)
396 (let* ((use (cond
397 (usage (setq doc (cdr usage)) (car usage))
398 ((listp arglist)
399 (format "%S" (help-make-usage function arglist)))
400 ((stringp arglist) arglist)
401 ;; Maybe the arglist is in the docstring of the alias.
402 ((let ((fun function))
403 (while (and (symbolp fun)
404 (setq fun (symbol-function fun))
405 (not (setq usage (help-split-fundoc
406 (documentation fun)
407 function)))))
408 usage)
409 (car usage))
410 ((or (stringp def)
411 (vectorp def))
412 (format "\nMacro: %s" (format-kbd-macro def)))
413 (t "[Missing arglist. Please make a bug report.]")))
414 (high (help-highlight-arguments use doc)))
415 (insert (car high) "\n")
416 (setq doc (cdr high))))
417 (let ((obsolete (and
418 ;; function might be a lambda construct.
419 (symbolp function)
420 (get function 'byte-obsolete-info))))
421 (when obsolete
422 (princ "\nThis function is obsolete")
423 (when (nth 2 obsolete)
424 (insert (format " since %s" (nth 2 obsolete))))
425 (insert ";\n"
426 (if (stringp (car obsolete)) (car obsolete)
427 (format "use `%s' instead." (car obsolete)))
428 "\n"))
429 (insert "\n"
430 (or doc "Not documented.")))))))
431
432 \f
433 ;; Variables
434
435 ;;;###autoload
436 (defun variable-at-point ()
437 "Return the bound variable symbol found around point.
438 Return 0 if there is no such symbol."
439 (condition-case ()
440 (with-syntax-table emacs-lisp-mode-syntax-table
441 (save-excursion
442 (or (not (zerop (skip-syntax-backward "_w")))
443 (eq (char-syntax (following-char)) ?w)
444 (eq (char-syntax (following-char)) ?_)
445 (forward-sexp -1))
446 (skip-chars-forward "'")
447 (let ((obj (read (current-buffer))))
448 (or (and (symbolp obj) (boundp obj) obj)
449 0))))
450 (error 0)))
451
452 ;;;###autoload
453 (defun describe-variable (variable &optional buffer)
454 "Display the full documentation of VARIABLE (a symbol).
455 Returns the documentation as a string, also.
456 If VARIABLE has a buffer-local value in BUFFER (default to the current buffer),
457 it is displayed along with the global value."
458 (interactive
459 (let ((v (variable-at-point))
460 (enable-recursive-minibuffers t)
461 val)
462 (setq val (completing-read (if (symbolp v)
463 (format
464 "Describe variable (default %s): " v)
465 "Describe variable: ")
466 obarray 'boundp t nil nil
467 (if (symbolp v) (symbol-name v))))
468 (list (if (equal val "")
469 v (intern val)))))
470 (unless (buffer-live-p buffer) (setq buffer (current-buffer)))
471 (if (not (symbolp variable))
472 (message "You did not specify a variable")
473 (save-excursion
474 (let* ((valvoid (not (with-current-buffer buffer (boundp variable))))
475 ;; Extract the value before setting up the output buffer,
476 ;; in case `buffer' *is* the output buffer.
477 (val (unless valvoid (buffer-local-value variable buffer))))
478 (help-setup-xref (list #'describe-variable variable buffer)
479 (interactive-p))
480 (with-output-to-temp-buffer (help-buffer)
481 (with-current-buffer buffer
482 (prin1 variable)
483 (if valvoid
484 (princ " is void")
485 (with-current-buffer standard-output
486 (princ "'s value is ")
487 (terpri)
488 (let ((from (point)))
489 (pp val)
490 (help-xref-on-pp from (point))
491 (if (< (point) (+ from 20))
492 (delete-region (1- from) from)))))
493 (terpri)
494 (when (local-variable-p variable)
495 (princ (format "%socal in buffer %s; "
496 (if (get variable 'permanent-local)
497 "Permanently l" "L")
498 (buffer-name)))
499 (if (not (default-boundp variable))
500 (princ "globally void")
501 (let ((val (default-value variable)))
502 (with-current-buffer standard-output
503 (princ "global value is ")
504 (terpri)
505 ;; Fixme: pp can take an age if you happen to
506 ;; ask for a very large expression. We should
507 ;; probably print it raw once and check it's a
508 ;; sensible size before prettyprinting. -- fx
509 (let ((from (point)))
510 (pp val)
511 (help-xref-on-pp from (point))
512 (if (< (point) (+ from 20))
513 (delete-region (1- from) from))))))
514 (terpri))
515 (terpri)
516 (with-current-buffer standard-output
517 (when (> (count-lines (point-min) (point-max)) 10)
518 ;; Note that setting the syntax table like below
519 ;; makes forward-sexp move over a `'s' at the end
520 ;; of a symbol.
521 (set-syntax-table emacs-lisp-mode-syntax-table)
522 (goto-char (point-min))
523 (if valvoid
524 (forward-line 1)
525 (forward-sexp 1)
526 (delete-region (point) (progn (end-of-line) (point)))
527 (insert " value is shown below.\n\n")
528 (save-excursion
529 (insert "\n\nValue:"))))
530 ;; Add a note for variables that have been make-var-buffer-local.
531 (when (and (local-variable-if-set-p variable)
532 (or (not (local-variable-p variable))
533 (with-temp-buffer
534 (local-variable-if-set-p variable))))
535 (save-excursion
536 (forward-line -1)
537 (insert "Automatically becomes buffer-local when set in any fashion.\n"))))
538 ;; Mention if it's an alias
539 (let* ((alias (condition-case nil
540 (indirect-variable variable)
541 (error variable)))
542 (obsolete (get variable 'byte-obsolete-variable))
543 (doc (or (documentation-property variable 'variable-documentation)
544 (documentation-property alias 'variable-documentation))))
545 (unless (eq alias variable)
546 (princ (format "This variable is an alias for `%s'." alias))
547 (terpri)
548 (terpri))
549 (when obsolete
550 (princ "This variable is obsolete")
551 (if (cdr obsolete) (princ (format " since %s" (cdr obsolete))))
552 (princ ";") (terpri)
553 (princ (if (stringp (car obsolete)) (car obsolete)
554 (format "use `%s' instead." (car obsolete))))
555 (terpri)
556 (terpri))
557 (princ (or doc "Not documented as a variable.")))
558 ;; Make a link to customize if this variable can be customized.
559 (if (custom-variable-p variable)
560 (let ((customize-label "customize"))
561 (terpri)
562 (terpri)
563 (princ (concat "You can " customize-label " this variable."))
564 (with-current-buffer standard-output
565 (save-excursion
566 (re-search-backward
567 (concat "\\(" customize-label "\\)") nil t)
568 (help-xref-button 1 'help-customize-variable variable)))))
569 ;; Make a hyperlink to the library if appropriate. (Don't
570 ;; change the format of the buffer's initial line in case
571 ;; anything expects the current format.)
572 (let ((file-name (symbol-file (cons 'defvar variable))))
573 (when (equal file-name "loaddefs.el")
574 ;; Find the real def site of the preloaded variable.
575 (let ((location
576 (condition-case nil
577 (find-variable-noselect variable file-name)
578 (error nil))))
579 (when location
580 (with-current-buffer (car location)
581 (goto-char (cdr location))
582 (when (re-search-backward
583 "^;;; Generated autoloads from \\(.*\\)" nil t)
584 (setq file-name (match-string 1)))))))
585 (when (and (null file-name)
586 (integerp (get variable 'variable-documentation)))
587 ;; It's a variable not defined in Elisp but in C.
588 (setq file-name
589 (if (get-buffer " *DOC*")
590 (help-C-file-name variable 'var)
591 'C-source)))
592 (when file-name
593 (princ "\n\nDefined in `")
594 (princ (if (eq file-name 'C-source) "C source code" file-name))
595 (princ "'.")
596 (with-current-buffer standard-output
597 (save-excursion
598 (re-search-backward "`\\([^`']+\\)'" nil t)
599 (help-xref-button 1 'help-variable-def
600 variable file-name)))))
601
602 (print-help-return-message)
603 (save-excursion
604 (set-buffer standard-output)
605 ;; Return the text we displayed.
606 (buffer-string))))))))
607
608
609 ;;;###autoload
610 (defun describe-syntax (&optional buffer)
611 "Describe the syntax specifications in the syntax table of BUFFER.
612 The descriptions are inserted in a help buffer, which is then displayed.
613 BUFFER defaults to the current buffer."
614 (interactive)
615 (setq buffer (or buffer (current-buffer)))
616 (help-setup-xref (list #'describe-syntax buffer) (interactive-p))
617 (with-output-to-temp-buffer (help-buffer)
618 (let ((table (with-current-buffer buffer (syntax-table))))
619 (with-current-buffer standard-output
620 (describe-vector table 'internal-describe-syntax-value)
621 (while (setq table (char-table-parent table))
622 (insert "\nThe parent syntax table is:")
623 (describe-vector table 'internal-describe-syntax-value))))))
624
625 (defun help-describe-category-set (value)
626 (insert (cond
627 ((null value) "default")
628 ((char-table-p value) "deeper char-table ...")
629 (t (condition-case err
630 (category-set-mnemonics value)
631 (error "invalid"))))))
632
633 ;;;###autoload
634 (defun describe-categories (&optional buffer)
635 "Describe the category specifications in the current category table.
636 The descriptions are inserted in a buffer, which is then displayed.
637 If BUFFER is non-nil, then describe BUFFER's category table instead.
638 BUFFER should be a buffer or a buffer name."
639 (interactive)
640 (setq buffer (or buffer (current-buffer)))
641 (help-setup-xref (list #'describe-categories buffer) (interactive-p))
642 (with-output-to-temp-buffer (help-buffer)
643 (let ((table (with-current-buffer buffer (category-table))))
644 (with-current-buffer standard-output
645 (describe-vector table 'help-describe-category-set)
646 (let ((docs (char-table-extra-slot table 0)))
647 (if (or (not (vectorp docs)) (/= (length docs) 95))
648 (insert "Invalid first extra slot in this char table\n")
649 (insert "Meanings of mnemonic characters are:\n")
650 (dotimes (i 95)
651 (let ((elt (aref docs i)))
652 (when elt
653 (insert (+ i ?\ ) ": " elt "\n"))))
654 (while (setq table (char-table-parent table))
655 (insert "\nThe parent category table is:")
656 (describe-vector table 'help-describe-category-set))))))))
657
658 (provide 'help-fns)
659
660 ;;; arch-tag: 9e10331c-ae81-4d13-965d-c4819aaab0b3
661 ;;; help-fns.el ends here