1 ;;; help-fns.el --- Complex help functions
3 ;; Copyright (C) 1985-1986, 1993-1994, 1998-2011
4 ;; Free Software Foundation, Inc.
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
38 (defun describe-function (function)
39 "Display the full documentation of FUNCTION (a symbol)."
41 (let ((fn (function-called-at-point))
42 (enable-recursive-minibuffers t
)
44 (setq val
(completing-read (if fn
45 (format "Describe function (default %s): " fn
)
46 "Describe function: ")
47 obarray
'fboundp t nil nil
48 (and fn
(symbol-name fn
))))
49 (list (if (equal val
"")
52 (message "You didn't specify a function")
53 (help-setup-xref (list #'describe-function function
)
54 (called-interactively-p 'interactive
))
56 (with-help-window (help-buffer)
58 ;; Use " is " instead of a colon so that
59 ;; it is easier to get out the function name using forward-sexp.
61 (describe-function-1 function
)
62 (with-current-buffer standard-output
63 ;; Return the text we displayed.
66 (defun help-split-fundoc (docstring def
)
67 "Split a function DOCSTRING into the actual doc and the usage info.
68 Return (USAGE . DOC) or nil if there's no usage info.
69 DEF is the function whose usage we're looking for in DOCSTRING."
70 ;; Functions can get the calling sequence at the end of the doc string.
71 ;; In cases where `function' has been fset to a subr we can't search for
72 ;; function's name in the doc string so we use `fn' as the anonymous
73 ;; function name instead.
74 (when (and docstring
(string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" docstring
))
76 ;; Replace `fn' with the actual function name.
77 (if (consp def
) "anonymous" def
)
78 (match-string 1 docstring
))
79 (substring docstring
0 (match-beginning 0)))))
81 (defun help-add-fundoc-usage (docstring arglist
)
82 "Add the usage info to DOCSTRING.
83 If DOCSTRING already has a usage info, then just return it unchanged.
84 The usage info is built from ARGLIST. DOCSTRING can be nil.
85 ARGLIST can also be t or a string of the form \"(FUN ARG1 ARG2 ...)\"."
86 (unless (stringp docstring
) (setq docstring
"Not documented"))
87 (if (or (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" docstring
) (eq arglist t
))
90 (if (string-match "\n?\n\\'" docstring
)
91 (if (< (- (match-end 0) (match-beginning 0)) 2) "\n" "")
93 (if (and (stringp arglist
)
94 (string-match "\\`([^ ]+\\(.*\\))\\'" arglist
))
95 (concat "(fn" (match-string 1 arglist
) ")")
96 (format "%S" (help-make-usage 'fn arglist
))))))
98 (defun help-function-arglist (def)
99 ;; Handle symbols aliased to other symbols.
100 (if (and (symbolp def
) (fboundp def
)) (setq def
(indirect-function def
)))
101 ;; If definition is a macro, find the function inside it.
102 (if (eq (car-safe def
) 'macro
) (setq def
(cdr def
)))
103 ;; and do the same for interpreted closures
104 (if (eq (car-safe def
) 'closure
) (setq def
(cddr def
)))
106 ((byte-code-function-p def
) (aref def
0))
107 ((eq (car-safe def
) 'lambda
) (nth 1 def
))
108 ((and (eq (car-safe def
) 'autoload
) (not (eq (nth 4 def
) 'keymap
)))
109 "[Arg list not available until function definition is loaded.]")
112 (defun help-make-usage (function arglist
)
113 (cons (if (symbolp function
) function
'anonymous
)
114 (mapcar (lambda (arg)
115 (if (not (symbolp arg
))
116 (if (and (consp arg
) (symbolp (car arg
)))
117 ;; CL style default values for optional args.
118 (cons (intern (upcase (symbol-name (car arg
))))
121 (let ((name (symbol-name arg
)))
123 ((string-match "\\`&" name
) arg
)
124 ((string-match "\\`_" name
)
125 (intern (upcase (substring name
1))))
126 (t (intern (upcase name
)))))))
129 ;; Could be this, if we make symbol-file do the work below.
130 ;; (defun help-C-file-name (subr-or-var kind)
131 ;; "Return the name of the C file where SUBR-OR-VAR is defined.
132 ;; KIND should be `var' for a variable or `subr' for a subroutine."
133 ;; (symbol-file (if (symbolp subr-or-var) subr-or-var
134 ;; (subr-name subr-or-var))
135 ;; (if (eq kind 'var) 'defvar 'defun)))
137 (defun help-C-file-name (subr-or-var kind
)
138 "Return the name of the C file where SUBR-OR-VAR is defined.
139 KIND should be `var' for a variable or `subr' for a subroutine."
140 (let ((docbuf (get-buffer-create " *DOC*"))
141 (name (if (eq 'var kind
)
142 (concat "V" (symbol-name subr-or-var
))
143 (concat "F" (subr-name subr-or-var
)))))
144 (with-current-buffer docbuf
145 (goto-char (point-min))
147 (insert-file-contents-literally
148 (expand-file-name internal-doc-file-name doc-directory
)))
149 (let ((file (catch 'loop
151 (let ((pnt (search-forward (concat "\x1f" name
"\n"))))
152 (re-search-backward "\x1fS\\(.*\\)")
153 (let ((file (match-string 1)))
154 (if (member file build-files
)
156 (goto-char pnt
))))))))
157 (if (string-match "^ns.*\\(\\.o\\|obj\\)\\'" file
)
158 (setq file
(replace-match ".m" t t file
1))
159 (if (string-match "\\.\\(o\\|obj\\)\\'" file
)
160 (setq file
(replace-match ".c" t t file
))))
161 (if (string-match "\\.\\(c\\|m\\)\\'" file
)
165 (defcustom help-downcase-arguments nil
166 "If non-nil, argument names in *Help* buffers are downcased."
171 (defun help-highlight-arg (arg)
172 "Highlight ARG as an argument name for a *Help* buffer.
173 Return ARG in face `help-argument-name'; ARG is also downcased
174 if the variable `help-downcase-arguments' is non-nil."
175 (propertize (if help-downcase-arguments
(downcase arg
) arg
)
176 'face
'help-argument-name
))
178 (defun help-do-arg-highlight (doc args
)
179 (with-syntax-table (make-syntax-table emacs-lisp-mode-syntax-table
)
180 (modify-syntax-entry ?\-
"w")
181 (dolist (arg args doc
)
182 (setq doc
(replace-regexp-in-string
183 ;; This is heuristic, but covers all common cases
185 (concat "\\<" ; beginning of word
186 "\\(?:[a-z-]*-\\)?" ; for xxx-ARG
190 "\\(?:es\\|s\\|th\\)?" ; for ARGth, ARGs
191 "\\(?:-[a-z0-9-]+\\)?" ; for ARG-xxx, ARG-n
192 "\\(?:-[{([<`\"].*?\\)?"; for ARG-{x}, (x), <x>, [x], `x'
194 (help-highlight-arg arg
)
197 (defun help-highlight-arguments (usage doc
&rest args
)
198 (when (and usage
(string-match "^(" usage
))
201 (goto-char (point-min))
202 (let ((case-fold-search nil
)
203 (next (not (or args
(looking-at "\\["))))
205 ;; Make a list of all arguments
206 (skip-chars-forward "^ ")
208 (or opt
(not (looking-at " &")) (setq opt t
))
209 (if (not (re-search-forward " \\([\\[(]*\\)\\([^] &)\.]+\\)" nil t
))
211 (setq args
(cons (match-string 2) args
))
212 (when (and opt
(string= (match-string 1) "("))
213 ;; A pesky CL-style optional argument with default value,
214 ;; so let's skip over it
215 (search-backward "(")
216 (goto-char (scan-sexps (point) 1)))))
217 ;; Highlight aguments in the USAGE string
218 (setq usage
(help-do-arg-highlight (buffer-string) args
))
219 ;; Highlight arguments in the DOC string
220 (setq doc
(and doc
(help-do-arg-highlight doc args
))))))
221 ;; Return value is like the one from help-split-fundoc, but highlighted
224 ;; The following function was compiled from the former functions
225 ;; `describe-simplify-lib-file-name' and `find-source-lisp-file' with
226 ;; some excerpts from `describe-function-1' and `describe-variable'.
227 ;; The only additional twists provided are (1) locate the defining file
228 ;; for autoloaded functions, and (2) give preference to files in the
229 ;; "install directory" (directories found via `load-path') rather than
230 ;; to files in the "compile directory" (directories found by searching
231 ;; the loaddefs.el file). We autoload it because it's also used by
232 ;; `describe-face' (instead of `describe-simplify-lib-file-name').
235 (defun find-lisp-object-file-name (object type
)
236 "Guess the file that defined the Lisp object OBJECT, of type TYPE.
237 OBJECT should be a symbol associated with a function, variable, or face;
238 alternatively, it can be a function definition.
239 If TYPE is `defvar', search for a variable definition.
240 If TYPE is `defface', search for a face definition.
241 If TYPE is the value returned by `symbol-function' for a function symbol,
242 search for a function definition.
244 The return value is the absolute name of a readable file where OBJECT is
245 defined. If several such files exist, preference is given to a file
246 found via `load-path'. The return value can also be `C-source', which
247 means that OBJECT is a function or variable defined in C. If no
248 suitable file is found, return nil."
249 (let* ((autoloaded (eq (car-safe type
) 'autoload
))
250 (file-name (or (and autoloaded
(nth 1 type
))
252 object
(if (memq type
(list 'defvar
'defface
))
257 ;; An autoloaded function: Locate the file since `symbol-function'
258 ;; has only returned a bare string here.
260 (locate-file file-name load-path
'(".el" ".elc") 'readable
)))
261 ((and (stringp file-name
)
262 (string-match "[.]*loaddefs.el\\'" file-name
))
263 ;; An autoloaded variable or face. Visit loaddefs.el in a buffer
264 ;; and try to extract the defining file. The following form is
265 ;; from `describe-function-1' and `describe-variable'.
268 (find-function-search-for-symbol object nil file-name
)
271 (with-current-buffer (car location
)
272 (goto-char (cdr location
))
273 (when (re-search-backward
274 "^;;; Generated autoloads from \\(.*\\)" nil t
)
277 (file-name-sans-extension
278 (match-string-no-properties 1))
279 load-path
'(".el" ".elc") 'readable
))))))))
282 ((and (not file-name
) (subrp type
))
283 ;; A built-in function. The form is from `describe-function-1'.
284 (if (get-buffer " *DOC*")
285 (help-C-file-name type
'subr
)
287 ((and (not file-name
) (symbolp object
)
288 (integerp (get object
'variable-documentation
)))
289 ;; A variable defined in C. The form is from `describe-variable'.
290 (if (get-buffer " *DOC*")
291 (help-C-file-name object
'var
)
293 ((not (stringp file-name
))
294 ;; If we don't have a file-name string by now, we lost.
296 ;; Now, `file-name' should have become an absolute file name.
297 ;; For files loaded from ~/.emacs.elc, try ~/.emacs.
299 (and (string-equal file-name
300 (expand-file-name ".emacs.elc" "~"))
301 (file-readable-p (setq fn
(expand-file-name ".emacs" "~")))
303 ;; When the Elisp source file can be found in the install
304 ;; directory, return the name of that file.
306 (if (string-match "[.]elc\\'" file-name
)
307 (substring-no-properties file-name
0 -
1)
309 (or (and (file-readable-p lib-name
) lib-name
)
310 ;; The library might be compressed.
311 (and (file-readable-p (concat lib-name
".gz")) lib-name
))))
312 ((let* ((lib-name (file-name-nondirectory file-name
))
313 ;; The next form is from `describe-simplify-lib-file-name'.
315 ;; Try converting the absolute file name to a library
316 ;; name, convert that back to a file name and see if we
317 ;; get the original one. If so, they are equivalent.
318 (if (equal file-name
(locate-file lib-name load-path
'("")))
319 (if (string-match "[.]elc\\'" lib-name
)
320 (substring-no-properties lib-name
0 -
1)
323 ;; The next three forms are from `find-source-lisp-file'.
324 (elc-file (locate-file
326 (if (string-match "\\.el\\'" file-name
)
329 load-path nil
'readable
))
332 (insert-file-contents-literally elc-file nil
0 256)
335 (string-match ";;; from file \\(.*\\.el\\)" str
)
336 (match-string 1 str
))))
337 (and src-file
(file-readable-p src-file
) src-file
))))))
339 (declare-function ad-get-advice-info
"advice" (function))
342 (defun describe-function-1 (function)
343 (let* ((advised (and (symbolp function
) (featurep 'advice
)
344 (ad-get-advice-info function
)))
345 ;; If the function is advised, use the symbol that has the
346 ;; real definition, if that symbol is already set up.
349 (let ((origname (cdr (assq 'origname advised
))))
350 (and (fboundp origname
) origname
)))
352 ;; Get the real definition.
353 (def (if (symbolp real-function
)
354 (symbol-function real-function
)
357 (beg (if (commandp def
) "an interactive " "a "))
358 (pt1 (with-current-buffer (help-buffer) (point)))
361 (cond ((or (stringp def
) (vectorp def
))
364 (if (eq 'unevalled
(cdr (subr-arity def
)))
365 (concat beg
"special form")
366 (concat beg
"built-in function")))
367 ((byte-code-function-p def
)
368 (concat beg
"compiled Lisp function"))
370 (while (and (fboundp def
)
371 (symbolp (symbol-function def
)))
372 (setq def
(symbol-function def
)))
373 ;; Handle (defalias 'foo 'bar), where bar is undefined.
374 (or (fboundp def
) (setq errtype
'alias
))
375 (format "an alias for `%s'" def
))
376 ((eq (car-safe def
) 'lambda
)
377 (concat beg
"Lisp function"))
378 ((eq (car-safe def
) 'macro
)
380 ((eq (car-safe def
) 'closure
)
381 (concat beg
"Lisp closure"))
382 ((eq (car-safe def
) 'autoload
)
383 (format "%s autoloaded %s"
384 (if (commandp def
) "an interactive" "an")
385 (if (eq (nth 4 def
) 'keymap
) "keymap"
386 (if (nth 4 def
) "Lisp macro" "Lisp function"))))
389 (elts (cdr-safe def
)))
391 (if (char-table-p (car-safe elts
))
394 (setq elts
(cdr-safe elts
)))
400 (if (eq errtype
'alias
)
401 (princ ",\nwhich is not defined. Please make a bug report.")
402 (with-current-buffer standard-output
405 (when (re-search-backward "alias for `\\([^`']+\\)'" nil t
)
406 (help-xref-button 1 'help-function def
)))))
408 (setq file-name
(find-lisp-object-file-name function def
))
411 ;; We used to add .el to the file name,
412 ;; but that's completely wrong when the user used load-file.
413 (princ (if (eq file-name
'C-source
)
415 (file-name-nondirectory file-name
)))
417 ;; Make a hyperlink to the library.
418 (with-current-buffer standard-output
420 (re-search-backward "`\\([^`']+\\)'" nil t
)
421 (help-xref-button 1 'help-function-def function file-name
))))
423 (with-current-buffer (help-buffer)
424 (fill-region-as-paragraph (save-excursion (goto-char pt1
) (forward-line 0) (point))
427 (when (commandp function
)
428 (let ((pt2 (with-current-buffer (help-buffer) (point)))
429 (remapped (command-remapping function
)))
430 (unless (memq remapped
'(ignore undefined
))
431 (let ((keys (where-is-internal
432 (or remapped function
) overriding-local-map nil nil
))
434 (if (and (eq function
'self-insert-command
)
435 (vectorp (car-safe keys
))
436 (consp (aref (car keys
) 0)))
437 (princ "It is bound to many ordinary text characters.\n")
438 ;; Which non-control non-meta keys run this command?
440 (if (member (event-modifiers (aref key
0)) '(nil (shift)))
441 (push key non-modified-keys
)))
443 (princ "It is remapped to `")
444 (princ (symbol-name remapped
))
448 (princ (if remapped
", which is bound to " "It is bound to "))
449 ;; If lots of ordinary text characters run this command,
450 ;; don't mention them one by one.
451 (if (< (length non-modified-keys
) 10)
452 (princ (mapconcat 'key-description keys
", "))
453 (dolist (key non-modified-keys
)
454 (setq keys
(delq key keys
)))
457 (princ (mapconcat 'key-description keys
", "))
458 (princ ", and many ordinary text characters"))
459 (princ "many ordinary text characters"))))
460 (when (or remapped keys non-modified-keys
)
464 (with-current-buffer (help-buffer)
465 (fill-region-as-paragraph pt2
(point))
466 (unless (looking-back "\n\n")
468 ;; Note that list* etc do not get this property until
469 ;; cl-hack-byte-compiler runs, after bytecomp is loaded.
470 (when (and (symbolp function
)
471 (eq (get function
'byte-compile
)
472 'cl-byte-compile-compiler-macro
))
473 (princ "This function has a compiler macro")
474 (let ((lib (get function
'compiler-macro-file
)))
476 (princ (format " in `%s'" lib
))
477 (with-current-buffer standard-output
479 (re-search-backward "`\\([^`']+\\)'" nil t
)
480 (help-xref-button 1 'help-function-cmacro function lib
)))))
482 (let* ((advertised (gethash def advertised-signature-table t
))
483 (arglist (if (listp advertised
)
484 advertised
(help-function-arglist def
)))
485 (doc (documentation function
))
486 (usage (help-split-fundoc doc function
)))
487 (with-current-buffer standard-output
488 ;; If definition is a keymap, skip arglist note.
489 (unless (keymapp function
)
490 (if usage
(setq doc
(cdr usage
)))
492 ((and usage
(not (listp advertised
))) (car usage
))
494 (format "%S" (help-make-usage function arglist
)))
495 ((stringp arglist
) arglist
)
496 ;; Maybe the arglist is in the docstring of a symbol
497 ;; this one is aliased to.
498 ((let ((fun real-function
))
499 (while (and (symbolp fun
)
500 (setq fun
(symbol-function fun
))
501 (not (setq usage
(help-split-fundoc
508 (format "\nMacro: %s" (format-kbd-macro def
)))
509 (t "[Missing arglist. Please make a bug report.]")))
510 (high (help-highlight-arguments use doc
)))
511 (let ((fill-begin (point)))
512 (insert (car high
) "\n")
513 (fill-region fill-begin
(point)))
514 (setq doc
(cdr high
))))
515 (let* ((obsolete (and
516 ;; function might be a lambda construct.
518 (get function
'byte-obsolete-info
)))
519 (use (car obsolete
)))
521 (princ "\nThis function is obsolete")
522 (when (nth 2 obsolete
)
523 (insert (format " since %s" (nth 2 obsolete
))))
524 (insert (cond ((stringp use
) (concat ";\n" use
))
525 (use (format ";\nuse `%s' instead." use
))
529 (or doc
"Not documented."))))))))
535 (defun variable-at-point (&optional any-symbol
)
536 "Return the bound variable symbol found at or before point.
537 Return 0 if there is no such symbol.
538 If ANY-SYMBOL is non-nil, don't insist the symbol be bound."
539 (with-syntax-table emacs-lisp-mode-syntax-table
540 (or (condition-case ()
542 (or (not (zerop (skip-syntax-backward "_w")))
543 (eq (char-syntax (following-char)) ?w
)
544 (eq (char-syntax (following-char)) ?_
)
546 (skip-chars-forward "'")
547 (let ((obj (read (current-buffer))))
548 (and (symbolp obj
) (boundp obj
) obj
)))
550 (let* ((str (find-tag-default))
551 (sym (if str
(intern-soft str
))))
552 (if (and sym
(or any-symbol
(boundp sym
)))
555 (when (and str
(string-match "\\`\\W*\\(.*?\\)\\W*\\'" str
))
556 (setq sym
(intern-soft (match-string 1 str
)))
557 (and (or any-symbol
(boundp sym
)) sym
)))))
560 (defun describe-variable-custom-version-info (variable)
561 (let ((custom-version (get variable
'custom-version
))
562 (cpv (get variable
'custom-package-version
))
566 (format "This variable was introduced, or its default value was changed, in\nversion %s of Emacs.\n"
569 (let* ((package (car-safe cpv
))
570 (version (if (listp (cdr-safe cpv
))
573 (pkg-versions (assq package customize-package-emacs-version-alist
))
574 (emacsv (cdr (assoc version pkg-versions
))))
575 (if (and package version
)
577 (format (concat "This variable was introduced, or its default value was changed, in\nversion %s of the %s package"
579 (format " that is part of Emacs %s" emacsv
))
581 version package
))))))
585 (defun describe-variable (variable &optional buffer frame
)
586 "Display the full documentation of VARIABLE (a symbol).
587 Returns the documentation as a string, also.
588 If VARIABLE has a buffer-local value in BUFFER or FRAME
589 \(default to the current buffer and current frame),
590 it is displayed along with the global value."
592 (let ((v (variable-at-point))
593 (enable-recursive-minibuffers t
)
595 (setq val
(completing-read (if (symbolp v
)
597 "Describe variable (default %s): " v
)
598 "Describe variable: ")
602 (get vv
'variable-documentation
)))
604 (if (symbolp v
) (symbol-name v
))))
605 (list (if (equal val
"")
608 (unless (buffer-live-p buffer
) (setq buffer
(current-buffer)))
609 (unless (frame-live-p frame
) (setq frame
(selected-frame)))
610 (if (not (symbolp variable
))
611 (message "You did not specify a variable")
613 (let ((valvoid (not (with-current-buffer buffer
(boundp variable
))))
614 val val-start-pos locus
)
615 ;; Extract the value before setting up the output buffer,
616 ;; in case `buffer' *is* the output buffer.
618 (with-selected-frame frame
619 (with-current-buffer buffer
620 (setq val
(symbol-value variable
)
621 locus
(variable-binding-locus variable
)))))
622 (help-setup-xref (list #'describe-variable variable buffer
)
623 (called-interactively-p 'interactive
))
624 (with-help-window (help-buffer)
625 (with-current-buffer buffer
627 (setq file-name
(find-lisp-object-file-name variable
'defvar
))
631 (princ " is a variable defined in `")
632 (princ (if (eq file-name
'C-source
)
634 (file-name-nondirectory file-name
)))
636 (with-current-buffer standard-output
638 (re-search-backward "`\\([^`']+\\)'" nil t
)
639 (help-xref-button 1 'help-variable-def
640 variable file-name
)))
642 (princ "It is void as a variable.")
645 (princ " is void as a variable.")
648 (with-current-buffer standard-output
649 (setq val-start-pos
(point))
651 (let ((from (point)))
654 (if (< (point) (+ 68 (line-beginning-position 0)))
655 (delete-region from
(1+ from
))
656 (delete-region (1- from
) from
))
657 (let* ((sv (get variable
'standard-value
))
658 (origval (and (consp sv
)
661 (error :help-eval-error
)))))
662 (when (and (consp sv
)
663 (not (equal origval val
))
664 (not (equal origval
:help-eval-error
)))
665 (princ "\nOriginal value was \n")
668 (if (< (point) (+ from
20))
669 (delete-region (1- from
) from
)))))))
673 (princ (format "%socal in buffer %s; "
674 (if (get variable
'permanent-local
)
677 (princ (format "It is a frame-local variable; ")))
678 (if (not (default-boundp variable
))
679 (princ "globally void")
680 (let ((val (default-value variable
)))
681 (with-current-buffer standard-output
682 (princ "global value is ")
684 ;; Fixme: pp can take an age if you happen to
685 ;; ask for a very large expression. We should
686 ;; probably print it raw once and check it's a
687 ;; sensible size before prettyprinting. -- fx
688 (let ((from (point)))
690 ;; See previous comment for this function.
691 ;; (help-xref-on-pp from (point))
692 (if (< (point) (+ from
20))
693 (delete-region (1- from
) from
))))))
696 ;; If the value is large, move it to the end.
697 (with-current-buffer standard-output
698 (when (> (count-lines (point-min) (point-max)) 10)
699 ;; Note that setting the syntax table like below
700 ;; makes forward-sexp move over a `'s' at the end
702 (set-syntax-table emacs-lisp-mode-syntax-table
)
703 (goto-char val-start-pos
)
704 ;; The line below previously read as
705 ;; (delete-region (point) (progn (end-of-line) (point)))
706 ;; which suppressed display of the buffer local value for
708 (when (looking-at "value is") (replace-match ""))
710 (insert "\n\nValue:")
711 (set (make-local-variable 'help-button-cache
)
713 (insert "value is shown ")
714 (insert-button "below"
715 'action help-button-cache
717 'help-echo
"mouse-2, RET: show value")
721 (let* ((alias (condition-case nil
722 (indirect-variable variable
)
724 (obsolete (get variable
'byte-obsolete-variable
))
726 (safe-var (get variable
'safe-local-variable
))
727 (doc (or (documentation-property variable
'variable-documentation
)
728 (documentation-property alias
'variable-documentation
)))
730 ;; Add a note for variables that have been make-var-buffer-local.
731 (when (and (local-variable-if-set-p variable
)
732 (or (not (local-variable-p variable
))
734 (local-variable-if-set-p variable
))))
736 (princ " Automatically becomes buffer-local when set in any fashion.\n"))
738 ;; Mention if it's an alias
739 (unless (eq alias variable
)
741 (princ (format " This variable is an alias for `%s'.\n" alias
)))
745 (princ " This variable is obsolete")
746 (if (cdr obsolete
) (princ (format " since %s" (cdr obsolete
))))
747 (princ (cond ((stringp use
) (concat ";\n " use
))
748 (use (format ";\n use `%s' instead." (car obsolete
)))
752 (when (member (cons variable val
) file-local-variables-alist
)
754 (if (member (cons variable val
) dir-local-variables-alist
)
755 (let ((file (and (buffer-file-name)
756 (not (file-remote-p (buffer-file-name)))
757 (dir-locals-find-file (buffer-file-name)))))
758 (princ " This variable is a directory local variable")
760 (princ (concat "\n from the file \""
766 (princ " This variable is a file local variable.\n")))
768 (when (memq variable ignored-local-variables
)
770 (princ " This variable is ignored when used as a file local \
773 ;; Can be both risky and safe, eg auto-fill-function.
774 (when (risky-local-variable-p variable
)
776 (princ " This variable is potentially risky when used as a \
777 file local variable.\n")
778 (when (assq variable safe-local-variable-values
)
779 (princ " However, you have added it to \
780 `safe-local-variable-values'.\n")))
784 (princ " This variable is safe as a file local variable ")
785 (princ "if its value\n satisfies the predicate ")
786 (princ (if (byte-code-function-p safe-var
)
787 "which is byte-compiled expression.\n"
788 (format "`%s'.\n" safe-var
))))
790 (if extra-line
(terpri))
791 (princ "Documentation:\n")
792 (with-current-buffer standard-output
793 (insert (or doc
"Not documented as a variable."))))
795 ;; Make a link to customize if this variable can be customized.
796 (when (custom-variable-p variable
)
797 (let ((customize-label "customize"))
800 (princ (concat "You can " customize-label
" this variable."))
801 (with-current-buffer standard-output
804 (concat "\\(" customize-label
"\\)") nil t
)
805 (help-xref-button 1 'help-customize-variable variable
))))
806 ;; Note variable's version or package version
807 (let ((output (describe-variable-custom-version-info variable
)))
813 (with-current-buffer standard-output
814 ;; Return the text we displayed.
815 (buffer-string))))))))
819 (defun describe-syntax (&optional buffer
)
820 "Describe the syntax specifications in the syntax table of BUFFER.
821 The descriptions are inserted in a help buffer, which is then displayed.
822 BUFFER defaults to the current buffer."
824 (setq buffer
(or buffer
(current-buffer)))
825 (help-setup-xref (list #'describe-syntax buffer
)
826 (called-interactively-p 'interactive
))
827 (with-help-window (help-buffer)
828 (let ((table (with-current-buffer buffer
(syntax-table))))
829 (with-current-buffer standard-output
830 (describe-vector table
'internal-describe-syntax-value
)
831 (while (setq table
(char-table-parent table
))
832 (insert "\nThe parent syntax table is:")
833 (describe-vector table
'internal-describe-syntax-value
))))))
835 (defun help-describe-category-set (value)
837 ((null value
) "default")
838 ((char-table-p value
) "deeper char-table ...")
839 (t (condition-case err
840 (category-set-mnemonics value
)
841 (error "invalid"))))))
844 (defun describe-categories (&optional buffer
)
845 "Describe the category specifications in the current category table.
846 The descriptions are inserted in a buffer, which is then displayed.
847 If BUFFER is non-nil, then describe BUFFER's category table instead.
848 BUFFER should be a buffer or a buffer name."
850 (setq buffer
(or buffer
(current-buffer)))
851 (help-setup-xref (list #'describe-categories buffer
)
852 (called-interactively-p 'interactive
))
853 (with-help-window (help-buffer)
854 (let* ((table (with-current-buffer buffer
(category-table)))
855 (docs (char-table-extra-slot table
0)))
856 (if (or (not (vectorp docs
)) (/= (length docs
) 95))
857 (error "Invalid first extra slot in this category table\n"))
858 (with-current-buffer standard-output
859 (insert "Legend of category mnemonics (see the tail for the longer description)\n")
860 (let ((pos (point)) (items 0) lines n
)
862 (if (aref docs i
) (setq items
(1+ items
))))
863 (setq lines
(1+ (/ (1- items
) 4)))
866 (let ((elt (aref docs i
)))
868 (string-match ".*" elt
)
869 (setq elt
(match-string 0 elt
))
870 (if (>= (length elt
) 17)
871 (setq elt
(concat (substring elt
0 14) "...")))
872 (if (< (point) (point-max))
873 (move-to-column (* 20 (/ n lines
)) t
))
874 (insert (+ i ?\s
) ?
: elt
)
875 (if (< (point) (point-max))
879 (if (= (% n lines
) 0)
881 (goto-char (point-max))
883 "character(s)\tcategory mnemonics\n"
884 "------------\t------------------")
885 (describe-vector table
'help-describe-category-set
)
886 (insert "Legend of category mnemonics:\n")
888 (let ((elt (aref docs i
)))
890 (if (string-match "\n" elt
)
891 (setq elt
(substring elt
(match-end 0))))
892 (insert (+ i ?\s
) ": " elt
"\n"))))
893 (while (setq table
(char-table-parent table
))
894 (insert "\nThe parent category table is:")
895 (describe-vector table
'help-describe-category-set
))))))
898 ;;; Replacements for old lib-src/ programs. Don't seem especially useful.
900 ;; Replaces lib-src/digest-doc.c.
902 (defun doc-file-to-man (file)
903 "Produce an nroff buffer containing the doc-strings from the DOC file."
904 (interactive (list (read-file-name "Name of DOC file: " doc-directory
905 internal-doc-file-name t
)))
906 (or (file-readable-p file
)
907 (error "Cannot read file `%s'" file
))
908 (pop-to-buffer (generate-new-buffer "*man-doc*"))
909 (setq buffer-undo-list t
)
910 (insert ".TH \"Command Summary for GNU Emacs\"\n"
911 ".AU Richard M. Stallman\n")
912 (insert-file-contents file
)
914 (while (search-forward "\x1f" nil
'move
)
916 (delete-region (1- (point)) (line-end-position))
922 (insert (if (looking-at "F") "Function " "Variable "))
925 (insert ".DS L\n"))))
927 (setq buffer-undo-list nil
)
930 ;; Replaces lib-src/sorted-doc.c.
932 (defun doc-file-to-info (file)
933 "Produce a texinfo buffer with sorted doc-strings from the DOC file."
934 (interactive (list (read-file-name "Name of DOC file: " doc-directory
935 internal-doc-file-name t
)))
936 (or (file-readable-p file
)
937 (error "Cannot read file `%s'" file
))
938 (let ((i 0) type name doc alist
)
940 (insert-file-contents file
)
941 ;; The characters "@{}" need special treatment.
942 (while (re-search-forward "[@{}]" nil t
)
946 (goto-char (point-min))
947 (while (search-forward "\x1f" nil t
)
948 (unless (looking-at "S")
949 (setq type
(char-after)
950 name
(buffer-substring (1+ (point)) (line-end-position))
951 doc
(buffer-substring (line-beginning-position 2)
952 (if (search-forward "\x1f" nil
'move
)
955 alist
(cons (list name type doc
) alist
))
957 (pop-to-buffer (generate-new-buffer "*info-doc*"))
958 (setq buffer-undo-list t
)
959 ;; Write the output header.
960 (insert "\\input texinfo @c -*-texinfo-*-\n"
961 "@setfilename emacsdoc.info\n"
962 "@settitle Command Summary for GNU Emacs\n"
965 "@unnumbered Command Summary for GNU Emacs\n\n"
968 "@global@let@ITEM@item\n"
969 "@def@item{@filbreak@vskip5pt@ITEM}\n"
970 "@font@tensy cmsy10 scaled @magstephalf\n"
971 "@font@teni cmmi10 scaled @magstephalf\n"
972 "@def\\{{@tensy@char110}}\n" ; this backslash goes with cmr10
973 "@def|{{@tensy@char106}}\n"
974 "@def@{{{@tensy@char102}}\n"
975 "@def@}{{@tensy@char103}}\n"
976 "@def<{{@teni@char62}}\n"
977 "@def>{{@teni@char60}}\n"
980 "@tableindent-0.2in\n"
982 ;; Sort the array by name; within each name, by type (functions first).
983 (setq alist
(sort alist
(lambda (e1 e2
)
984 (if (string-equal (car e1
) (car e2
))
985 (<= (cadr e1
) (cadr e2
))
986 (string-lessp (car e1
) (car e2
))))))
987 ;; Print each function.
990 (if (char-equal (cadr e
) ?\F
) "Function" "Variable")
991 " @code{" (car e
) "}\n@display\n"
994 ;; Try to avoid a save size overflow in the TeX output routine.
995 (if (zerop (setq i
(%
(1+ i
) 100)))
996 (insert "\n@end table\n@table @asis\n")))
997 (insert "@end table\n"
999 (setq buffer-undo-list nil
)
1004 ;;; help-fns.el ends here