summaryrefslogtreecommitdiff
path: root/lisp/help-fns.el
diff options
context:
space:
mode:
authorNoam Postavsky <npostavs@gmail.com>2017-06-03 22:15:19 -0400
committerNoam Postavsky <npostavs@gmail.com>2017-06-27 20:34:14 -0400
commit2d992690de5bcb2036eeb4d2854761596b863704 (patch)
tree8a200ae5194707445c0da6f9efc46b39aa04465f /lisp/help-fns.el
parent4a5653cd2859308ada4bbf5ffc9fb9b283eef31a (diff)
downloademacs-2d992690de5bcb2036eeb4d2854761596b863704.tar.gz
emacs-2d992690de5bcb2036eeb4d2854761596b863704.tar.bz2
emacs-2d992690de5bcb2036eeb4d2854761596b863704.zip
Don't read eshell/which output from *Help* buffer (Bug#26894)
* lisp/help-fns.el (help-fns--analyse-function) (help-fns-function-description-header): New functions, extracted from describe-function-1. (describe-function-1): Use them. * lisp/eshell/esh-cmd.el (eshell/which): Use `help-fns-function-description-header' instead of `describe-function-1'.
Diffstat (limited to 'lisp/help-fns.el')
-rw-r--r--lisp/help-fns.el103
1 files changed, 57 insertions, 46 deletions
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 2c635ffa500..32324ae3bcb 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -560,8 +560,9 @@ FILE is the file where FUNCTION was probably defined."
(setq short rel))))
short))
-;;;###autoload
-(defun describe-function-1 (function)
+(defun help-fns--analyse-function (function)
+ "Return information about FUNCTION.
+Returns a list of the form (REAL-FUNCTION DEF ALIASED REAL-DEF)."
(let* ((advised (and (symbolp function)
(featurep 'nadvice)
(advice--p (advice--symbol-function function))))
@@ -594,22 +595,24 @@ FILE is the file where FUNCTION was probably defined."
(setq f (symbol-function f)))
f))
((subrp def) (intern (subr-name def)))
- (t def)))
- (sig-key (if (subrp def)
- (indirect-function real-def)
- real-def))
- (file-name (find-lisp-object-file-name function (if aliased 'defun
- def)))
- (pt1 (with-current-buffer (help-buffer) (point)))
- (beg (if (and (or (byte-code-function-p def)
- (keymapp def)
- (memq (car-safe def) '(macro lambda closure)))
- (stringp file-name)
- (help-fns--autoloaded-p function file-name))
- (if (commandp def)
- "an interactive autoloaded "
- "an autoloaded ")
- (if (commandp def) "an interactive " "a "))))
+ (t def))))
+ (list real-function def aliased real-def)))
+
+(defun help-fns-function-description-header (function)
+ "Print a line describing FUNCTION to `standard-output'."
+ (pcase-let* ((`(,_real-function ,def ,aliased ,real-def)
+ (help-fns--analyse-function function))
+ (file-name (find-lisp-object-file-name function (if aliased 'defun
+ def)))
+ (beg (if (and (or (byte-code-function-p def)
+ (keymapp def)
+ (memq (car-safe def) '(macro lambda closure)))
+ (stringp file-name)
+ (help-fns--autoloaded-p function file-name))
+ (if (commandp def)
+ "an interactive autoloaded "
+ "an autoloaded ")
+ (if (commandp def) "an interactive " "a "))))
;; Print what kind of function-like object FUNCTION is.
(princ (cond ((or (stringp def) (vectorp def))
@@ -676,34 +679,42 @@ FILE is the file where FUNCTION was probably defined."
(re-search-backward (substitute-command-keys "`\\([^`']+\\)'")
nil t)
(help-xref-button 1 'help-function-def function file-name))))
- (princ ".")
- (with-current-buffer (help-buffer)
- (fill-region-as-paragraph (save-excursion (goto-char pt1) (forward-line 0) (point))
- (point)))
- (terpri)(terpri)
-
- (let ((doc-raw (documentation function t))
- (key-bindings-buffer (current-buffer)))
-
- ;; If the function is autoloaded, and its docstring has
- ;; key substitution constructs, load the library.
- (and (autoloadp real-def) doc-raw
- help-enable-auto-load
- (string-match "\\([^\\]=\\|[^=]\\|\\`\\)\\\\[[{<]" doc-raw)
- (autoload-do-load real-def))
-
- (help-fns--key-bindings function)
- (with-current-buffer standard-output
- (let ((doc (help-fns--signature function doc-raw sig-key
- real-function key-bindings-buffer)))
- (run-hook-with-args 'help-fns-describe-function-functions function)
- (insert "\n"
- (or doc "Not documented."))
- ;; Avoid asking the user annoying questions if she decides
- ;; to save the help buffer, when her locale's codeset
- ;; isn't UTF-8.
- (unless (memq text-quoting-style '(straight grave))
- (set-buffer-file-coding-system 'utf-8))))))))
+ (princ "."))))
+
+;;;###autoload
+(defun describe-function-1 (function)
+ (let ((pt1 (with-current-buffer (help-buffer) (point))))
+ (help-fns-function-description-header function)
+ (with-current-buffer (help-buffer)
+ (fill-region-as-paragraph (save-excursion (goto-char pt1) (forward-line 0) (point))
+ (point))))
+ (terpri)(terpri)
+
+ (pcase-let ((`(,real-function ,def ,_aliased ,real-def)
+ (help-fns--analyse-function function))
+ (doc-raw (documentation function t))
+ (key-bindings-buffer (current-buffer)))
+
+ ;; If the function is autoloaded, and its docstring has
+ ;; key substitution constructs, load the library.
+ (and (autoloadp real-def) doc-raw
+ help-enable-auto-load
+ (string-match "\\([^\\]=\\|[^=]\\|\\`\\)\\\\[[{<]" doc-raw)
+ (autoload-do-load real-def))
+
+ (help-fns--key-bindings function)
+ (with-current-buffer standard-output
+ (let ((doc (help-fns--signature
+ function doc-raw
+ (if (subrp def) (indirect-function real-def) real-def)
+ real-function key-bindings-buffer)))
+ (run-hook-with-args 'help-fns-describe-function-functions function)
+ (insert "\n" (or doc "Not documented.")))
+ ;; Avoid asking the user annoying questions if she decides
+ ;; to save the help buffer, when her locale's codeset
+ ;; isn't UTF-8.
+ (unless (memq text-quoting-style '(straight grave))
+ (set-buffer-file-coding-system 'utf-8)))))
;; Add defaults to `help-fns-describe-function-functions'.
(add-hook 'help-fns-describe-function-functions #'help-fns--obsolete)