diff options
| author | Stefan Monnier | 2015-07-06 13:25:26 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2015-07-06 13:25:26 -0400 |
| commit | 824fc04b660631e7ff976a36b7f70f7c3d5fc181 (patch) | |
| tree | a500a9e9ab7010e70e5bfb8b9b09c16fe58d7f9f | |
| parent | 2a8dca13a7f5efd36390e5a93e55d3809f325c21 (diff) | |
| download | emacs-824fc04b660631e7ff976a36b7f70f7c3d5fc181.tar.gz emacs-824fc04b660631e7ff976a36b7f70f7c3d5fc181.zip | |
(describe-symbol): Rewrite describe-function-or-variable
* lisp/help-fns.el (describe-symbol-backends): New var.
(help-xref-stack-item): Declare.
(describe-symbol): Rename from describe-function-or-variable.
Rewrite using describe-symbol-backends instead of help-xref-interned.
* lisp/help.el (help-map): Use it.
* lisp/help-mode.el (help-symbol, help-follow-symbol): Use it.
(help-xref-interned): Make it into an obsolete alias.
| -rw-r--r-- | etc/NEWS | 2 | ||||
| -rw-r--r-- | lisp/help-fns.el | 73 | ||||
| -rw-r--r-- | lisp/help-mode.el | 57 | ||||
| -rw-r--r-- | lisp/help.el | 2 |
4 files changed, 65 insertions, 69 deletions
| @@ -84,6 +84,8 @@ command line when `initial-buffer-choice' is non-nil. | |||
| 84 | 84 | ||
| 85 | * Changes in Emacs 25.1 | 85 | * Changes in Emacs 25.1 |
| 86 | 86 | ||
| 87 | ** New doc command `describe-symbol'. Works for functions, vars, faces, etc... | ||
| 88 | |||
| 87 | ** `isearch' and `query-replace' now perform character folding in matches. | 89 | ** `isearch' and `query-replace' now perform character folding in matches. |
| 88 | This is analogous to case-folding, but applies between Unicode | 90 | This is analogous to case-folding, but applies between Unicode |
| 89 | characters and their ASCII counterparts. This means many characters | 91 | characters and their ASCII counterparts. This means many characters |
diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 9541d4797b4..0a22c5ebcff 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el | |||
| @@ -32,6 +32,8 @@ | |||
| 32 | 32 | ||
| 33 | ;;; Code: | 33 | ;;; Code: |
| 34 | 34 | ||
| 35 | (require 'cl-lib) | ||
| 36 | |||
| 35 | (defvar help-fns-describe-function-functions nil | 37 | (defvar help-fns-describe-function-functions nil |
| 36 | "List of functions to run in help buffer in `describe-function'. | 38 | "List of functions to run in help buffer in `describe-function'. |
| 37 | Those functions will be run after the header line and argument | 39 | Those functions will be run after the header line and argument |
| @@ -968,13 +970,23 @@ file-local variable.\n") | |||
| 968 | (buffer-string)))))))) | 970 | (buffer-string)))))))) |
| 969 | 971 | ||
| 970 | 972 | ||
| 973 | (defvar describe-symbol-backends | ||
| 974 | `((nil ,#'fboundp ,(lambda (s _b _f) (describe-function s))) | ||
| 975 | ("face" ,#'facep ,(lambda (s _b _f) (describe-face s))) | ||
| 976 | (nil | ||
| 977 | ,(lambda (symbol) | ||
| 978 | (or (and (boundp symbol) (not (keywordp symbol))) | ||
| 979 | (get symbol 'variable-documentation))) | ||
| 980 | ,#'describe-variable))) | ||
| 981 | |||
| 982 | (defvar help-xref-stack-item) | ||
| 983 | |||
| 971 | ;;;###autoload | 984 | ;;;###autoload |
| 972 | (defun describe-function-or-variable (symbol &optional buffer frame) | 985 | (defun describe-symbol (symbol &optional buffer frame) |
| 973 | "Display the full documentation of the function or variable SYMBOL. | 986 | "Display the full documentation of SYMBOL. |
| 974 | If SYMBOL is a variable and has a buffer-local value in BUFFER or FRAME | 987 | Will show the info of SYMBOL as a function, variable, and/or face." |
| 975 | \(default to the current buffer and current frame), it is displayed along | ||
| 976 | with the global value." | ||
| 977 | (interactive | 988 | (interactive |
| 989 | ;; FIXME: also let the user enter a face name. | ||
| 978 | (let* ((v-or-f (variable-at-point)) | 990 | (let* ((v-or-f (variable-at-point)) |
| 979 | (found (symbolp v-or-f)) | 991 | (found (symbolp v-or-f)) |
| 980 | (v-or-f (if found v-or-f (function-called-at-point))) | 992 | (v-or-f (if found v-or-f (function-called-at-point))) |
| @@ -983,21 +995,54 @@ with the global value." | |||
| 983 | val) | 995 | val) |
| 984 | (setq val (completing-read (if found | 996 | (setq val (completing-read (if found |
| 985 | (format | 997 | (format |
| 986 | "Describe function or variable (default %s): " v-or-f) | 998 | "Describe symbol (default %s): " v-or-f) |
| 987 | "Describe function or variable: ") | 999 | "Describe symbol: ") |
| 988 | obarray | 1000 | obarray |
| 989 | (lambda (vv) | 1001 | (lambda (vv) |
| 990 | (or (fboundp vv) | 1002 | (cl-some (lambda (x) (funcall (nth 1 x) vv)) |
| 991 | (get vv 'variable-documentation) | 1003 | describe-symbol-backends)) |
| 992 | (and (boundp vv) (not (keywordp vv))))) | ||
| 993 | t nil nil | 1004 | t nil nil |
| 994 | (if found (symbol-name v-or-f)))) | 1005 | (if found (symbol-name v-or-f)))) |
| 995 | (list (if (equal val "") | 1006 | (list (if (equal val "") |
| 996 | v-or-f (intern val))))) | 1007 | v-or-f (intern val))))) |
| 997 | (if (not (symbolp symbol)) (message "You didn't specify a function or variable") | 1008 | (if (not (symbolp symbol)) |
| 998 | (unless (buffer-live-p buffer) (setq buffer (current-buffer))) | 1009 | (user-error "You didn't specify a function or variable")) |
| 999 | (unless (frame-live-p frame) (setq frame (selected-frame))) | 1010 | (unless (buffer-live-p buffer) (setq buffer (current-buffer))) |
| 1000 | (help-xref-interned symbol buffer frame))) | 1011 | (unless (frame-live-p frame) (setq frame (selected-frame))) |
| 1012 | (with-current-buffer (help-buffer) | ||
| 1013 | ;; Push the previous item on the stack before clobbering the output buffer. | ||
| 1014 | (help-setup-xref nil nil) | ||
| 1015 | (let* ((docs | ||
| 1016 | (nreverse | ||
| 1017 | (delq nil | ||
| 1018 | (mapcar (pcase-lambda (`(,name ,testfn ,descfn)) | ||
| 1019 | (when (funcall testfn symbol) | ||
| 1020 | ;; Don't record the current entry in the stack. | ||
| 1021 | (setq help-xref-stack-item nil) | ||
| 1022 | (cons name | ||
| 1023 | (funcall descfn symbol buffer frame)))) | ||
| 1024 | describe-symbol-backends)))) | ||
| 1025 | (single (null (cdr docs)))) | ||
| 1026 | (while (cdr docs) | ||
| 1027 | (goto-char (point-min)) | ||
| 1028 | (let ((inhibit-read-only t) | ||
| 1029 | (name (caar docs)) ;Name of doc currently at BOB. | ||
| 1030 | (doc (cdr (cadr docs)))) ;Doc to add at BOB. | ||
| 1031 | (insert doc) | ||
| 1032 | (delete-region (point) (progn (skip-chars-backward " \t\n") (point))) | ||
| 1033 | (insert "\n\n" | ||
| 1034 | (eval-when-compile | ||
| 1035 | (propertize "\n" 'face '(:height 0.1 :inverse-video t))) | ||
| 1036 | "\n") | ||
| 1037 | (when name | ||
| 1038 | (insert (symbol-name symbol) | ||
| 1039 | " is also a " name "." "\n\n"))) | ||
| 1040 | (setq docs (cdr docs))) | ||
| 1041 | (unless single | ||
| 1042 | ;; Don't record the `describe-variable' item in the stack. | ||
| 1043 | (setq help-xref-stack-item nil) | ||
| 1044 | (help-setup-xref (list #'describe-symbol symbol) nil)) | ||
| 1045 | (goto-char (point-min))))) | ||
| 1001 | 1046 | ||
| 1002 | ;;;###autoload | 1047 | ;;;###autoload |
| 1003 | (defun describe-syntax (&optional buffer) | 1048 | (defun describe-syntax (&optional buffer) |
diff --git a/lisp/help-mode.el b/lisp/help-mode.el index 6454eed27bd..cdddd542532 100644 --- a/lisp/help-mode.el +++ b/lisp/help-mode.el | |||
| @@ -148,7 +148,7 @@ The format is (FUNCTION ARGS...).") | |||
| 148 | 148 | ||
| 149 | (define-button-type 'help-symbol | 149 | (define-button-type 'help-symbol |
| 150 | :supertype 'help-xref | 150 | :supertype 'help-xref |
| 151 | 'help-function #'help-xref-interned | 151 | 'help-function #'describe-symbol |
| 152 | 'help-echo (purecopy "mouse-2, RET: describe this symbol")) | 152 | 'help-echo (purecopy "mouse-2, RET: describe this symbol")) |
| 153 | 153 | ||
| 154 | (define-button-type 'help-back | 154 | (define-button-type 'help-back |
| @@ -624,58 +624,7 @@ See `help-make-xrefs'." | |||
| 624 | ;; Additional functions for (re-)creating types of help buffers. | 624 | ;; Additional functions for (re-)creating types of help buffers. |
| 625 | 625 | ||
| 626 | ;;;###autoload | 626 | ;;;###autoload |
| 627 | (defun help-xref-interned (symbol &optional buffer frame) | 627 | (define-obsolete-function-alias 'help-xref-interned 'describe-symbol "25.1") |
| 628 | "Follow a hyperlink which appeared to be an arbitrary interned SYMBOL. | ||
| 629 | Both variable, function and face documentation are extracted into a single | ||
| 630 | help buffer. If SYMBOL is a variable, include buffer-local value for optional | ||
| 631 | BUFFER or FRAME." | ||
| 632 | (with-current-buffer (help-buffer) | ||
| 633 | ;; Push the previous item on the stack before clobbering the output buffer. | ||
| 634 | (help-setup-xref nil nil) | ||
| 635 | (let ((facedoc (when (facep symbol) | ||
| 636 | ;; Don't record the current entry in the stack. | ||
| 637 | (setq help-xref-stack-item nil) | ||
| 638 | (describe-face symbol))) | ||
| 639 | (fdoc (when (fboundp symbol) | ||
| 640 | ;; Don't record the current entry in the stack. | ||
| 641 | (setq help-xref-stack-item nil) | ||
| 642 | (describe-function symbol))) | ||
| 643 | (sdoc (when (or (boundp symbol) | ||
| 644 | (get symbol 'variable-documentation)) | ||
| 645 | ;; Don't record the current entry in the stack. | ||
| 646 | (setq help-xref-stack-item nil) | ||
| 647 | (describe-variable symbol buffer frame)))) | ||
| 648 | (cond | ||
| 649 | (sdoc | ||
| 650 | ;; We now have a help buffer on the variable. | ||
| 651 | ;; Insert the function and face text before it. | ||
| 652 | (when (or fdoc facedoc) | ||
| 653 | (goto-char (point-min)) | ||
| 654 | (let ((inhibit-read-only t)) | ||
| 655 | (when fdoc | ||
| 656 | (insert fdoc "\n\n") | ||
| 657 | (when facedoc | ||
| 658 | (insert (make-string 30 ?-) "\n\n" (symbol-name symbol) | ||
| 659 | " is also a " "face." "\n\n"))) | ||
| 660 | (when facedoc | ||
| 661 | (insert facedoc "\n\n")) | ||
| 662 | (insert (make-string 30 ?-) "\n\n" (symbol-name symbol) | ||
| 663 | " is also a " "variable." "\n\n")) | ||
| 664 | ;; Don't record the `describe-variable' item in the stack. | ||
| 665 | (setq help-xref-stack-item nil) | ||
| 666 | (help-setup-xref (list #'help-xref-interned symbol) nil))) | ||
| 667 | (fdoc | ||
| 668 | ;; We now have a help buffer on the function. | ||
| 669 | ;; Insert face text before it. | ||
| 670 | (when facedoc | ||
| 671 | (goto-char (point-max)) | ||
| 672 | (let ((inhibit-read-only t)) | ||
| 673 | (insert "\n\n" (make-string 30 ?-) "\n\n" (symbol-name symbol) | ||
| 674 | " is also a " "face." "\n\n" facedoc)) | ||
| 675 | ;; Don't record the `describe-function' item in the stack. | ||
| 676 | (setq help-xref-stack-item nil) | ||
| 677 | (help-setup-xref (list #'help-xref-interned symbol) nil)))) | ||
| 678 | (goto-char (point-min))))) | ||
| 679 | 628 | ||
| 680 | 629 | ||
| 681 | ;; Navigation/hyperlinking with xrefs | 630 | ;; Navigation/hyperlinking with xrefs |
| @@ -774,7 +723,7 @@ Show all docs for that symbol as either a variable, function or face." | |||
| 774 | (when (or (boundp sym) | 723 | (when (or (boundp sym) |
| 775 | (get sym 'variable-documentation) | 724 | (get sym 'variable-documentation) |
| 776 | (fboundp sym) (facep sym)) | 725 | (fboundp sym) (facep sym)) |
| 777 | (help-do-xref pos #'help-xref-interned (list sym))))) | 726 | (help-do-xref pos #'describe-symbol (list sym))))) |
| 778 | 727 | ||
| 779 | (defun help-mode-revert-buffer (_ignore-auto noconfirm) | 728 | (defun help-mode-revert-buffer (_ignore-auto noconfirm) |
| 780 | (when (or noconfirm (yes-or-no-p "Revert help buffer? ")) | 729 | (when (or noconfirm (yes-or-no-p "Revert help buffer? ")) |
diff --git a/lisp/help.el b/lisp/help.el index 7a3460c1b3d..1826cb7219a 100644 --- a/lisp/help.el +++ b/lisp/help.el | |||
| @@ -95,7 +95,7 @@ | |||
| 95 | (define-key map "k" 'describe-key) | 95 | (define-key map "k" 'describe-key) |
| 96 | (define-key map "l" 'view-lossage) | 96 | (define-key map "l" 'view-lossage) |
| 97 | (define-key map "m" 'describe-mode) | 97 | (define-key map "m" 'describe-mode) |
| 98 | (define-key map "o" 'describe-function-or-variable) | 98 | (define-key map "o" 'describe-symbol) |
| 99 | (define-key map "n" 'view-emacs-news) | 99 | (define-key map "n" 'view-emacs-news) |
| 100 | (define-key map "p" 'finder-by-keyword) | 100 | (define-key map "p" 'finder-by-keyword) |
| 101 | (define-key map "P" 'describe-package) | 101 | (define-key map "P" 'describe-package) |