1 ;;; help-fns.el --- Complex help functions -*- lexical-binding: t -*-
3 ;; Copyright (C) 1985-1986, 1993-1994, 1998-2014 Free Software
6 ;; Maintainer: emacs-devel@gnu.org
7 ;; 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
35 (defvar help-fns-describe-function-functions nil
36 "List of functions to run in help buffer in `describe-function'.
37 Those functions will be run after the header line and argument
38 list was inserted, and before the documentation will be inserted.
39 The functions will receive the function name as argument.")
44 (defun describe-function (function)
45 "Display the full documentation of FUNCTION (a symbol)."
47 (let ((fn (function-called-at-point))
48 (enable-recursive-minibuffers t
)
50 (setq val
(completing-read (if fn
51 (format "Describe function (default %s): " fn
)
52 "Describe function: ")
53 obarray
'fboundp t nil nil
54 (and fn
(symbol-name fn
))))
55 (list (if (equal val
"")
58 (message "You didn't specify a function")
59 (help-setup-xref (list #'describe-function function
)
60 (called-interactively-p 'interactive
))
62 (with-help-window (help-buffer)
64 ;; Use " is " instead of a colon so that
65 ;; it is easier to get out the function name using forward-sexp.
67 (describe-function-1 function
)
68 (with-current-buffer standard-output
69 ;; Return the text we displayed.
73 ;; Could be this, if we make symbol-file do the work below.
74 ;; (defun help-C-file-name (subr-or-var kind)
75 ;; "Return the name of the C file where SUBR-OR-VAR is defined.
76 ;; KIND should be `var' for a variable or `subr' for a subroutine."
77 ;; (symbol-file (if (symbolp subr-or-var) subr-or-var
78 ;; (subr-name subr-or-var))
79 ;; (if (eq kind 'var) 'defvar 'defun)))
81 (defun help-C-file-name (subr-or-var kind
)
82 "Return the name of the C file where SUBR-OR-VAR is defined.
83 KIND should be `var' for a variable or `subr' for a subroutine."
84 (let ((docbuf (get-buffer-create " *DOC*"))
85 (name (if (eq 'var kind
)
86 (concat "V" (symbol-name subr-or-var
))
87 (concat "F" (subr-name (advice--cd*r subr-or-var
))))))
88 (with-current-buffer docbuf
89 (goto-char (point-min))
91 (insert-file-contents-literally
92 (expand-file-name internal-doc-file-name doc-directory
)))
93 (let ((file (catch 'loop
95 (let ((pnt (search-forward (concat "\x1f" name
"\n"))))
96 (re-search-backward "\x1fS\\(.*\\)")
97 (let ((file (match-string 1)))
98 (if (member file build-files
)
100 (goto-char pnt
))))))))
101 (if (string-match "^ns.*\\(\\.o\\|obj\\)\\'" file
)
102 (setq file
(replace-match ".m" t t file
1))
103 (if (string-match "\\.\\(o\\|obj\\)\\'" file
)
104 (setq file
(replace-match ".c" t t file
))))
105 (if (string-match "\\.\\(c\\|m\\)\\'" file
)
109 (defcustom help-downcase-arguments nil
110 "If non-nil, argument names in *Help* buffers are downcased."
115 (defun help-highlight-arg (arg)
116 "Highlight ARG as an argument name for a *Help* buffer.
117 Return ARG in face `help-argument-name'; ARG is also downcased
118 if the variable `help-downcase-arguments' is non-nil."
119 (propertize (if help-downcase-arguments
(downcase arg
) arg
)
120 'face
'help-argument-name
))
122 (defun help-do-arg-highlight (doc args
)
123 (with-syntax-table (make-syntax-table emacs-lisp-mode-syntax-table
)
124 (modify-syntax-entry ?\-
"w")
126 (setq doc
(replace-regexp-in-string
127 ;; This is heuristic, but covers all common cases
129 (concat "\\<" ; beginning of word
130 "\\(?:[a-z-]*-\\)?" ; for xxx-ARG
134 "\\(?:es\\|s\\|th\\)?" ; for ARGth, ARGs
135 "\\(?:-[a-z0-9-]+\\)?" ; for ARG-xxx, ARG-n
136 "\\(?:-[{([<`\"].*?\\)?"; for ARG-{x}, (x), <x>, [x], `x'
138 (help-highlight-arg arg
)
142 (defun help-highlight-arguments (usage doc
&rest args
)
143 (when (and usage
(string-match "^(" usage
))
146 (goto-char (point-min))
147 (let ((case-fold-search nil
)
148 (next (not (or args
(looking-at "\\["))))
150 ;; Make a list of all arguments
151 (skip-chars-forward "^ ")
153 (or opt
(not (looking-at " &")) (setq opt t
))
154 (if (not (re-search-forward " \\([\\[(]*\\)\\([^] &)\.]+\\)" nil t
))
156 (setq args
(cons (match-string 2) args
))
157 (when (and opt
(string= (match-string 1) "("))
158 ;; A pesky CL-style optional argument with default value,
159 ;; so let's skip over it
160 (search-backward "(")
161 (goto-char (scan-sexps (point) 1)))))
162 ;; Highlight arguments in the USAGE string
163 (setq usage
(help-do-arg-highlight (buffer-string) args
))
164 ;; Highlight arguments in the DOC string
165 (setq doc
(and doc
(help-do-arg-highlight doc args
))))))
166 ;; Return value is like the one from help-split-fundoc, but highlighted
169 ;; The following function was compiled from the former functions
170 ;; `describe-simplify-lib-file-name' and `find-source-lisp-file' with
171 ;; some excerpts from `describe-function-1' and `describe-variable'.
172 ;; The only additional twists provided are (1) locate the defining file
173 ;; for autoloaded functions, and (2) give preference to files in the
174 ;; "install directory" (directories found via `load-path') rather than
175 ;; to files in the "compile directory" (directories found by searching
176 ;; the loaddefs.el file). We autoload it because it's also used by
177 ;; `describe-face' (instead of `describe-simplify-lib-file-name').
180 (defun find-lisp-object-file-name (object type
)
181 "Guess the file that defined the Lisp object OBJECT, of type TYPE.
182 OBJECT should be a symbol associated with a function, variable, or face;
183 alternatively, it can be a function definition.
184 If TYPE is `defvar', search for a variable definition.
185 If TYPE is `defface', search for a face definition.
186 If TYPE is the value returned by `symbol-function' for a function symbol,
187 search for a function definition.
189 The return value is the absolute name of a readable file where OBJECT is
190 defined. If several such files exist, preference is given to a file
191 found via `load-path'. The return value can also be `C-source', which
192 means that OBJECT is a function or variable defined in C. If no
193 suitable file is found, return nil."
194 (let* ((autoloaded (autoloadp type
))
195 (file-name (or (and autoloaded
(nth 1 type
))
197 object
(if (memq type
(list 'defvar
'defface
))
202 ;; An autoloaded function: Locate the file since `symbol-function'
203 ;; has only returned a bare string here.
205 (locate-file file-name load-path
'(".el" ".elc") 'readable
)))
206 ((and (stringp file-name
)
207 (string-match "[.]*loaddefs.el\\'" file-name
))
208 ;; An autoloaded variable or face. Visit loaddefs.el in a buffer
209 ;; and try to extract the defining file. The following form is
210 ;; from `describe-function-1' and `describe-variable'.
213 (find-function-search-for-symbol object nil file-name
)
216 (with-current-buffer (car location
)
217 (goto-char (cdr location
))
218 (when (re-search-backward
219 "^;;; Generated autoloads from \\(.*\\)" nil t
)
222 (file-name-sans-extension
223 (match-string-no-properties 1))
224 load-path
'(".el" ".elc") 'readable
))))))))
227 ((and (not file-name
) (subrp type
))
228 ;; A built-in function. The form is from `describe-function-1'.
229 (if (get-buffer " *DOC*")
230 (help-C-file-name type
'subr
)
232 ((and (not file-name
) (symbolp object
)
233 (integerp (get object
'variable-documentation
)))
234 ;; A variable defined in C. The form is from `describe-variable'.
235 (if (get-buffer " *DOC*")
236 (help-C-file-name object
'var
)
238 ((not (stringp file-name
))
239 ;; If we don't have a file-name string by now, we lost.
241 ;; Now, `file-name' should have become an absolute file name.
242 ;; For files loaded from ~/.foo.elc, try ~/.foo.
243 ;; This applies to config files like ~/.emacs,
244 ;; which people sometimes compile.
246 (and (string-match "\\`\\..*\\.elc\\'"
247 (file-name-nondirectory file-name
))
248 (string-equal (file-name-directory file-name
)
249 (file-name-as-directory (expand-file-name "~")))
250 (file-readable-p (setq fn
(file-name-sans-extension file-name
)))
252 ;; When the Elisp source file can be found in the install
253 ;; directory, return the name of that file.
255 (if (string-match "[.]elc\\'" file-name
)
256 (substring-no-properties file-name
0 -
1)
258 (or (and (file-readable-p lib-name
) lib-name
)
259 ;; The library might be compressed.
260 (and (file-readable-p (concat lib-name
".gz")) lib-name
))))
261 ((let* ((lib-name (file-name-nondirectory file-name
))
262 ;; The next form is from `describe-simplify-lib-file-name'.
264 ;; Try converting the absolute file name to a library
265 ;; name, convert that back to a file name and see if we
266 ;; get the original one. If so, they are equivalent.
267 (if (equal file-name
(locate-file lib-name load-path
'("")))
268 (if (string-match "[.]elc\\'" lib-name
)
269 (substring-no-properties lib-name
0 -
1)
272 ;; The next three forms are from `find-source-lisp-file'.
273 (elc-file (locate-file
275 (if (string-match "\\.el\\'" file-name
)
278 load-path nil
'readable
))
281 (insert-file-contents-literally elc-file nil
0 256)
284 (string-match ";;; from file \\(.*\\.el\\)" str
)
285 (match-string 1 str
))))
286 (and src-file
(file-readable-p src-file
) src-file
))))))
288 (defun help-fns--key-bindings (function)
289 (when (commandp function
)
290 (let ((pt2 (with-current-buffer standard-output
(point)))
291 (remapped (command-remapping function
)))
292 (unless (memq remapped
'(ignore undefined
))
293 (let ((keys (where-is-internal
294 (or remapped function
) overriding-local-map nil nil
))
296 (if (and (eq function
'self-insert-command
)
297 (vectorp (car-safe keys
))
298 (consp (aref (car keys
) 0)))
299 (princ "It is bound to many ordinary text characters.\n")
300 ;; Which non-control non-meta keys run this command?
302 (if (member (event-modifiers (aref key
0)) '(nil (shift)))
303 (push key non-modified-keys
)))
305 (princ "Its keys are remapped to ")
306 (princ (if (symbolp remapped
)
307 (concat "`" (symbol-name remapped
) "'")
308 "an anonymous command"))
313 "Without this remapping, it would be bound to "
315 ;; If lots of ordinary text characters run this command,
316 ;; don't mention them one by one.
317 (if (< (length non-modified-keys
) 10)
318 (princ (mapconcat 'key-description keys
", "))
319 (dolist (key non-modified-keys
)
320 (setq keys
(delq key keys
)))
323 (princ (mapconcat 'key-description keys
", "))
324 (princ ", and many ordinary text characters"))
325 (princ "many ordinary text characters"))))
326 (when (or remapped keys non-modified-keys
)
330 (with-current-buffer standard-output
331 (fill-region-as-paragraph pt2
(point))
332 (unless (looking-back "\n\n")
335 (defun help-fns--compiler-macro (function)
336 (let ((handler (function-get function
'compiler-macro
)))
338 (insert "\nThis function has a compiler macro")
339 (if (symbolp handler
)
341 (insert (format " `%s'" handler
))
343 (re-search-backward "`\\([^`']+\\)'" nil t
)
344 (help-xref-button 1 'help-function handler
)))
345 ;; FIXME: Obsolete since 24.4.
346 (let ((lib (get function
'compiler-macro-file
)))
348 (insert (format " in `%s'" lib
))
350 (re-search-backward "`\\([^`']+\\)'" nil t
)
351 (help-xref-button 1 'help-function-cmacro function lib
)))))
354 (defun help-fns--signature (function doc real-def real-function
)
355 (unless (keymapp function
) ; If definition is a keymap, skip arglist note.
356 (let* ((advertised (gethash real-def advertised-signature-table t
))
357 (arglist (if (listp advertised
)
358 advertised
(help-function-arglist real-def
)))
359 (usage (help-split-fundoc doc function
)))
360 (if usage
(setq doc
(cdr usage
)))
362 ((and usage
(not (listp advertised
))) (car usage
))
364 (format "%S" (help-make-usage function arglist
)))
365 ((stringp arglist
) arglist
)
366 ;; Maybe the arglist is in the docstring of a symbol
367 ;; this one is aliased to.
368 ((let ((fun real-function
))
369 (while (and (symbolp fun
)
370 (setq fun
(symbol-function fun
))
371 (not (setq usage
(help-split-fundoc
376 ((or (stringp real-def
)
378 (format "\nMacro: %s" (format-kbd-macro real-def
)))
379 (t "[Missing arglist. Please make a bug report.]")))
380 (high (help-highlight-arguments use doc
)))
381 (let ((fill-begin (point)))
382 (insert (car high
) "\n")
383 (fill-region fill-begin
(point)))
386 (defun help-fns--parent-mode (function)
387 ;; If this is a derived mode, link to the parent.
388 (let ((parent-mode (and (symbolp function
)
390 'derived-mode-parent
))))
392 (insert "\nParent mode: `")
394 (insert (format "%s" parent-mode
))
395 (make-text-button beg
(point)
397 'help-args
(list parent-mode
)))
400 (defun help-fns--obsolete (function)
401 ;; Ignore lambda constructs, keyboard macros, etc.
402 (let* ((obsolete (and (symbolp function
)
403 (get function
'byte-obsolete-info
)))
404 (use (car obsolete
)))
407 (if (eq (car-safe (symbol-function function
)) 'macro
)
411 (when (nth 2 obsolete
)
412 (insert (format " since %s" (nth 2 obsolete
))))
413 (insert (cond ((stringp use
) (concat ";\n" use
))
414 (use (format ";\nuse `%s' instead." use
))
418 ;; We could use `symbol-file' but this is a wee bit more efficient.
419 (defun help-fns--autoloaded-p (function file
)
420 "Return non-nil if FUNCTION has previously been autoloaded.
421 FILE is the file where FUNCTION was probably defined."
422 (let* ((file (file-name-sans-extension (file-truename file
)))
423 (load-hist load-history
)
424 (target (cons t function
))
426 (while (and load-hist
(not found
))
427 (and (caar load-hist
)
428 (equal (file-name-sans-extension (caar load-hist
)) file
)
429 (setq found
(member target
(cdar load-hist
))))
430 (setq load-hist
(cdr load-hist
)))
434 (defun describe-function-1 (function)
435 (let* ((advised (and (symbolp function
)
437 (advice--p (advice--symbol-function function
))))
438 ;; If the function is advised, use the symbol that has the
439 ;; real definition, if that symbol is already set up.
442 (advice--cd*r
(advice--symbol-function function
)))
444 ;; Get the real definition.
445 (def (if (symbolp real-function
)
446 (symbol-function real-function
)
448 (aliased (or (symbolp def
)
449 ;; Advised & aliased function.
450 (and advised
(symbolp real-function
))))
452 (aliased (let ((f real-function
))
453 (while (and (fboundp f
)
454 (symbolp (symbol-function f
)))
455 (setq f
(symbol-function f
)))
457 ((subrp def
) (intern (subr-name def
)))
459 (file-name (find-lisp-object-file-name function def
))
460 (pt1 (with-current-buffer (help-buffer) (point)))
461 (beg (if (and (or (byte-code-function-p def
)
463 (memq (car-safe def
) '(macro lambda closure
)))
465 (help-fns--autoloaded-p function file-name
))
467 "an interactive autoloaded "
469 (if (commandp def
) "an interactive " "a "))))
471 ;; Print what kind of function-like object FUNCTION is.
472 (princ (cond ((or (stringp def
) (vectorp def
))
475 (if (eq 'unevalled
(cdr (subr-arity def
)))
476 (concat beg
"special form")
477 (concat beg
"built-in function")))
478 ;; Aliases are Lisp functions, so we need to check
479 ;; aliases before functions.
481 (format "an alias for `%s'" real-def
))
482 ((or (eq (car-safe def
) 'macro
)
483 ;; For advised macros, def is a lambda
484 ;; expression or a byte-code-function-p, so we
485 ;; need to check macros before functions.
487 (concat beg
"Lisp macro"))
488 ((byte-code-function-p def
)
489 (concat beg
"compiled Lisp function"))
490 ((eq (car-safe def
) 'lambda
)
491 (concat beg
"Lisp function"))
492 ((eq (car-safe def
) 'closure
)
493 (concat beg
"Lisp closure"))
495 (format "%s autoloaded %s"
496 (if (commandp def
) "an interactive" "an")
497 (if (eq (nth 4 def
) 'keymap
) "keymap"
498 (if (nth 4 def
) "Lisp macro" "Lisp function"))))
501 (elts (cdr-safe def
)))
503 (if (char-table-p (car-safe elts
))
506 (setq elts
(cdr-safe elts
)))
507 (concat beg
(if is-full
"keymap" "sparse keymap"))))
510 (if (and aliased
(not (fboundp real-def
)))
511 (princ ",\nwhich is not defined. Please make a bug report.")
512 (with-current-buffer standard-output
515 (when (re-search-backward "alias for `\\([^`']+\\)'" nil t
)
516 (help-xref-button 1 'help-function real-def
)))))
520 ;; We used to add .el to the file name,
521 ;; but that's completely wrong when the user used load-file.
522 (princ (if (eq file-name
'C-source
)
524 (file-name-nondirectory file-name
)))
526 ;; Make a hyperlink to the library.
527 (with-current-buffer standard-output
529 (re-search-backward "`\\([^`']+\\)'" nil t
)
530 (help-xref-button 1 'help-function-def function file-name
))))
532 (with-current-buffer (help-buffer)
533 (fill-region-as-paragraph (save-excursion (goto-char pt1
) (forward-line 0) (point))
537 (let* ((doc-raw (documentation function t
))
538 ;; If the function is autoloaded, and its docstring has
539 ;; key substitution constructs, load the library.
541 (and (autoloadp real-def
) doc-raw
542 help-enable-auto-load
543 (string-match "\\([^\\]=\\|[^=]\\|\\`\\)\\\\[[{<]"
545 (load (cadr real-def
) t
))
546 (substitute-command-keys doc-raw
))))
548 (help-fns--key-bindings function
)
549 (with-current-buffer standard-output
550 (setq doc
(help-fns--signature function doc real-def real-function
))
551 (run-hook-with-args 'help-fns-describe-function-functions function
)
553 (or doc
"Not documented.")))))))
555 ;; Add defaults to `help-fns-describe-function-functions'.
556 (add-hook 'help-fns-describe-function-functions
#'help-fns--obsolete
)
557 (add-hook 'help-fns-describe-function-functions
#'help-fns--parent-mode
)
558 (add-hook 'help-fns-describe-function-functions
#'help-fns--compiler-macro
)
564 (defun variable-at-point (&optional any-symbol
)
565 "Return the bound variable symbol found at or before point.
566 Return 0 if there is no such symbol.
567 If ANY-SYMBOL is non-nil, don't insist the symbol be bound."
568 (with-syntax-table emacs-lisp-mode-syntax-table
569 (or (condition-case ()
571 (skip-chars-forward "'")
572 (or (not (zerop (skip-syntax-backward "_w")))
573 (eq (char-syntax (following-char)) ?w
)
574 (eq (char-syntax (following-char)) ?_
)
576 (skip-chars-forward "'")
577 (let ((obj (read (current-buffer))))
578 (and (symbolp obj
) (boundp obj
) obj
)))
580 (let* ((str (find-tag-default))
581 (sym (if str
(intern-soft str
))))
582 (if (and sym
(or any-symbol
(boundp sym
)))
585 (when (and str
(string-match "\\`\\W*\\(.*?\\)\\W*\\'" str
))
586 (setq sym
(intern-soft (match-string 1 str
)))
587 (and (or any-symbol
(boundp sym
)) sym
)))))
590 (defun describe-variable-custom-version-info (variable)
591 (let ((custom-version (get variable
'custom-version
))
592 (cpv (get variable
'custom-package-version
))
596 (format "This variable was introduced, or its default value was changed, in\nversion %s of Emacs.\n"
599 (let* ((package (car-safe cpv
))
600 (version (if (listp (cdr-safe cpv
))
603 (pkg-versions (assq package customize-package-emacs-version-alist
))
604 (emacsv (cdr (assoc version pkg-versions
))))
605 (if (and package version
)
607 (format (concat "This variable was introduced, or its default value was changed, in\nversion %s of the %s package"
609 (format " that is part of Emacs %s" emacsv
))
611 version package
))))))
615 (defun describe-variable (variable &optional buffer frame
)
616 "Display the full documentation of VARIABLE (a symbol).
617 Returns the documentation as a string, also.
618 If VARIABLE has a buffer-local value in BUFFER or FRAME
619 \(default to the current buffer and current frame),
620 it is displayed along with the global value."
622 (let ((v (variable-at-point))
623 (enable-recursive-minibuffers t
)
625 (setq val
(completing-read (if (symbolp v
)
627 "Describe variable (default %s): " v
)
628 "Describe variable: ")
631 (or (get vv
'variable-documentation
)
632 (and (boundp vv
) (not (keywordp vv
)))))
634 (if (symbolp v
) (symbol-name v
))))
635 (list (if (equal val
"")
638 (unless (buffer-live-p buffer
) (setq buffer
(current-buffer)))
639 (unless (frame-live-p frame
) (setq frame
(selected-frame)))
640 (if (not (symbolp variable
))
641 (message "You did not specify a variable")
643 (let ((valvoid (not (with-current-buffer buffer
(boundp variable
))))
644 (permanent-local (get variable
'permanent-local
))
645 val val-start-pos locus
)
646 ;; Extract the value before setting up the output buffer,
647 ;; in case `buffer' *is* the output buffer.
649 (with-selected-frame frame
650 (with-current-buffer buffer
651 (setq val
(symbol-value variable
)
652 locus
(variable-binding-locus variable
)))))
653 (help-setup-xref (list #'describe-variable variable buffer
)
654 (called-interactively-p 'interactive
))
655 (with-help-window (help-buffer)
656 (with-current-buffer buffer
658 (setq file-name
(find-lisp-object-file-name variable
'defvar
))
662 (princ " is a variable defined in `")
663 (princ (if (eq file-name
'C-source
)
665 (file-name-nondirectory file-name
)))
667 (with-current-buffer standard-output
669 (re-search-backward "`\\([^`']+\\)'" nil t
)
670 (help-xref-button 1 'help-variable-def
671 variable file-name
)))
673 (princ "It is void as a variable.")
676 (princ " is void as a variable.")
679 (with-current-buffer standard-output
680 (setq val-start-pos
(point))
683 (line-beg (line-beginning-position))
685 (let ((print-quoted t
))
686 (prin1-to-string val
))))
687 (if (< (+ (length print-rep
) (point) (- line-beg
)) 68)
691 (if (< (point) (+ 68 (line-beginning-position 0)))
692 (delete-region from
(1+ from
))
693 (delete-region (1- from
) from
)))
694 (let* ((sv (get variable
'standard-value
))
695 (origval (and (consp sv
)
698 (error :help-eval-error
)))))
699 (when (and (consp sv
)
700 (not (equal origval val
))
701 (not (equal origval
:help-eval-error
)))
702 (princ "\nOriginal value was \n")
705 (if (< (point) (+ from
20))
706 (delete-region (1- from
) from
)))))))
711 (princ (format "Local in buffer %s; "
712 (buffer-name buffer
))))
714 (princ (format "It is a frame-local variable; ")))
715 ((terminal-live-p locus
)
716 (princ (format "It is a terminal-local variable; ")))
718 (princ (format "It is local to %S" locus
))))
719 (if (not (default-boundp variable
))
720 (princ "globally void")
721 (let ((global-val (default-value variable
)))
722 (with-current-buffer standard-output
723 (princ "global value is ")
724 (if (eq val global-val
)
727 ;; Fixme: pp can take an age if you happen to
728 ;; ask for a very large expression. We should
729 ;; probably print it raw once and check it's a
730 ;; sensible size before prettyprinting. -- fx
731 (let ((from (point)))
733 ;; See previous comment for this function.
734 ;; (help-xref-on-pp from (point))
735 (if (< (point) (+ from
20))
736 (delete-region (1- from
) from
)))))))
739 ;; If the value is large, move it to the end.
740 (with-current-buffer standard-output
741 (when (> (count-lines (point-min) (point-max)) 10)
742 ;; Note that setting the syntax table like below
743 ;; makes forward-sexp move over a `'s' at the end
745 (set-syntax-table emacs-lisp-mode-syntax-table
)
746 (goto-char val-start-pos
)
747 ;; The line below previously read as
748 ;; (delete-region (point) (progn (end-of-line) (point)))
749 ;; which suppressed display of the buffer local value for
751 (when (looking-at "value is") (replace-match ""))
753 (insert "\n\nValue:")
754 (set (make-local-variable 'help-button-cache
)
756 (insert "value is shown ")
757 (insert-button "below"
758 'action help-button-cache
760 'help-echo
"mouse-2, RET: show value")
764 (let* ((alias (condition-case nil
765 (indirect-variable variable
)
767 (obsolete (get variable
'byte-obsolete-variable
))
769 (safe-var (get variable
'safe-local-variable
))
770 (doc (or (documentation-property
771 variable
'variable-documentation
)
772 (documentation-property
773 alias
'variable-documentation
)))
776 ;; Mention if it's a local variable.
778 ((and (local-variable-if-set-p variable
)
779 (or (not (local-variable-p variable
))
781 (local-variable-if-set-p variable
))))
783 (princ " Automatically becomes ")
785 (princ "permanently "))
786 (princ "buffer-local when set.\n"))
787 ((not permanent-local
))
790 (princ " This variable's buffer-local value is permanent.\n"))
793 (princ " This variable's value is permanent \
794 if it is given a local binding.\n")))
796 ;; Mention if it's an alias.
797 (unless (eq alias variable
)
799 (princ (format " This variable is an alias for `%s'.\n" alias
)))
803 (princ " This variable is obsolete")
805 (princ (format " since %s" (nth 2 obsolete
))))
806 (princ (cond ((stringp use
) (concat ";\n " use
))
807 (use (format ";\n use `%s' instead." (car obsolete
)))
811 (when (member (cons variable val
)
812 (with-current-buffer buffer
813 file-local-variables-alist
))
815 (if (member (cons variable val
)
816 (with-current-buffer buffer
817 dir-local-variables-alist
))
818 (let ((file (and (buffer-file-name buffer
)
820 (buffer-file-name buffer
)))
821 (dir-locals-find-file
822 (buffer-file-name buffer
))))
824 (princ " This variable's value is directory-local")
828 (if (consp file
) ; result from cache
829 ;; If the cache element has an mtime, we
830 ;; assume it came from a file.
832 (setq file
(expand-file-name
833 dir-locals-file
(car file
)))
834 ;; Otherwise, assume it was set directly.
835 (setq file
(car file
)
839 "for the directory\n `"))
840 (with-current-buffer standard-output
842 file
'type
'help-dir-local-var-def
843 'help-args
(list variable file
)))
845 (princ " This variable's value is file-local.\n")))
847 (when (memq variable ignored-local-variables
)
849 (princ " This variable is ignored as a file-local \
852 ;; Can be both risky and safe, eg auto-fill-function.
853 (when (risky-local-variable-p variable
)
855 (princ " This variable may be risky if used as a \
856 file-local variable.\n")
857 (when (assq variable safe-local-variable-values
)
858 (princ " However, you have added it to \
859 `safe-local-variable-values'.\n")))
863 (princ " This variable is safe as a file local variable ")
864 (princ "if its value\n satisfies the predicate ")
865 (princ (if (byte-code-function-p safe-var
)
866 "which is a byte-compiled expression.\n"
867 (format "`%s'.\n" safe-var
))))
869 (if extra-line
(terpri))
870 (princ "Documentation:\n")
871 (with-current-buffer standard-output
872 (insert (or doc
"Not documented as a variable."))))
874 ;; Make a link to customize if this variable can be customized.
875 (when (custom-variable-p variable
)
876 (let ((customize-label "customize"))
879 (princ (concat "You can " customize-label
" this variable."))
880 (with-current-buffer standard-output
883 (concat "\\(" customize-label
"\\)") nil t
)
884 (help-xref-button 1 'help-customize-variable variable
))))
885 ;; Note variable's version or package version
886 (let ((output (describe-variable-custom-version-info variable
)))
892 (with-current-buffer standard-output
893 ;; Return the text we displayed.
894 (buffer-string))))))))
898 (defun describe-syntax (&optional buffer
)
899 "Describe the syntax specifications in the syntax table of BUFFER.
900 The descriptions are inserted in a help buffer, which is then displayed.
901 BUFFER defaults to the current buffer."
903 (setq buffer
(or buffer
(current-buffer)))
904 (help-setup-xref (list #'describe-syntax buffer
)
905 (called-interactively-p 'interactive
))
906 (with-help-window (help-buffer)
907 (let ((table (with-current-buffer buffer
(syntax-table))))
908 (with-current-buffer standard-output
909 (describe-vector table
'internal-describe-syntax-value
)
910 (while (setq table
(char-table-parent table
))
911 (insert "\nThe parent syntax table is:")
912 (describe-vector table
'internal-describe-syntax-value
))))))
914 (defun help-describe-category-set (value)
916 ((null value
) "default")
917 ((char-table-p value
) "deeper char-table ...")
918 (t (condition-case nil
919 (category-set-mnemonics value
)
920 (error "invalid"))))))
923 (defun describe-categories (&optional buffer
)
924 "Describe the category specifications in the current category table.
925 The descriptions are inserted in a buffer, which is then displayed.
926 If BUFFER is non-nil, then describe BUFFER's category table instead.
927 BUFFER should be a buffer or a buffer name."
929 (setq buffer
(or buffer
(current-buffer)))
930 (help-setup-xref (list #'describe-categories buffer
)
931 (called-interactively-p 'interactive
))
932 (with-help-window (help-buffer)
933 (let* ((table (with-current-buffer buffer
(category-table)))
934 (docs (char-table-extra-slot table
0)))
935 (if (or (not (vectorp docs
)) (/= (length docs
) 95))
936 (error "Invalid first extra slot in this category table\n"))
937 (with-current-buffer standard-output
938 (insert "Legend of category mnemonics (see the tail for the longer description)\n")
939 (let ((pos (point)) (items 0) lines n
)
941 (if (aref docs i
) (setq items
(1+ items
))))
942 (setq lines
(1+ (/ (1- items
) 4)))
945 (let ((elt (aref docs i
)))
947 (string-match ".*" elt
)
948 (setq elt
(match-string 0 elt
))
949 (if (>= (length elt
) 17)
950 (setq elt
(concat (substring elt
0 14) "...")))
951 (if (< (point) (point-max))
952 (move-to-column (* 20 (/ n lines
)) t
))
953 (insert (+ i ?\s
) ?
: elt
)
954 (if (< (point) (point-max))
958 (if (= (% n lines
) 0)
960 (goto-char (point-max))
962 "character(s)\tcategory mnemonics\n"
963 "------------\t------------------")
964 (describe-vector table
'help-describe-category-set
)
965 (insert "Legend of category mnemonics:\n")
967 (let ((elt (aref docs i
)))
969 (if (string-match "\n" elt
)
970 (setq elt
(substring elt
(match-end 0))))
971 (insert (+ i ?\s
) ": " elt
"\n"))))
972 (while (setq table
(char-table-parent table
))
973 (insert "\nThe parent category table is:")
974 (describe-vector table
'help-describe-category-set
))))))
977 ;;; Replacements for old lib-src/ programs. Don't seem especially useful.
979 ;; Replaces lib-src/digest-doc.c.
981 (defun doc-file-to-man (file)
982 "Produce an nroff buffer containing the doc-strings from the DOC file."
983 (interactive (list (read-file-name "Name of DOC file: " doc-directory
984 internal-doc-file-name t
)))
985 (or (file-readable-p file
)
986 (error "Cannot read file `%s'" file
))
987 (pop-to-buffer (generate-new-buffer "*man-doc*"))
988 (setq buffer-undo-list t
)
989 (insert ".TH \"Command Summary for GNU Emacs\"\n"
990 ".AU Richard M. Stallman\n")
991 (insert-file-contents file
)
993 (while (search-forward "\x1f" nil
'move
)
995 (delete-region (1- (point)) (line-end-position))
1001 (insert (if (looking-at "F") "Function " "Variable "))
1004 (insert ".DS L\n"))))
1006 (setq buffer-undo-list nil
)
1009 ;; Replaces lib-src/sorted-doc.c.
1011 (defun doc-file-to-info (file)
1012 "Produce a texinfo buffer with sorted doc-strings from the DOC file."
1013 (interactive (list (read-file-name "Name of DOC file: " doc-directory
1014 internal-doc-file-name t
)))
1015 (or (file-readable-p file
)
1016 (error "Cannot read file `%s'" file
))
1017 (let ((i 0) type name doc alist
)
1019 (insert-file-contents file
)
1020 ;; The characters "@{}" need special treatment.
1021 (while (re-search-forward "[@{}]" nil t
)
1025 (goto-char (point-min))
1026 (while (search-forward "\x1f" nil t
)
1027 (unless (looking-at "S")
1028 (setq type
(char-after)
1029 name
(buffer-substring (1+ (point)) (line-end-position))
1030 doc
(buffer-substring (line-beginning-position 2)
1031 (if (search-forward "\x1f" nil
'move
)
1034 alist
(cons (list name type doc
) alist
))
1035 (backward-char 1))))
1036 (pop-to-buffer (generate-new-buffer "*info-doc*"))
1037 (setq buffer-undo-list t
)
1038 ;; Write the output header.
1039 (insert "\\input texinfo @c -*-texinfo-*-\n"
1040 "@setfilename emacsdoc.info\n"
1041 "@settitle Command Summary for GNU Emacs\n"
1044 "@unnumbered Command Summary for GNU Emacs\n\n"
1047 "@global@let@ITEM@item\n"
1048 "@def@item{@filbreak@vskip5pt@ITEM}\n"
1049 "@font@tensy cmsy10 scaled @magstephalf\n"
1050 "@font@teni cmmi10 scaled @magstephalf\n"
1051 "@def\\{{@tensy@char110}}\n" ; this backslash goes with cmr10
1052 "@def|{{@tensy@char106}}\n"
1053 "@def@{{{@tensy@char102}}\n"
1054 "@def@}{{@tensy@char103}}\n"
1055 "@def<{{@teni@char62}}\n"
1056 "@def>{{@teni@char60}}\n"
1059 "@tableindent-0.2in\n"
1061 ;; Sort the array by name; within each name, by type (functions first).
1062 (setq alist
(sort alist
(lambda (e1 e2
)
1063 (if (string-equal (car e1
) (car e2
))
1064 (<= (cadr e1
) (cadr e2
))
1065 (string-lessp (car e1
) (car e2
))))))
1066 ;; Print each function.
1069 (if (char-equal (cadr e
) ?\F
) "Function" "Variable")
1070 " @code{" (car e
) "}\n@display\n"
1073 ;; Try to avoid a save size overflow in the TeX output routine.
1074 (if (zerop (setq i
(%
(1+ i
) 100)))
1075 (insert "\n@end table\n@table @asis\n")))
1076 (insert "@end table\n"
1078 (setq buffer-undo-list nil
)
1083 ;;; help-fns.el ends here