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