1 ;;; help-fns.el --- Complex help functions
3 ;; Copyright (C) 1985, 1986, 1993, 1994, 1998, 1999, 2000, 2001, 2002,
4 ;; 2003, 2004, 2005, 2006, 2007, 2008, 2009
5 ;; Free Software Foundation, Inc.
8 ;; Keywords: help, internal
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; This file contains those help commands which are complicated, and
28 ;; which may not be used in every session. For example
29 ;; `describe-function' will probably be heavily used when doing elisp
30 ;; programming, but not if just editing C files. Simpler help commands
40 (defun describe-function (function)
41 "Display the full documentation of FUNCTION (a symbol)."
43 (let ((fn (function-called-at-point))
44 (enable-recursive-minibuffers t
)
46 (setq val
(completing-read (if fn
47 (format "Describe function (default %s): " fn
)
48 "Describe function: ")
49 obarray
'fboundp t nil nil
50 (and fn
(symbol-name fn
))))
51 (list (if (equal val
"")
54 (message "You didn't specify a function")
55 (help-setup-xref (list #'describe-function function
)
56 (called-interactively-p 'interactive
))
58 (with-help-window (help-buffer)
60 ;; Use " is " instead of a colon so that
61 ;; it is easier to get out the function name using forward-sexp.
63 (describe-function-1 function
)
64 (with-current-buffer standard-output
65 ;; Return the text we displayed.
68 (defun help-split-fundoc (docstring def
)
69 "Split a function DOCSTRING into the actual doc and the usage info.
70 Return (USAGE . DOC) or nil if there's no usage info.
71 DEF is the function whose usage we're looking for in DOCSTRING."
72 ;; Functions can get the calling sequence at the end of the doc string.
73 ;; In cases where `function' has been fset to a subr we can't search for
74 ;; function's name in the doc string so we use `fn' as the anonymous
75 ;; function name instead.
76 (when (and docstring
(string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" docstring
))
78 ;; Replace `fn' with the actual function name.
79 (if (consp def
) "anonymous" def
)
80 (match-string 1 docstring
))
81 (substring docstring
0 (match-beginning 0)))))
83 (defun help-add-fundoc-usage (docstring arglist
)
84 "Add the usage info to DOCSTRING.
85 If DOCSTRING already has a usage info, then just return it unchanged.
86 The usage info is built from ARGLIST. DOCSTRING can be nil.
87 ARGLIST can also be t or a string of the form \"(FUN ARG1 ARG2 ...)\"."
88 (unless (stringp docstring
) (setq docstring
"Not documented"))
89 (if (or (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" docstring
) (eq arglist t
))
92 (if (string-match "\n?\n\\'" docstring
)
93 (if (< (- (match-end 0) (match-beginning 0)) 2) "\n" "")
95 (if (and (stringp arglist
)
96 (string-match "\\`([^ ]+\\(.*\\))\\'" arglist
))
97 (concat "(fn" (match-string 1 arglist
) ")")
98 (format "%S" (help-make-usage 'fn arglist
))))))
100 (defun help-function-arglist (def)
101 ;; Handle symbols aliased to other symbols.
102 (if (and (symbolp def
) (fboundp def
)) (setq def
(indirect-function def
)))
103 ;; If definition is a macro, find the function inside it.
104 (let ((advertised (gethash def advertised-signature-table t
)))
105 (if (listp advertised
) advertised
106 (if (eq (car-safe def
) 'macro
) (setq def
(cdr def
)))
108 ((byte-code-function-p def
) (aref def
0))
109 ((eq (car-safe def
) 'lambda
) (nth 1 def
))
110 ((and (eq (car-safe def
) 'autoload
) (not (eq (nth 4 def
) 'keymap
)))
111 "[Arg list not available until function definition is loaded.]")
114 (defun help-make-usage (function arglist
)
115 (cons (if (symbolp function
) function
'anonymous
)
116 (mapcar (lambda (arg)
117 (if (not (symbolp arg
))
118 (if (and (consp arg
) (symbolp (car arg
)))
119 ;; CL style default values for optional args.
120 (cons (intern (upcase (symbol-name (car arg
))))
123 (let ((name (symbol-name arg
)))
124 (if (string-match "\\`&" name
) arg
125 (intern (upcase name
))))))
128 ;; Could be this, if we make symbol-file do the work below.
129 ;; (defun help-C-file-name (subr-or-var kind)
130 ;; "Return the name of the C file where SUBR-OR-VAR is defined.
131 ;; KIND should be `var' for a variable or `subr' for a subroutine."
132 ;; (symbol-file (if (symbolp subr-or-var) subr-or-var
133 ;; (subr-name subr-or-var))
134 ;; (if (eq kind 'var) 'defvar 'defun)))
136 (defun help-C-file-name (subr-or-var kind
)
137 "Return the name of the C file where SUBR-OR-VAR is defined.
138 KIND should be `var' for a variable or `subr' for a subroutine."
139 (let ((docbuf (get-buffer-create " *DOC*"))
140 (name (if (eq 'var kind
)
141 (concat "V" (symbol-name subr-or-var
))
142 (concat "F" (subr-name subr-or-var
)))))
143 (with-current-buffer docbuf
144 (goto-char (point-min))
146 (insert-file-contents-literally
147 (expand-file-name internal-doc-file-name doc-directory
)))
148 (let ((file (catch 'loop
150 (let ((pnt (search-forward (concat "\1f" name
"\n"))))
151 (re-search-backward "\1fS\\(.*\\)")
152 (let ((file (match-string 1)))
153 (if (member file build-files
)
155 (goto-char pnt
))))))))
156 (if (string-match "^ns.*\\(\\.o\\|obj\\)\\'" file
)
157 (setq file
(replace-match ".m" t t file
1))
158 (if (string-match "\\.\\(o\\|obj\\)\\'" file
)
159 (setq file
(replace-match ".c" t t file
))))
160 (if (string-match "\\.\\(c\\|m\\)\\'" file
)
164 (defcustom help-downcase-arguments nil
165 "If non-nil, argument names in *Help* buffers are downcased."
170 (defun help-highlight-arg (arg)
171 "Highlight ARG as an argument name for a *Help* buffer.
172 Return ARG in face `help-argument-name'; ARG is also downcased
173 if the variable `help-downcase-arguments' is non-nil."
174 (propertize (if help-downcase-arguments
(downcase arg
) arg
)
175 'face
'help-argument-name
))
177 (defun help-do-arg-highlight (doc args
)
178 (with-syntax-table (make-syntax-table emacs-lisp-mode-syntax-table
)
179 (modify-syntax-entry ?\-
"w")
180 (dolist (arg args doc
)
181 (setq doc
(replace-regexp-in-string
182 ;; This is heuristic, but covers all common cases
184 (concat "\\<" ; beginning of word
185 "\\(?:[a-z-]*-\\)?" ; for xxx-ARG
189 "\\(?:es\\|s\\|th\\)?" ; for ARGth, ARGs
190 "\\(?:-[a-z0-9-]+\\)?" ; for ARG-xxx, ARG-n
191 "\\(?:-[{([<`\"].*?\\)?"; for ARG-{x}, (x), <x>, [x], `x'
193 (help-highlight-arg arg
)
196 (defun help-highlight-arguments (usage doc
&rest args
)
200 (goto-char (point-min))
201 (let ((case-fold-search nil
)
202 (next (not (or args
(looking-at "\\["))))
204 ;; Make a list of all arguments
205 (skip-chars-forward "^ ")
207 (or opt
(not (looking-at " &")) (setq opt t
))
208 (if (not (re-search-forward " \\([\\[(]*\\)\\([^] &)\.]+\\)" nil t
))
210 (setq args
(cons (match-string 2) args
))
211 (when (and opt
(string= (match-string 1) "("))
212 ;; A pesky CL-style optional argument with default value,
213 ;; so let's skip over it
214 (search-backward "(")
215 (goto-char (scan-sexps (point) 1)))))
216 ;; Highlight aguments in the USAGE string
217 (setq usage
(help-do-arg-highlight (buffer-string) args
))
218 ;; Highlight arguments in the DOC string
219 (setq doc
(and doc
(help-do-arg-highlight doc args
))))))
220 ;; Return value is like the one from help-split-fundoc, but highlighted
223 ;; The following function was compiled from the former functions
224 ;; `describe-simplify-lib-file-name' and `find-source-lisp-file' with
225 ;; some excerpts from `describe-function-1' and `describe-variable'.
226 ;; The only additional twists provided are (1) locate the defining file
227 ;; for autoloaded functions, and (2) give preference to files in the
228 ;; "install directory" (directories found via `load-path') rather than
229 ;; to files in the "compile directory" (directories found by searching
230 ;; the loaddefs.el file). We autoload it because it's also used by
231 ;; `describe-face' (instead of `describe-simplify-lib-file-name').
234 (defun find-lisp-object-file-name (object type
)
235 "Guess the file that defined the Lisp object OBJECT, of type TYPE.
236 OBJECT should be a symbol associated with a function, variable, or face;
237 alternatively, it can be a function definition.
238 If TYPE is `variable', search for a variable definition.
239 If TYPE is `face', search for a face definition.
240 If TYPE is the value returned by `symbol-function' for a function symbol,
241 search for a function definition.
243 The return value is the absolute name of a readable file where OBJECT is
244 defined. If several such files exist, preference is given to a file
245 found via `load-path'. The return value can also be `C-source', which
246 means that OBJECT is a function or variable defined in C. If no
247 suitable file is found, return nil."
248 (let* ((autoloaded (eq (car-safe type
) 'autoload
))
249 (file-name (or (and autoloaded
(nth 1 type
))
251 object
(if (memq type
(list 'defvar
'defface
))
256 ;; An autoloaded function: Locate the file since `symbol-function'
257 ;; has only returned a bare string here.
259 (locate-file file-name load-path
'(".el" ".elc") 'readable
)))
260 ((and (stringp file-name
)
261 (string-match "[.]*loaddefs.el\\'" file-name
))
262 ;; An autoloaded variable or face. Visit loaddefs.el in a buffer
263 ;; and try to extract the defining file. The following form is
264 ;; from `describe-function-1' and `describe-variable'.
267 (find-function-search-for-symbol object nil file-name
)
270 (with-current-buffer (car location
)
271 (goto-char (cdr location
))
272 (when (re-search-backward
273 "^;;; Generated autoloads from \\(.*\\)" nil t
)
276 (file-name-sans-extension
277 (match-string-no-properties 1))
278 load-path
'(".el" ".elc") 'readable
))))))))
281 ((and (not file-name
) (subrp type
))
282 ;; A built-in function. The form is from `describe-function-1'.
283 (if (get-buffer " *DOC*")
284 (help-C-file-name type
'subr
)
286 ((and (not file-name
) (symbolp object
)
287 (integerp (get object
'variable-documentation
)))
288 ;; A variable defined in C. The form is from `describe-variable'.
289 (if (get-buffer " *DOC*")
290 (help-C-file-name object
'var
)
292 ((not (stringp file-name
))
293 ;; If we don't have a file-name string by now, we lost.
296 (if (string-match "[.]elc\\'" file-name
)
297 (substring-no-properties file-name
0 -
1)
299 ;; When the Elisp source file can be found in the install
300 ;; directory return the name of that file - `file-name' should
301 ;; have become an absolute file name ny now.
302 (or (and (file-readable-p lib-name
) lib-name
)
303 ;; The library might be compressed.
304 (and (file-readable-p (concat lib-name
".gz")) lib-name
))))
305 ((let* ((lib-name (file-name-nondirectory file-name
))
306 ;; The next form is from `describe-simplify-lib-file-name'.
308 ;; Try converting the absolute file name to a library
309 ;; name, convert that back to a file name and see if we
310 ;; get the original one. If so, they are equivalent.
311 (if (equal file-name
(locate-file lib-name load-path
'("")))
312 (if (string-match "[.]elc\\'" lib-name
)
313 (substring-no-properties lib-name
0 -
1)
316 ;; The next three forms are from `find-source-lisp-file'.
317 (elc-file (locate-file
319 (if (string-match "\\.el\\'" file-name
)
322 load-path nil
'readable
))
325 (insert-file-contents-literally elc-file nil
0 256)
328 (string-match ";;; from file \\(.*\\.el\\)" str
)
329 (match-string 1 str
))))
330 (and src-file
(file-readable-p src-file
) src-file
))))))
332 (declare-function ad-get-advice-info
"advice" (function))
335 (defun describe-function-1 (function)
336 (let* ((advised (and (symbolp function
) (featurep 'advice
)
337 (ad-get-advice-info function
)))
338 ;; If the function is advised, use the symbol that has the
339 ;; real definition, if that symbol is already set up.
342 (let ((origname (cdr (assq 'origname advised
))))
343 (and (fboundp origname
) origname
)))
345 ;; Get the real definition.
346 (def (if (symbolp real-function
)
347 (symbol-function real-function
)
350 (beg (if (commandp def
) "an interactive " "a "))
351 (pt1 (with-current-buffer (help-buffer) (point)))
354 (cond ((or (stringp def
)
358 (if (eq 'unevalled
(cdr (subr-arity def
)))
359 (concat beg
"special form")
360 (concat beg
"built-in function")))
361 ((byte-code-function-p def
)
362 (concat beg
"compiled Lisp function"))
364 (while (and (fboundp def
)
365 (symbolp (symbol-function def
)))
366 (setq def
(symbol-function def
)))
367 ;; Handle (defalias 'foo 'bar), where bar is undefined.
368 (or (fboundp def
) (setq errtype
'alias
))
369 (format "an alias for `%s'" def
))
370 ((eq (car-safe def
) 'lambda
)
371 (concat beg
"Lisp function"))
372 ((eq (car-safe def
) 'macro
)
374 ((eq (car-safe def
) 'autoload
)
375 (format "%s autoloaded %s"
376 (if (commandp def
) "an interactive" "an")
377 (if (eq (nth 4 def
) 'keymap
) "keymap"
378 (if (nth 4 def
) "Lisp macro" "Lisp function"))))
381 (elts (cdr-safe def
)))
383 (if (char-table-p (car-safe elts
))
386 (setq elts
(cdr-safe elts
)))
392 (if (eq errtype
'alias
)
393 (princ ",\nwhich is not defined. Please make a bug report.")
394 (with-current-buffer standard-output
397 (when (re-search-backward "alias for `\\([^`']+\\)'" nil t
)
398 (help-xref-button 1 'help-function def
)))))
400 (setq file-name
(find-lisp-object-file-name function def
))
403 ;; We used to add .el to the file name,
404 ;; but that's completely wrong when the user used load-file.
405 (princ (if (eq file-name
'C-source
)
407 (file-name-nondirectory file-name
)))
409 ;; Make a hyperlink to the library.
410 (with-current-buffer standard-output
412 (re-search-backward "`\\([^`']+\\)'" nil t
)
413 (help-xref-button 1 'help-function-def function file-name
))))
415 (with-current-buffer (help-buffer)
416 (fill-region-as-paragraph (save-excursion (goto-char pt1
) (forward-line 0) (point))
419 (when (commandp function
)
420 (let ((pt2 (with-current-buffer (help-buffer) (point)))
421 (remapped (command-remapping function
)))
422 (unless (memq remapped
'(ignore undefined
))
423 (let ((keys (where-is-internal
424 (or remapped function
) overriding-local-map nil nil
))
426 (if (and (eq function
'self-insert-command
)
427 (vectorp (car-safe keys
))
428 (consp (aref (car keys
) 0)))
429 (princ "It is bound to many ordinary text characters.\n")
430 ;; Which non-control non-meta keys run this command?
432 (if (member (event-modifiers (aref key
0)) '(nil (shift)))
433 (push key non-modified-keys
)))
435 (princ "It is remapped to `")
436 (princ (symbol-name remapped
))
440 (princ (if remapped
", which is bound to " "It is bound to "))
441 ;; If lots of ordinary text characters run this command,
442 ;; don't mention them one by one.
443 (if (< (length non-modified-keys
) 10)
444 (princ (mapconcat 'key-description keys
", "))
445 (dolist (key non-modified-keys
)
446 (setq keys
(delq key keys
)))
449 (princ (mapconcat 'key-description keys
", "))
450 (princ ", and many ordinary text characters"))
451 (princ "many ordinary text characters"))))
452 (when (or remapped keys non-modified-keys
)
456 (with-current-buffer (help-buffer)
457 (fill-region-as-paragraph pt2
(point))
458 (unless (looking-back "\n\n")
460 ;; Note that list* etc do not get this property until
461 ;; cl-hack-byte-compiler runs, after bytecomp is loaded.
462 (when (eq (get function
'byte-compile
) 'cl-byte-compile-compiler-macro
)
463 (princ "This function has a compiler macro")
464 (let ((lib (get function
'compiler-macro-file
)))
466 (princ (format " in `%s'" lib
))
467 (with-current-buffer standard-output
469 (re-search-backward "`\\([^`']+\\)'" nil t
)
470 (help-xref-button 1 'help-function-cmacro function lib
)))))
472 (let* ((arglist (help-function-arglist def
))
473 (doc (documentation function
))
474 (usage (help-split-fundoc doc function
)))
475 (with-current-buffer standard-output
476 ;; If definition is a keymap, skip arglist note.
477 (unless (keymapp function
)
479 (usage (setq doc
(cdr usage
)) (car usage
))
481 (format "%S" (help-make-usage function arglist
)))
482 ((stringp arglist
) arglist
)
483 ;; Maybe the arglist is in the docstring of a symbol
484 ;; this one is aliased to.
485 ((let ((fun real-function
))
486 (while (and (symbolp fun
)
487 (setq fun
(symbol-function fun
))
488 (not (setq usage
(help-split-fundoc
495 (format "\nMacro: %s" (format-kbd-macro def
)))
496 (t "[Missing arglist. Please make a bug report.]")))
497 (high (help-highlight-arguments use doc
)))
498 (let ((fill-begin (point)))
499 (insert (car high
) "\n")
500 (fill-region fill-begin
(point)))
501 (setq doc
(cdr high
))))
502 (let* ((obsolete (and
503 ;; function might be a lambda construct.
505 (get function
'byte-obsolete-info
)))
506 (use (car obsolete
)))
508 (princ "\nThis function is obsolete")
509 (when (nth 2 obsolete
)
510 (insert (format " since %s" (nth 2 obsolete
))))
511 (insert (cond ((stringp use
) (concat ";\n" use
))
512 (use (format ";\nuse `%s' instead." use
))
516 (or doc
"Not documented."))))))))
522 (defun variable-at-point (&optional any-symbol
)
523 "Return the bound variable symbol found at or before point.
524 Return 0 if there is no such symbol.
525 If ANY-SYMBOL is non-nil, don't insist the symbol be bound."
526 (with-syntax-table emacs-lisp-mode-syntax-table
527 (or (condition-case ()
529 (or (not (zerop (skip-syntax-backward "_w")))
530 (eq (char-syntax (following-char)) ?w
)
531 (eq (char-syntax (following-char)) ?_
)
533 (skip-chars-forward "'")
534 (let ((obj (read (current-buffer))))
535 (and (symbolp obj
) (boundp obj
) obj
)))
537 (let* ((str (find-tag-default))
538 (sym (if str
(intern-soft str
))))
539 (if (and sym
(or any-symbol
(boundp sym
)))
542 (when (and str
(string-match "\\`\\W*\\(.*?\\)\\W*\\'" str
))
543 (setq sym
(intern-soft (match-string 1 str
)))
544 (and (or any-symbol
(boundp sym
)) sym
)))))
547 (defun describe-variable-custom-version-info (variable)
548 (let ((custom-version (get variable
'custom-version
))
549 (cpv (get variable
'custom-package-version
))
553 (format "This variable was introduced, or its default value was changed, in\nversion %s of Emacs.\n"
556 (let* ((package (car-safe cpv
))
557 (version (if (listp (cdr-safe cpv
))
560 (pkg-versions (assq package customize-package-emacs-version-alist
))
561 (emacsv (cdr (assoc version pkg-versions
))))
562 (if (and package version
)
564 (format (concat "This variable was introduced, or its default value was changed, in\nversion %s of the %s package"
566 (format " that is part of Emacs %s" emacsv
))
568 version package
))))))
572 (defun describe-variable (variable &optional buffer frame
)
573 "Display the full documentation of VARIABLE (a symbol).
574 Returns the documentation as a string, also.
575 If VARIABLE has a buffer-local value in BUFFER or FRAME
576 \(default to the current buffer and current frame),
577 it is displayed along with the global value."
579 (let ((v (variable-at-point))
580 (enable-recursive-minibuffers t
)
582 (setq val
(completing-read (if (symbolp v
)
584 "Describe variable (default %s): " v
)
585 "Describe variable: ")
589 (get vv
'variable-documentation
)))
591 (if (symbolp v
) (symbol-name v
))))
592 (list (if (equal val
"")
595 (unless (buffer-live-p buffer
) (setq buffer
(current-buffer)))
596 (unless (frame-live-p frame
) (setq frame
(selected-frame)))
597 (if (not (symbolp variable
))
598 (message "You did not specify a variable")
600 (let ((valvoid (not (with-current-buffer buffer
(boundp variable
))))
601 val val-start-pos locus
)
602 ;; Extract the value before setting up the output buffer,
603 ;; in case `buffer' *is* the output buffer.
605 (with-selected-frame frame
606 (with-current-buffer buffer
607 (setq val
(symbol-value variable
)
608 locus
(variable-binding-locus variable
)))))
609 (help-setup-xref (list #'describe-variable variable buffer
)
610 (called-interactively-p 'interactive
))
611 (with-help-window (help-buffer)
612 (with-current-buffer buffer
614 (setq file-name
(find-lisp-object-file-name variable
'defvar
))
618 (princ " is a variable defined in `")
619 (princ (if (eq file-name
'C-source
)
621 (file-name-nondirectory file-name
)))
623 (with-current-buffer standard-output
625 (re-search-backward "`\\([^`']+\\)'" nil t
)
626 (help-xref-button 1 'help-variable-def
627 variable file-name
)))
629 (princ "It is void as a variable.")
632 (princ " is void as a variable.")
636 (with-current-buffer standard-output
637 (setq val-start-pos
(point))
640 (let ((from (point)))
642 ;; Hyperlinks in variable's value are quite frequently
643 ;; inappropriate e.g C-h v <RET> features <RET>
644 ;; (help-xref-on-pp from (point))
645 (if (< (point) (+ from
20))
646 (delete-region (1- from
) from
)))))
651 (princ (format "%socal in buffer %s; "
652 (if (get variable
'permanent-local
)
655 (princ (format "It is a frame-local variable; ")))
656 (if (not (default-boundp variable
))
657 (princ "globally void")
658 (let ((val (default-value variable
)))
659 (with-current-buffer standard-output
660 (princ "global value is ")
662 ;; Fixme: pp can take an age if you happen to
663 ;; ask for a very large expression. We should
664 ;; probably print it raw once and check it's a
665 ;; sensible size before prettyprinting. -- fx
666 (let ((from (point)))
668 ;; See previous comment for this function.
669 ;; (help-xref-on-pp from (point))
670 (if (< (point) (+ from
20))
671 (delete-region (1- from
) from
))))))
674 ;; If the value is large, move it to the end.
675 (with-current-buffer standard-output
676 (when (> (count-lines (point-min) (point-max)) 10)
677 ;; Note that setting the syntax table like below
678 ;; makes forward-sexp move over a `'s' at the end
680 (set-syntax-table emacs-lisp-mode-syntax-table
)
681 (goto-char val-start-pos
)
682 ;; The line below previously read as
683 ;; (delete-region (point) (progn (end-of-line) (point)))
684 ;; which suppressed display of the buffer local value for
686 (when (looking-at "value is") (replace-match ""))
688 (insert "\n\nValue:")
689 (set (make-local-variable 'help-button-cache
)
691 (insert "value is shown ")
692 (insert-button "below"
693 'action help-button-cache
695 'help-echo
"mouse-2, RET: show value")
699 (let* ((alias (condition-case nil
700 (indirect-variable variable
)
702 (obsolete (get variable
'byte-obsolete-variable
))
704 (safe-var (get variable
'safe-local-variable
))
705 (doc (or (documentation-property variable
'variable-documentation
)
706 (documentation-property alias
'variable-documentation
)))
708 ;; Add a note for variables that have been make-var-buffer-local.
709 (when (and (local-variable-if-set-p variable
)
710 (or (not (local-variable-p variable
))
712 (local-variable-if-set-p variable
))))
714 (princ " Automatically becomes buffer-local when set in any fashion.\n"))
716 ;; Mention if it's an alias
717 (unless (eq alias variable
)
719 (princ (format " This variable is an alias for `%s'.\n" alias
)))
723 (princ " This variable is obsolete")
724 (if (cdr obsolete
) (princ (format " since %s" (cdr obsolete
))))
725 (princ (cond ((stringp use
) (concat ";\n " use
))
726 (use (format ";\n use `%s' instead." (car obsolete
)))
730 (when (member (cons variable val
) file-local-variables-alist
)
732 (if (member (cons variable val
) dir-local-variables-alist
)
733 (let ((file (and (buffer-file-name)
734 (not (file-remote-p (buffer-file-name)))
735 (dir-locals-find-file (buffer-file-name)))))
736 (princ " This variable is a directory local variable")
738 (princ (concat "\n from the file \""
744 (princ " This variable is a file local variable.\n")))
746 (when (memq variable ignored-local-variables
)
748 (princ " This variable is ignored when used as a file local \
751 ;; Can be both risky and safe, eg auto-fill-function.
752 (when (risky-local-variable-p variable
)
754 (princ " This variable is potentially risky when used as a \
755 file local variable.\n")
756 (when (assq variable safe-local-variable-values
)
757 (princ " However, you have added it to \
758 `safe-local-variable-values'.\n")))
762 (princ " This variable is safe as a file local variable ")
763 (princ "if its value\n satisfies the predicate ")
764 (princ (if (byte-code-function-p safe-var
)
765 "which is byte-compiled expression.\n"
766 (format "`%s'.\n" safe-var
))))
768 (if extra-line
(terpri))
769 (princ "Documentation:\n")
770 (with-current-buffer standard-output
771 (insert (or doc
"Not documented as a variable."))))
773 ;; Make a link to customize if this variable can be customized.
774 (when (custom-variable-p variable
)
775 (let ((customize-label "customize"))
778 (princ (concat "You can " customize-label
" this variable."))
779 (with-current-buffer standard-output
782 (concat "\\(" customize-label
"\\)") nil t
)
783 (help-xref-button 1 'help-customize-variable variable
))))
784 ;; Note variable's version or package version
785 (let ((output (describe-variable-custom-version-info variable
)))
792 (set-buffer standard-output
)
793 ;; Return the text we displayed.
794 (buffer-string))))))))
798 (defun describe-syntax (&optional buffer
)
799 "Describe the syntax specifications in the syntax table of BUFFER.
800 The descriptions are inserted in a help buffer, which is then displayed.
801 BUFFER defaults to the current buffer."
803 (setq buffer
(or buffer
(current-buffer)))
804 (help-setup-xref (list #'describe-syntax buffer
)
805 (called-interactively-p 'interactive
))
806 (with-help-window (help-buffer)
807 (let ((table (with-current-buffer buffer
(syntax-table))))
808 (with-current-buffer standard-output
809 (describe-vector table
'internal-describe-syntax-value
)
810 (while (setq table
(char-table-parent table
))
811 (insert "\nThe parent syntax table is:")
812 (describe-vector table
'internal-describe-syntax-value
))))))
814 (defun help-describe-category-set (value)
816 ((null value
) "default")
817 ((char-table-p value
) "deeper char-table ...")
818 (t (condition-case err
819 (category-set-mnemonics value
)
820 (error "invalid"))))))
823 (defun describe-categories (&optional buffer
)
824 "Describe the category specifications in the current category table.
825 The descriptions are inserted in a buffer, which is then displayed.
826 If BUFFER is non-nil, then describe BUFFER's category table instead.
827 BUFFER should be a buffer or a buffer name."
829 (setq buffer
(or buffer
(current-buffer)))
830 (help-setup-xref (list #'describe-categories buffer
)
831 (called-interactively-p 'interactive
))
832 (with-help-window (help-buffer)
833 (let* ((table (with-current-buffer buffer
(category-table)))
834 (docs (char-table-extra-slot table
0)))
835 (if (or (not (vectorp docs
)) (/= (length docs
) 95))
836 (error "Invalid first extra slot in this category table\n"))
837 (with-current-buffer standard-output
838 (insert "Legend of category mnemonics (see the tail for the longer description)\n")
839 (let ((pos (point)) (items 0) lines n
)
841 (if (aref docs i
) (setq items
(1+ items
))))
842 (setq lines
(1+ (/ (1- items
) 4)))
845 (let ((elt (aref docs i
)))
847 (string-match ".*" elt
)
848 (setq elt
(match-string 0 elt
))
849 (if (>= (length elt
) 17)
850 (setq elt
(concat (substring elt
0 14) "...")))
851 (if (< (point) (point-max))
852 (move-to-column (* 20 (/ n lines
)) t
))
853 (insert (+ i ?\s
) ?
: elt
)
854 (if (< (point) (point-max))
858 (if (= (% n lines
) 0)
860 (goto-char (point-max))
862 "character(s)\tcategory mnemonics\n"
863 "------------\t------------------")
864 (describe-vector table
'help-describe-category-set
)
865 (insert "Legend of category mnemonics:\n")
867 (let ((elt (aref docs i
)))
869 (if (string-match "\n" elt
)
870 (setq elt
(substring elt
(match-end 0))))
871 (insert (+ i ?\s
) ": " elt
"\n"))))
872 (while (setq table
(char-table-parent table
))
873 (insert "\nThe parent category table is:")
874 (describe-vector table
'help-describe-category-set
))))))
878 ;; arch-tag: 9e10331c-ae81-4d13-965d-c4819aaab0b3
879 ;;; help-fns.el ends here