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