(set-visited-file-name, file-expand-wildcards): Fix docstring.
[emacs.git] / lisp / help-fns.el
blobdf8f93598533ba9a79094014f066707b37bc6f4d
1 ;;; help-fns.el --- Complex help functions
3 ;; Copyright (C) 1985, 86, 93, 94, 98, 1999, 2000, 01, 02, 03, 2004
4 ;; Free Software Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: help, internal
9 ;; This file is part of GNU Emacs.
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.
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.
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.
26 ;;; Commentary:
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
34 ;;; Code:
36 (require 'help-mode)
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]"))
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))
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))))
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.
110 If the optional third arg PATH is specified, that list of directories
111 is used instead of `load-path'.
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
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))
131 ;; Functions
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))))))
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)))))
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))
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)))))
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)))
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)))
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 "\x1f" name "\n"))
232 (re-search-backward "\x1fS\\(.*\\)")
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)))))
240 (defface help-argument-name '((t (:slant italic)))
241 "Face to highlight function arguments in docstrings.")
243 (defun help-do-arg-highlight (doc args)
244 (with-syntax-table (make-syntax-table emacs-lisp-mode-syntax-table)
245 (modify-syntax-entry ?\- "w")
246 (while args
247 (let ((arg (prog1 (car args) (setq args (cdr args)))))
248 (setq doc (replace-regexp-in-string
249 (concat "\\<\\(" arg "\\)\\(?:es\\|s\\|th\\)?\\>")
250 (propertize arg 'face 'help-argument-name)
251 doc t t 1))))
252 doc))
254 (defun help-highlight-arguments (usage doc &rest args)
255 (when usage
256 (with-temp-buffer
257 (insert usage)
258 (goto-char (point-min))
259 (let ((case-fold-search nil)
260 (next (not (or args (looking-at "\\["))))
261 (opt nil))
262 ;; Make a list of all arguments
263 (while next
264 (or opt (not (looking-at " &")) (setq opt t))
265 (if (not (re-search-forward " \\([\\[(]*\\)\\([^] &)\.]+\\)" nil t))
266 (setq next nil)
267 (setq args (cons (match-string 2) args))
268 (when (and opt (string= (match-string 1) "("))
269 ;; A pesky CL-style optional argument with default value,
270 ;; so let's skip over it
271 (search-backward "(")
272 (goto-char (scan-sexps (point) 1)))))
273 ;; Highlight aguments in the USAGE string
274 (setq usage (help-do-arg-highlight (buffer-string) args))
275 ;; Highlight arguments in the DOC string
276 (setq doc (and doc (help-do-arg-highlight doc args))))))
277 ;; Return value is like the one from help-split-fundoc, but highlighted
278 (cons usage doc))
280 ;;;###autoload
281 (defun describe-function-1 (function)
282 (let* ((def (if (symbolp function)
283 (symbol-function function)
284 function))
285 file-name string
286 (beg (if (commandp def) "an interactive " "a ")))
287 (setq string
288 (cond ((or (stringp def)
289 (vectorp def))
290 "a keyboard macro")
291 ((subrp def)
292 (if (eq 'unevalled (cdr (subr-arity def)))
293 (concat beg "special form")
294 (concat beg "built-in function")))
295 ((byte-code-function-p def)
296 (concat beg "compiled Lisp function"))
297 ((symbolp def)
298 (while (symbolp (symbol-function def))
299 (setq def (symbol-function def)))
300 (format "an alias for `%s'" def))
301 ((eq (car-safe def) 'lambda)
302 (concat beg "Lisp function"))
303 ((eq (car-safe def) 'macro)
304 "a Lisp macro")
305 ((eq (car-safe def) 'autoload)
306 (setq file-name (nth 1 def))
307 (format "%s autoloaded %s"
308 (if (commandp def) "an interactive" "an")
309 (if (eq (nth 4 def) 'keymap) "keymap"
310 (if (nth 4 def) "Lisp macro" "Lisp function"))
312 ((keymapp def)
313 (let ((is-full nil)
314 (elts (cdr-safe def)))
315 (while elts
316 (if (char-table-p (car-safe elts))
317 (setq is-full t
318 elts nil))
319 (setq elts (cdr-safe elts)))
320 (if is-full
321 "a full keymap"
322 "a sparse keymap")))
323 (t "")))
324 (princ string)
325 (with-current-buffer standard-output
326 (save-excursion
327 (save-match-data
328 (if (re-search-backward "alias for `\\([^`']+\\)'" nil t)
329 (help-xref-button 1 'help-function def)))))
330 (or file-name
331 (setq file-name (symbol-file function)))
332 (when (equal file-name "loaddefs.el")
333 ;; Find the real def site of the preloaded function.
334 ;; This is necessary only for defaliases.
335 (let ((location
336 (condition-case nil
337 (find-function-search-for-symbol function nil "loaddefs.el")
338 (error nil))))
339 (when location
340 (with-current-buffer (car location)
341 (goto-char (cdr location))
342 (when (re-search-backward
343 "^;;; Generated autoloads from \\(.*\\)" nil t)
344 (setq file-name (match-string 1)))))))
345 (when (and (null file-name) (subrp def))
346 ;; Find the C source file name.
347 (setq file-name (if (get-buffer " *DOC*")
348 (help-C-file-name def 'subr)
349 'C-source)))
350 (when file-name
351 (princ " in `")
352 ;; We used to add .el to the file name,
353 ;; but that's completely wrong when the user used load-file.
354 (princ (if (eq file-name 'C-source) "C source code" file-name))
355 (princ "'")
356 ;; Make a hyperlink to the library.
357 (with-current-buffer standard-output
358 (save-excursion
359 (re-search-backward "`\\([^`']+\\)'" nil t)
360 (help-xref-button 1 'help-function-def function file-name))))
361 (princ ".")
362 (terpri)
363 (when (commandp function)
364 (let* ((remapped (command-remapping function))
365 (keys (where-is-internal
366 (or remapped function) overriding-local-map nil nil))
367 non-modified-keys)
368 ;; Which non-control non-meta keys run this command?
369 (dolist (key keys)
370 (if (member (event-modifiers (aref key 0)) '(nil (shift)))
371 (push key non-modified-keys)))
372 (when remapped
373 (princ "It is remapped to `")
374 (princ (symbol-name remapped))
375 (princ "'"))
377 (when keys
378 (princ (if remapped " which is bound to " "It is bound to "))
379 ;; FIXME: This list can be very long (f.ex. for self-insert-command).
380 ;; If there are many, remove them from KEYS.
381 (if (< (length non-modified-keys) 10)
382 (princ (mapconcat 'key-description keys ", "))
383 (dolist (key non-modified-keys)
384 (setq keys (delq key keys)))
385 (if keys
386 (progn
387 (princ (mapconcat 'key-description keys ", "))
388 (princ ", and many ordinary text characters"))
389 (princ "many ordinary text characters"))))
390 (when (or remapped keys non-modified-keys)
391 (princ ".")
392 (terpri))))
393 (let* ((arglist (help-function-arglist def))
394 (doc (documentation function))
395 (usage (help-split-fundoc doc function)))
396 (with-current-buffer standard-output
397 ;; If definition is a keymap, skip arglist note.
398 (unless (keymapp def)
399 (let* ((use (cond
400 (usage (setq doc (cdr usage)) (car usage))
401 ((listp arglist)
402 (format "%S" (help-make-usage function arglist)))
403 ((stringp arglist) arglist)
404 ;; Maybe the arglist is in the docstring of the alias.
405 ((let ((fun function))
406 (while (and (symbolp fun)
407 (setq fun (symbol-function fun))
408 (not (setq usage (help-split-fundoc
409 (documentation fun)
410 function)))))
411 usage)
412 (car usage))
413 ((or (stringp def)
414 (vectorp def))
415 (format "\nMacro: %s" (format-kbd-macro def)))
416 (t "[Missing arglist. Please make a bug report.]")))
417 (high (help-highlight-arguments use doc)))
418 (insert (car high) "\n")
419 (setq doc (cdr high))))
420 (let ((obsolete (and
421 ;; function might be a lambda construct.
422 (symbolp function)
423 (get function 'byte-obsolete-info))))
424 (when obsolete
425 (princ "\nThis function is obsolete")
426 (when (nth 2 obsolete)
427 (insert (format " since %s" (nth 2 obsolete))))
428 (insert ";\n"
429 (if (stringp (car obsolete)) (car obsolete)
430 (format "use `%s' instead." (car obsolete)))
431 "\n"))
432 (insert "\n"
433 (or doc "Not documented.")))))))
436 ;; Variables
438 ;;;###autoload
439 (defun variable-at-point ()
440 "Return the bound variable symbol found around point.
441 Return 0 if there is no such symbol."
442 (condition-case ()
443 (with-syntax-table emacs-lisp-mode-syntax-table
444 (save-excursion
445 (or (not (zerop (skip-syntax-backward "_w")))
446 (eq (char-syntax (following-char)) ?w)
447 (eq (char-syntax (following-char)) ?_)
448 (forward-sexp -1))
449 (skip-chars-forward "'")
450 (let ((obj (read (current-buffer))))
451 (or (and (symbolp obj) (boundp obj) obj)
452 0))))
453 (error 0)))
455 ;;;###autoload
456 (defun describe-variable (variable &optional buffer)
457 "Display the full documentation of VARIABLE (a symbol).
458 Returns the documentation as a string, also.
459 If VARIABLE has a buffer-local value in BUFFER (default to the current buffer),
460 it is displayed along with the global value."
461 (interactive
462 (let ((v (variable-at-point))
463 (enable-recursive-minibuffers t)
464 val)
465 (setq val (completing-read (if (symbolp v)
466 (format
467 "Describe variable (default %s): " v)
468 "Describe variable: ")
469 obarray 'boundp t nil nil
470 (if (symbolp v) (symbol-name v))))
471 (list (if (equal val "")
472 v (intern val)))))
473 (unless (buffer-live-p buffer) (setq buffer (current-buffer)))
474 (if (not (symbolp variable))
475 (message "You did not specify a variable")
476 (save-excursion
477 (let* ((valvoid (not (with-current-buffer buffer (boundp variable))))
478 ;; Extract the value before setting up the output buffer,
479 ;; in case `buffer' *is* the output buffer.
480 (val (unless valvoid (buffer-local-value variable buffer))))
481 (help-setup-xref (list #'describe-variable variable buffer)
482 (interactive-p))
483 (with-output-to-temp-buffer (help-buffer)
484 (with-current-buffer buffer
485 (prin1 variable)
486 (if valvoid
487 (princ " is void")
488 (with-current-buffer standard-output
489 (princ "'s value is ")
490 (terpri)
491 (let ((from (point)))
492 (pp val)
493 (help-xref-on-pp from (point))
494 (if (< (point) (+ from 20))
495 (delete-region (1- from) from)))))
496 (terpri)
497 (when (local-variable-p variable)
498 (princ (format "%socal in buffer %s; "
499 (if (get variable 'permanent-local)
500 "Permanently l" "L")
501 (buffer-name)))
502 (if (not (default-boundp variable))
503 (princ "globally void")
504 (let ((val (default-value variable)))
505 (with-current-buffer standard-output
506 (princ "global value is ")
507 (terpri)
508 ;; Fixme: pp can take an age if you happen to
509 ;; ask for a very large expression. We should
510 ;; probably print it raw once and check it's a
511 ;; sensible size before prettyprinting. -- fx
512 (let ((from (point)))
513 (pp val)
514 (help-xref-on-pp from (point))
515 (if (< (point) (+ from 20))
516 (delete-region (1- from) from))))))
517 (terpri))
518 (terpri)
519 (with-current-buffer standard-output
520 (when (> (count-lines (point-min) (point-max)) 10)
521 ;; Note that setting the syntax table like below
522 ;; makes forward-sexp move over a `'s' at the end
523 ;; of a symbol.
524 (set-syntax-table emacs-lisp-mode-syntax-table)
525 (goto-char (point-min))
526 (if valvoid
527 (forward-line 1)
528 (forward-sexp 1)
529 (delete-region (point) (progn (end-of-line) (point)))
530 (insert " value is shown below.\n\n")
531 (save-excursion
532 (insert "\n\nValue:"))))
533 ;; Add a note for variables that have been make-var-buffer-local.
534 (when (and (local-variable-if-set-p variable)
535 (or (not (local-variable-p variable))
536 (with-temp-buffer
537 (local-variable-if-set-p variable))))
538 (save-excursion
539 (forward-line -1)
540 (insert "Automatically becomes buffer-local when set in any fashion.\n"))))
541 ;; Mention if it's an alias
542 (let* ((alias (condition-case nil
543 (indirect-variable variable)
544 (error variable)))
545 (obsolete (get variable 'byte-obsolete-variable))
546 (doc (or (documentation-property variable 'variable-documentation)
547 (documentation-property alias 'variable-documentation))))
548 (unless (eq alias variable)
549 (princ (format "This variable is an alias for `%s'." alias))
550 (terpri)
551 (terpri))
552 (when obsolete
553 (princ "This variable is obsolete")
554 (if (cdr obsolete) (princ (format " since %s" (cdr obsolete))))
555 (princ ";") (terpri)
556 (princ (if (stringp (car obsolete)) (car obsolete)
557 (format "use `%s' instead." (car obsolete))))
558 (terpri)
559 (terpri))
560 (princ (or doc "Not documented as a variable.")))
561 ;; Make a link to customize if this variable can be customized.
562 (if (custom-variable-p variable)
563 (let ((customize-label "customize"))
564 (terpri)
565 (terpri)
566 (princ (concat "You can " customize-label " this variable."))
567 (with-current-buffer standard-output
568 (save-excursion
569 (re-search-backward
570 (concat "\\(" customize-label "\\)") nil t)
571 (help-xref-button 1 'help-customize-variable variable)))))
572 ;; Make a hyperlink to the library if appropriate. (Don't
573 ;; change the format of the buffer's initial line in case
574 ;; anything expects the current format.)
575 (let ((file-name (symbol-file (cons 'defvar variable))))
576 (when (equal file-name "loaddefs.el")
577 ;; Find the real def site of the preloaded variable.
578 (let ((location
579 (condition-case nil
580 (find-variable-noselect variable file-name)
581 (error nil))))
582 (when location
583 (with-current-buffer (car location)
584 (goto-char (cdr location))
585 (when (re-search-backward
586 "^;;; Generated autoloads from \\(.*\\)" nil t)
587 (setq file-name (match-string 1)))))))
588 (when (and (null file-name)
589 (integerp (get variable 'variable-documentation)))
590 ;; It's a variable not defined in Elisp but in C.
591 (setq file-name
592 (if (get-buffer " *DOC*")
593 (help-C-file-name variable 'var)
594 'C-source)))
595 (when file-name
596 (princ "\n\nDefined in `")
597 (princ (if (eq file-name 'C-source) "C source code" file-name))
598 (princ "'.")
599 (with-current-buffer standard-output
600 (save-excursion
601 (re-search-backward "`\\([^`']+\\)'" nil t)
602 (help-xref-button 1 'help-variable-def
603 variable file-name)))))
605 (print-help-return-message)
606 (save-excursion
607 (set-buffer standard-output)
608 ;; Return the text we displayed.
609 (buffer-string))))))))
612 ;;;###autoload
613 (defun describe-syntax (&optional buffer)
614 "Describe the syntax specifications in the syntax table of BUFFER.
615 The descriptions are inserted in a help buffer, which is then displayed.
616 BUFFER defaults to the current buffer."
617 (interactive)
618 (setq buffer (or buffer (current-buffer)))
619 (help-setup-xref (list #'describe-syntax buffer) (interactive-p))
620 (with-output-to-temp-buffer (help-buffer)
621 (let ((table (with-current-buffer buffer (syntax-table))))
622 (with-current-buffer standard-output
623 (describe-vector table 'internal-describe-syntax-value)
624 (while (setq table (char-table-parent table))
625 (insert "\nThe parent syntax table is:")
626 (describe-vector table 'internal-describe-syntax-value))))))
628 (defun help-describe-category-set (value)
629 (insert (cond
630 ((null value) "default")
631 ((char-table-p value) "deeper char-table ...")
632 (t (condition-case err
633 (category-set-mnemonics value)
634 (error "invalid"))))))
636 ;;;###autoload
637 (defun describe-categories (&optional buffer)
638 "Describe the category specifications in the current category table.
639 The descriptions are inserted in a buffer, which is then displayed.
640 If BUFFER is non-nil, then describe BUFFER's category table instead.
641 BUFFER should be a buffer or a buffer name."
642 (interactive)
643 (setq buffer (or buffer (current-buffer)))
644 (help-setup-xref (list #'describe-categories buffer) (interactive-p))
645 (with-output-to-temp-buffer (help-buffer)
646 (let ((table (with-current-buffer buffer (category-table))))
647 (with-current-buffer standard-output
648 (describe-vector table 'help-describe-category-set)
649 (let ((docs (char-table-extra-slot table 0)))
650 (if (or (not (vectorp docs)) (/= (length docs) 95))
651 (insert "Invalid first extra slot in this char table\n")
652 (insert "Meanings of mnemonic characters are:\n")
653 (dotimes (i 95)
654 (let ((elt (aref docs i)))
655 (when elt
656 (insert (+ i ?\ ) ": " elt "\n"))))
657 (while (setq table (char-table-parent table))
658 (insert "\nThe parent category table is:")
659 (describe-vector table 'help-describe-category-set))))))))
661 (provide 'help-fns)
663 ;;; arch-tag: 9e10331c-ae81-4d13-965d-c4819aaab0b3
664 ;;; help-fns.el ends here