]> code.delx.au - gnu-emacs/blob - lisp/help-fns.el
Merged from miles@gnu.org--gnu-2005 (patch 469)
[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., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, 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 (setq buffer-undo-list nil)
101 (set-buffer-modified-p nil))))
102
103 ;;;###autoload
104 (defun locate-library (library &optional nosuffix path interactive-call)
105 "Show the precise file name of Emacs library LIBRARY.
106 This command searches the directories in `load-path' like `\\[load-library]'
107 to find the file that `\\[load-library] RET LIBRARY RET' would load.
108 Optional second arg NOSUFFIX non-nil means don't add suffixes `load-suffixes'
109 to the specified name LIBRARY.
110
111 If the optional third arg PATH is specified, that list of directories
112 is used instead of `load-path'.
113
114 When called from a program, the file name is normaly returned as a
115 string. When run interactively, the argument INTERACTIVE-CALL is t,
116 and the file name is displayed in the echo area."
117 (interactive (list (completing-read "Locate library: "
118 'locate-file-completion
119 (cons load-path load-suffixes))
120 nil nil
121 t))
122 (let ((file (locate-file library
123 (or path load-path)
124 (append (unless nosuffix load-suffixes) '("")))))
125 (if interactive-call
126 (if file
127 (message "Library is file %s" (abbreviate-file-name file))
128 (message "No library %s in search path" library)))
129 file))
130
131 \f
132 ;; Functions
133
134 ;;;###autoload
135 (defun describe-function (function)
136 "Display the full documentation of FUNCTION (a symbol)."
137 (interactive
138 (let ((fn (function-called-at-point))
139 (enable-recursive-minibuffers t)
140 val)
141 (setq val (completing-read (if fn
142 (format "Describe function (default %s): " fn)
143 "Describe function: ")
144 obarray 'fboundp t nil nil (symbol-name fn)))
145 (list (if (equal val "")
146 fn (intern val)))))
147 (if (null function)
148 (message "You didn't specify a function")
149 (help-setup-xref (list #'describe-function function) (interactive-p))
150 (save-excursion
151 (with-output-to-temp-buffer (help-buffer)
152 (prin1 function)
153 ;; Use " is " instead of a colon so that
154 ;; it is easier to get out the function name using forward-sexp.
155 (princ " is ")
156 (describe-function-1 function)
157 (print-help-return-message)
158 (with-current-buffer standard-output
159 ;; Return the text we displayed.
160 (buffer-string))))))
161
162 (defun help-split-fundoc (docstring def)
163 "Split a function DOCSTRING into the actual doc and the usage info.
164 Return (USAGE . DOC) or nil if there's no usage info.
165 DEF is the function whose usage we're looking for in DOCSTRING."
166 ;; Functions can get the calling sequence at the end of the doc string.
167 ;; In cases where `function' has been fset to a subr we can't search for
168 ;; function's name in the doc string so we use `fn' as the anonymous
169 ;; function name instead.
170 (when (and docstring (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" docstring))
171 (cons (format "(%s%s"
172 ;; Replace `fn' with the actual function name.
173 (if (consp def) "anonymous" def)
174 (match-string 1 docstring))
175 (substring docstring 0 (match-beginning 0)))))
176
177 (defun help-add-fundoc-usage (docstring arglist)
178 "Add the usage info to DOCSTRING.
179 If DOCSTRING already has a usage info, then just return it unchanged.
180 The usage info is built from ARGLIST. DOCSTRING can be nil.
181 ARGLIST can also be t or a string of the form \"(FUN ARG1 ARG2 ...)\"."
182 (unless (stringp docstring) (setq docstring "Not documented"))
183 (if (or (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" docstring) (eq arglist t))
184 docstring
185 (concat docstring
186 (if (string-match "\n?\n\\'" docstring)
187 (if (< (- (match-end 0) (match-beginning 0)) 2) "\n" "")
188 "\n\n")
189 (if (and (stringp arglist)
190 (string-match "\\`([^ ]+\\(.*\\))\\'" arglist))
191 (concat "(fn" (match-string 1 arglist) ")")
192 (format "%S" (help-make-usage 'fn arglist))))))
193
194 (defun help-function-arglist (def)
195 ;; Handle symbols aliased to other symbols.
196 (if (and (symbolp def) (fboundp def)) (setq def (indirect-function def)))
197 ;; If definition is a macro, find the function inside it.
198 (if (eq (car-safe def) 'macro) (setq def (cdr def)))
199 (cond
200 ((byte-code-function-p def) (aref def 0))
201 ((eq (car-safe def) 'lambda) (nth 1 def))
202 ((and (eq (car-safe def) 'autoload) (not (eq (nth 4 def) 'keymap)))
203 "[Arg list not available until function definition is loaded.]")
204 (t t)))
205
206 (defun help-make-usage (function arglist)
207 (cons (if (symbolp function) function 'anonymous)
208 (mapcar (lambda (arg)
209 (if (not (symbolp arg))
210 (if (and (consp arg) (symbolp (car arg)))
211 ;; CL style default values for optional args.
212 (cons (intern (upcase (symbol-name (car arg))))
213 (cdr arg))
214 arg)
215 (let ((name (symbol-name arg)))
216 (if (string-match "\\`&" name) arg
217 (intern (upcase name))))))
218 arglist)))
219
220 ;;; Could be this, if we make symbol-file do the work below.
221 ;;; (defun help-C-file-name (subr-or-var kind)
222 ;;; "Return the name of the C file where SUBR-OR-VAR is defined.
223 ;;; KIND should be `var' for a variable or `subr' for a subroutine."
224 ;;; (symbol-file (if (symbolp subr-or-var) subr-or-var
225 ;;; (subr-name subr-or-var))
226 ;;; (if (eq kind 'var) 'defvar 'defun)))
227 ;;;###autoload
228 (defun help-C-file-name (subr-or-var kind)
229 "Return the name of the C file where SUBR-OR-VAR is defined.
230 KIND should be `var' for a variable or `subr' for a subroutine."
231 (let ((docbuf (get-buffer-create " *DOC*"))
232 (name (if (eq 'var kind)
233 (concat "V" (symbol-name subr-or-var))
234 (concat "F" (subr-name subr-or-var)))))
235 (with-current-buffer docbuf
236 (goto-char (point-min))
237 (if (eobp)
238 (insert-file-contents-literally
239 (expand-file-name internal-doc-file-name doc-directory)))
240 (let ((file (catch 'loop
241 (while t
242 (let ((pnt (search-forward (concat "\1f" name "\n"))))
243 (re-search-backward "\1fS\\(.*\\)")
244 (let ((file (match-string 1)))
245 (if (member file build-files)
246 (throw 'loop file)
247 (goto-char pnt))))))))
248 (if (string-match "\\.\\(o\\|obj\\)\\'" file)
249 (setq file (replace-match ".c" t t file)))
250 (if (string-match "\\.c\\'" file)
251 (concat "src/" file)
252 file)))))
253
254 ;;;###autoload
255 (defface help-argument-name '((((supports :slant italic)) :inherit italic))
256 "Face to highlight argument names in *Help* buffers."
257 :group 'help)
258
259 (defun help-default-arg-highlight (arg)
260 "Default function to highlight arguments in *Help* buffers.
261 It returns ARG in face `help-argument-name'; ARG is also
262 downcased if it displays differently than the default
263 face (according to `face-differs-from-default-p')."
264 (propertize (if (face-differs-from-default-p 'help-argument-name)
265 (downcase arg)
266 arg)
267 'face 'help-argument-name))
268
269 (defun help-do-arg-highlight (doc args)
270 (with-syntax-table (make-syntax-table emacs-lisp-mode-syntax-table)
271 (modify-syntax-entry ?\- "w")
272 (while args
273 (let ((arg (prog1 (car args) (setq args (cdr args)))))
274 (setq doc (replace-regexp-in-string
275 ;; This is heuristic, but covers all common cases
276 ;; except ARG1-ARG2
277 (concat "\\<" ; beginning of word
278 "\\(?:[a-z-]*-\\)?" ; for xxx-ARG
279 "\\("
280 (regexp-quote arg)
281 "\\)"
282 "\\(?:es\\|s\\|th\\)?" ; for ARGth, ARGs
283 "\\(?:-[a-z-]+\\)?" ; for ARG-xxx
284 "\\>") ; end of word
285 (help-default-arg-highlight arg)
286 doc t t 1))))
287 doc))
288
289 (defun help-highlight-arguments (usage doc &rest args)
290 (when usage
291 (with-temp-buffer
292 (insert usage)
293 (goto-char (point-min))
294 (let ((case-fold-search nil)
295 (next (not (or args (looking-at "\\["))))
296 (opt nil))
297 ;; Make a list of all arguments
298 (skip-chars-forward "^ ")
299 (while next
300 (or opt (not (looking-at " &")) (setq opt t))
301 (if (not (re-search-forward " \\([\\[(]*\\)\\([^] &)\.]+\\)" nil t))
302 (setq next nil)
303 (setq args (cons (match-string 2) args))
304 (when (and opt (string= (match-string 1) "("))
305 ;; A pesky CL-style optional argument with default value,
306 ;; so let's skip over it
307 (search-backward "(")
308 (goto-char (scan-sexps (point) 1)))))
309 ;; Highlight aguments in the USAGE string
310 (setq usage (help-do-arg-highlight (buffer-string) args))
311 ;; Highlight arguments in the DOC string
312 (setq doc (and doc (help-do-arg-highlight doc args))))))
313 ;; Return value is like the one from help-split-fundoc, but highlighted
314 (cons usage doc))
315
316 ;;;###autoload
317 (defun describe-function-1 (function)
318 (let* ((def (if (symbolp function)
319 (symbol-function function)
320 function))
321 file-name string
322 (beg (if (commandp def) "an interactive " "a ")))
323 (setq string
324 (cond ((or (stringp def)
325 (vectorp def))
326 "a keyboard macro")
327 ((subrp def)
328 (if (eq 'unevalled (cdr (subr-arity def)))
329 (concat beg "special form")
330 (concat beg "built-in function")))
331 ((byte-code-function-p def)
332 (concat beg "compiled Lisp function"))
333 ((symbolp def)
334 (while (symbolp (symbol-function def))
335 (setq def (symbol-function def)))
336 (format "an alias for `%s'" def))
337 ((eq (car-safe def) 'lambda)
338 (concat beg "Lisp function"))
339 ((eq (car-safe def) 'macro)
340 "a Lisp macro")
341 ((eq (car-safe def) 'autoload)
342 (setq file-name (nth 1 def))
343 (format "%s autoloaded %s"
344 (if (commandp def) "an interactive" "an")
345 (if (eq (nth 4 def) 'keymap) "keymap"
346 (if (nth 4 def) "Lisp macro" "Lisp function"))
347 ))
348 ((keymapp def)
349 (let ((is-full nil)
350 (elts (cdr-safe def)))
351 (while elts
352 (if (char-table-p (car-safe elts))
353 (setq is-full t
354 elts nil))
355 (setq elts (cdr-safe elts)))
356 (if is-full
357 "a full keymap"
358 "a sparse keymap")))
359 (t "")))
360 (princ string)
361 (with-current-buffer standard-output
362 (save-excursion
363 (save-match-data
364 (if (re-search-backward "alias for `\\([^`']+\\)'" nil t)
365 (help-xref-button 1 'help-function def)))))
366 (or file-name
367 (setq file-name (symbol-file function 'defun)))
368 (when (equal file-name "loaddefs.el")
369 ;; Find the real def site of the preloaded function.
370 ;; This is necessary only for defaliases.
371 (let ((location
372 (condition-case nil
373 (find-function-search-for-symbol function nil "loaddefs.el")
374 (error nil))))
375 (when location
376 (with-current-buffer (car location)
377 (goto-char (cdr location))
378 (when (re-search-backward
379 "^;;; Generated autoloads from \\(.*\\)" nil t)
380 (setq file-name (match-string 1)))))))
381 (when (and (null file-name) (subrp def))
382 ;; Find the C source file name.
383 (setq file-name (if (get-buffer " *DOC*")
384 (help-C-file-name def 'subr)
385 'C-source)))
386 (when file-name
387 (princ " in `")
388 ;; We used to add .el to the file name,
389 ;; but that's completely wrong when the user used load-file.
390 (princ (if (eq file-name 'C-source) "C source code" file-name))
391 (princ "'")
392 ;; Make a hyperlink to the library.
393 (with-current-buffer standard-output
394 (save-excursion
395 (re-search-backward "`\\([^`']+\\)'" nil t)
396 (help-xref-button 1 'help-function-def function file-name))))
397 (princ ".")
398 (terpri)
399 (when (commandp function)
400 (let* ((remapped (command-remapping function))
401 (keys (where-is-internal
402 (or remapped function) overriding-local-map nil nil))
403 non-modified-keys)
404 ;; Which non-control non-meta keys run this command?
405 (dolist (key keys)
406 (if (member (event-modifiers (aref key 0)) '(nil (shift)))
407 (push key non-modified-keys)))
408 (when remapped
409 (princ "It is remapped to `")
410 (princ (symbol-name remapped))
411 (princ "'"))
412
413 (when keys
414 (princ (if remapped " which is bound to " "It is bound to "))
415 ;; FIXME: This list can be very long (f.ex. for self-insert-command).
416 ;; If there are many, remove them from KEYS.
417 (if (< (length non-modified-keys) 10)
418 (princ (mapconcat 'key-description keys ", "))
419 (dolist (key non-modified-keys)
420 (setq keys (delq key keys)))
421 (if keys
422 (progn
423 (princ (mapconcat 'key-description keys ", "))
424 (princ ", and many ordinary text characters"))
425 (princ "many ordinary text characters"))))
426 (when (or remapped keys non-modified-keys)
427 (princ ".")
428 (terpri))))
429 (let* ((arglist (help-function-arglist def))
430 (doc (documentation function))
431 (usage (help-split-fundoc doc function)))
432 (with-current-buffer standard-output
433 ;; If definition is a keymap, skip arglist note.
434 (unless (keymapp def)
435 (let* ((use (cond
436 (usage (setq doc (cdr usage)) (car usage))
437 ((listp arglist)
438 (format "%S" (help-make-usage function arglist)))
439 ((stringp arglist) arglist)
440 ;; Maybe the arglist is in the docstring of the alias.
441 ((let ((fun function))
442 (while (and (symbolp fun)
443 (setq fun (symbol-function fun))
444 (not (setq usage (help-split-fundoc
445 (documentation fun)
446 function)))))
447 usage)
448 (car usage))
449 ((or (stringp def)
450 (vectorp def))
451 (format "\nMacro: %s" (format-kbd-macro def)))
452 (t "[Missing arglist. Please make a bug report.]")))
453 (high (help-highlight-arguments use doc)))
454 (insert (car high) "\n")
455 (setq doc (cdr high))))
456 (let ((obsolete (and
457 ;; function might be a lambda construct.
458 (symbolp function)
459 (get function 'byte-obsolete-info))))
460 (when obsolete
461 (princ "\nThis function is obsolete")
462 (when (nth 2 obsolete)
463 (insert (format " since %s" (nth 2 obsolete))))
464 (insert ";\n"
465 (if (stringp (car obsolete)) (car obsolete)
466 (format "use `%s' instead." (car obsolete)))
467 "\n"))
468 (insert "\n"
469 (or doc "Not documented.")))))))
470
471 \f
472 ;; Variables
473
474 ;;;###autoload
475 (defun variable-at-point (&optional any-symbol)
476 "Return the bound variable symbol found around point.
477 Return 0 if there is no such symbol.
478 If ANY-SYMBOL is non-nil, don't insist the symbol be bound."
479 (or (condition-case ()
480 (with-syntax-table emacs-lisp-mode-syntax-table
481 (save-excursion
482 (or (not (zerop (skip-syntax-backward "_w")))
483 (eq (char-syntax (following-char)) ?w)
484 (eq (char-syntax (following-char)) ?_)
485 (forward-sexp -1))
486 (skip-chars-forward "'")
487 (let ((obj (read (current-buffer))))
488 (and (symbolp obj) (boundp obj) obj))))
489 (error nil))
490 (let* ((str (find-tag-default))
491 (sym (if str (intern-soft str))))
492 (if (and sym (or any-symbol (boundp sym)))
493 sym
494 (save-match-data
495 (when (and str (string-match "\\`\\W*\\(.*?\\)\\W*\\'" str))
496 (setq sym (intern-soft (match-string 1 str)))
497 (and (or any-symbol (boundp sym)) sym)))))
498 0))
499
500 ;;;###autoload
501 (defun describe-variable (variable &optional buffer frame)
502 "Display the full documentation of VARIABLE (a symbol).
503 Returns the documentation as a string, also.
504 If VARIABLE has a buffer-local value in BUFFER or FRAME
505 \(default to the current buffer and current frame),
506 it is displayed along with the global value."
507 (interactive
508 (let ((v (variable-at-point))
509 (enable-recursive-minibuffers t)
510 val)
511 (setq val (completing-read (if (symbolp v)
512 (format
513 "Describe variable (default %s): " v)
514 "Describe variable: ")
515 obarray 'boundp t nil nil
516 (if (symbolp v) (symbol-name v))))
517 (list (if (equal val "")
518 v (intern val)))))
519 (unless (buffer-live-p buffer) (setq buffer (current-buffer)))
520 (unless (frame-live-p frame) (setq frame (selected-frame)))
521 (if (not (symbolp variable))
522 (message "You did not specify a variable")
523 (save-excursion
524 (let ((valvoid (not (with-current-buffer buffer (boundp variable))))
525 val locus)
526 ;; Extract the value before setting up the output buffer,
527 ;; in case `buffer' *is* the output buffer.
528 (unless valvoid
529 (with-selected-frame frame
530 (with-current-buffer buffer
531 (setq val (symbol-value variable)
532 locus (variable-binding-locus variable)))))
533 (help-setup-xref (list #'describe-variable variable buffer)
534 (interactive-p))
535 (with-output-to-temp-buffer (help-buffer)
536 (with-current-buffer buffer
537 (prin1 variable)
538 (if valvoid
539 (princ " is void")
540 (with-current-buffer standard-output
541 (princ "'s value is ")
542 (terpri)
543 (let ((from (point)))
544 (pp val)
545 ;; Hyperlinks in variable's value are quite frequently
546 ;; inappropriate e.g C-h v <RET> features <RET>
547 ;; (help-xref-on-pp from (point))
548 (if (< (point) (+ from 20))
549 (delete-region (1- from) from)))))
550 (terpri)
551 (when locus
552 (if (bufferp locus)
553 (princ (format "%socal in buffer %s; "
554 (if (get variable 'permanent-local)
555 "Permanently l" "L")
556 (buffer-name)))
557 (princ (format "It is a frame-local variable; ")))
558 (if (not (default-boundp variable))
559 (princ "globally void")
560 (let ((val (default-value variable)))
561 (with-current-buffer standard-output
562 (princ "global value is ")
563 (terpri)
564 ;; Fixme: pp can take an age if you happen to
565 ;; ask for a very large expression. We should
566 ;; probably print it raw once and check it's a
567 ;; sensible size before prettyprinting. -- fx
568 (let ((from (point)))
569 (pp val)
570 ;; See previous comment for this function.
571 ;; (help-xref-on-pp from (point))
572 (if (< (point) (+ from 20))
573 (delete-region (1- from) from))))))
574 (terpri))
575 (terpri)
576 (with-current-buffer standard-output
577 (when (> (count-lines (point-min) (point-max)) 10)
578 ;; Note that setting the syntax table like below
579 ;; makes forward-sexp move over a `'s' at the end
580 ;; of a symbol.
581 (set-syntax-table emacs-lisp-mode-syntax-table)
582 (goto-char (point-min))
583 (if valvoid
584 (forward-line 1)
585 (forward-sexp 1)
586 (delete-region (point) (progn (end-of-line) (point)))
587 (save-excursion
588 (insert "\n\nValue:")
589 (set (make-local-variable 'help-button-cache)
590 (point-marker)))
591 (insert " value is shown ")
592 (insert-button "below"
593 'action help-button-cache
594 'follow-link t
595 'help-echo "mouse-2, RET: show value")
596 (insert ".\n\n")))
597 ;; Add a note for variables that have been make-var-buffer-local.
598 (when (and (local-variable-if-set-p variable)
599 (or (not (local-variable-p variable))
600 (with-temp-buffer
601 (local-variable-if-set-p variable))))
602 (save-excursion
603 (forward-line -1)
604 (insert "Automatically becomes buffer-local when set in any fashion.\n"))))
605 ;; Mention if it's an alias
606 (let* ((alias (condition-case nil
607 (indirect-variable variable)
608 (error variable)))
609 (obsolete (get variable 'byte-obsolete-variable))
610 (doc (or (documentation-property variable 'variable-documentation)
611 (documentation-property alias 'variable-documentation))))
612 (unless (eq alias variable)
613 (princ (format "This variable is an alias for `%s'." alias))
614 (terpri)
615 (terpri))
616 (when obsolete
617 (princ "This variable is obsolete")
618 (if (cdr obsolete) (princ (format " since %s" (cdr obsolete))))
619 (princ ";") (terpri)
620 (princ (if (stringp (car obsolete)) (car obsolete)
621 (format "use `%s' instead." (car obsolete))))
622 (terpri)
623 (terpri))
624 (princ (or doc "Not documented as a variable.")))
625 ;; Make a link to customize if this variable can be customized.
626 (if (custom-variable-p variable)
627 (let ((customize-label "customize"))
628 (terpri)
629 (terpri)
630 (princ (concat "You can " customize-label " this variable."))
631 (with-current-buffer standard-output
632 (save-excursion
633 (re-search-backward
634 (concat "\\(" customize-label "\\)") nil t)
635 (help-xref-button 1 'help-customize-variable variable)))))
636 ;; Make a hyperlink to the library if appropriate. (Don't
637 ;; change the format of the buffer's initial line in case
638 ;; anything expects the current format.)
639 (let ((file-name (symbol-file variable 'defvar)))
640 (when (equal file-name "loaddefs.el")
641 ;; Find the real def site of the preloaded variable.
642 (let ((location
643 (condition-case nil
644 (find-variable-noselect variable file-name)
645 (error nil))))
646 (when location
647 (with-current-buffer (car location)
648 (goto-char (cdr location))
649 (when (re-search-backward
650 "^;;; Generated autoloads from \\(.*\\)" nil t)
651 (setq file-name (match-string 1)))))))
652 (when (and (null file-name)
653 (integerp (get variable 'variable-documentation)))
654 ;; It's a variable not defined in Elisp but in C.
655 (setq file-name
656 (if (get-buffer " *DOC*")
657 (help-C-file-name variable 'var)
658 'C-source)))
659 (when file-name
660 (princ "\n\nDefined in `")
661 (princ (if (eq file-name 'C-source) "C source code" file-name))
662 (princ "'.")
663 (with-current-buffer standard-output
664 (save-excursion
665 (re-search-backward "`\\([^`']+\\)'" nil t)
666 (help-xref-button 1 'help-variable-def
667 variable file-name)))))
668
669 (print-help-return-message)
670 (save-excursion
671 (set-buffer standard-output)
672 ;; Return the text we displayed.
673 (buffer-string))))))))
674
675
676 ;;;###autoload
677 (defun describe-syntax (&optional buffer)
678 "Describe the syntax specifications in the syntax table of BUFFER.
679 The descriptions are inserted in a help buffer, which is then displayed.
680 BUFFER defaults to the current buffer."
681 (interactive)
682 (setq buffer (or buffer (current-buffer)))
683 (help-setup-xref (list #'describe-syntax buffer) (interactive-p))
684 (with-output-to-temp-buffer (help-buffer)
685 (let ((table (with-current-buffer buffer (syntax-table))))
686 (with-current-buffer standard-output
687 (describe-vector table 'internal-describe-syntax-value)
688 (while (setq table (char-table-parent table))
689 (insert "\nThe parent syntax table is:")
690 (describe-vector table 'internal-describe-syntax-value))))))
691
692 (defun help-describe-category-set (value)
693 (insert (cond
694 ((null value) "default")
695 ((char-table-p value) "deeper char-table ...")
696 (t (condition-case err
697 (category-set-mnemonics value)
698 (error "invalid"))))))
699
700 ;;;###autoload
701 (defun describe-categories (&optional buffer)
702 "Describe the category specifications in the current category table.
703 The descriptions are inserted in a buffer, which is then displayed.
704 If BUFFER is non-nil, then describe BUFFER's category table instead.
705 BUFFER should be a buffer or a buffer name."
706 (interactive)
707 (setq buffer (or buffer (current-buffer)))
708 (help-setup-xref (list #'describe-categories buffer) (interactive-p))
709 (with-output-to-temp-buffer (help-buffer)
710 (let ((table (with-current-buffer buffer (category-table))))
711 (with-current-buffer standard-output
712 (describe-vector table 'help-describe-category-set)
713 (let ((docs (char-table-extra-slot table 0)))
714 (if (or (not (vectorp docs)) (/= (length docs) 95))
715 (insert "Invalid first extra slot in this char table\n")
716 (insert "Meanings of mnemonic characters are:\n")
717 (dotimes (i 95)
718 (let ((elt (aref docs i)))
719 (when elt
720 (insert (+ i ?\ ) ": " elt "\n"))))
721 (while (setq table (char-table-parent table))
722 (insert "\nThe parent category table is:")
723 (describe-vector table 'help-describe-category-set))))))))
724
725 (provide 'help-fns)
726
727 ;;; arch-tag: 9e10331c-ae81-4d13-965d-c4819aaab0b3
728 ;;; help-fns.el ends here