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