diff options
| author | Noam Postavsky | 2017-06-03 22:15:19 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2017-06-27 20:34:14 -0400 |
| commit | 2d992690de5bcb2036eeb4d2854761596b863704 (patch) | |
| tree | 8a200ae5194707445c0da6f9efc46b39aa04465f | |
| parent | 4a5653cd2859308ada4bbf5ffc9fb9b283eef31a (diff) | |
| download | emacs-2d992690de5bcb2036eeb4d2854761596b863704.tar.gz 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'.
| -rw-r--r-- | lisp/eshell/esh-cmd.el | 32 | ||||
| -rw-r--r-- | lisp/help-fns.el | 103 |
2 files changed, 70 insertions, 65 deletions
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index 86e7b83c281..24342208771 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el | |||
| @@ -1148,6 +1148,8 @@ be finished later after the completion of an asynchronous subprocess." | |||
| 1148 | 1148 | ||
| 1149 | ;; command invocation | 1149 | ;; command invocation |
| 1150 | 1150 | ||
| 1151 | (declare-function help-fns-function-description-header "help-fns") | ||
| 1152 | |||
| 1151 | (defun eshell/which (command &rest names) | 1153 | (defun eshell/which (command &rest names) |
| 1152 | "Identify the COMMAND, and where it is located." | 1154 | "Identify the COMMAND, and where it is located." |
| 1153 | (dolist (name (cons command names)) | 1155 | (dolist (name (cons command names)) |
| @@ -1164,25 +1166,17 @@ be finished later after the completion of an asynchronous subprocess." | |||
| 1164 | (concat name " is an alias, defined as \"" | 1166 | (concat name " is an alias, defined as \"" |
| 1165 | (cadr alias) "\""))) | 1167 | (cadr alias) "\""))) |
| 1166 | (unless program | 1168 | (unless program |
| 1167 | (setq program (eshell-search-path name)) | 1169 | (setq program |
| 1168 | (let* ((esym (eshell-find-alias-function name)) | 1170 | (let* ((esym (eshell-find-alias-function name)) |
| 1169 | (sym (or esym (intern-soft name)))) | 1171 | (sym (or esym (intern-soft name)))) |
| 1170 | (if (and (or esym (and sym (fboundp sym))) | 1172 | (if (and (or esym (and sym (fboundp sym))) |
| 1171 | (or eshell-prefer-lisp-functions (not direct))) | 1173 | (or eshell-prefer-lisp-functions (not direct))) |
| 1172 | (let ((desc (let ((inhibit-redisplay t)) | 1174 | (or (with-output-to-string |
| 1173 | (save-window-excursion | 1175 | (require 'help-fns) |
| 1174 | (prog1 | 1176 | (princ (format "%s is " sym)) |
| 1175 | (describe-function sym) | 1177 | (help-fns-function-description-header sym)) |
| 1176 | (message nil)))))) | 1178 | name) |
| 1177 | (setq desc (if desc (substring desc 0 | 1179 | (eshell-search-path name))))) |
| 1178 | (1- (or (string-match "\n" desc) | ||
| 1179 | (length desc)))) | ||
| 1180 | ;; This should not happen. | ||
| 1181 | (format "%s is defined, \ | ||
| 1182 | but no documentation was found" name))) | ||
| 1183 | (if (buffer-live-p (get-buffer "*Help*")) | ||
| 1184 | (kill-buffer "*Help*")) | ||
| 1185 | (setq program (or desc name)))))) | ||
| 1186 | (if (not program) | 1180 | (if (not program) |
| 1187 | (eshell-error (format "which: no %s in (%s)\n" | 1181 | (eshell-error (format "which: no %s in (%s)\n" |
| 1188 | name (getenv "PATH"))) | 1182 | name (getenv "PATH"))) |
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." | |||
| 560 | (setq short rel)))) | 560 | (setq short rel)))) |
| 561 | short)) | 561 | short)) |
| 562 | 562 | ||
| 563 | ;;;###autoload | 563 | (defun help-fns--analyse-function (function) |
| 564 | (defun describe-function-1 (function) | 564 | "Return information about FUNCTION. |
| 565 | Returns a list of the form (REAL-FUNCTION DEF ALIASED REAL-DEF)." | ||
| 565 | (let* ((advised (and (symbolp function) | 566 | (let* ((advised (and (symbolp function) |
| 566 | (featurep 'nadvice) | 567 | (featurep 'nadvice) |
| 567 | (advice--p (advice--symbol-function function)))) | 568 | (advice--p (advice--symbol-function function)))) |
| @@ -594,22 +595,24 @@ FILE is the file where FUNCTION was probably defined." | |||
| 594 | (setq f (symbol-function f))) | 595 | (setq f (symbol-function f))) |
| 595 | f)) | 596 | f)) |
| 596 | ((subrp def) (intern (subr-name def))) | 597 | ((subrp def) (intern (subr-name def))) |
| 597 | (t def))) | 598 | (t def)))) |
| 598 | (sig-key (if (subrp def) | 599 | (list real-function def aliased real-def))) |
| 599 | (indirect-function real-def) | 600 | |
| 600 | real-def)) | 601 | (defun help-fns-function-description-header (function) |
| 601 | (file-name (find-lisp-object-file-name function (if aliased 'defun | 602 | "Print a line describing FUNCTION to `standard-output'." |
| 602 | def))) | 603 | (pcase-let* ((`(,_real-function ,def ,aliased ,real-def) |
| 603 | (pt1 (with-current-buffer (help-buffer) (point))) | 604 | (help-fns--analyse-function function)) |
| 604 | (beg (if (and (or (byte-code-function-p def) | 605 | (file-name (find-lisp-object-file-name function (if aliased 'defun |
| 605 | (keymapp def) | 606 | def))) |
| 606 | (memq (car-safe def) '(macro lambda closure))) | 607 | (beg (if (and (or (byte-code-function-p def) |
| 607 | (stringp file-name) | 608 | (keymapp def) |
| 608 | (help-fns--autoloaded-p function file-name)) | 609 | (memq (car-safe def) '(macro lambda closure))) |
| 609 | (if (commandp def) | 610 | (stringp file-name) |
| 610 | "an interactive autoloaded " | 611 | (help-fns--autoloaded-p function file-name)) |
| 611 | "an autoloaded ") | 612 | (if (commandp def) |
| 612 | (if (commandp def) "an interactive " "a ")))) | 613 | "an interactive autoloaded " |
| 614 | "an autoloaded ") | ||
| 615 | (if (commandp def) "an interactive " "a ")))) | ||
| 613 | 616 | ||
| 614 | ;; Print what kind of function-like object FUNCTION is. | 617 | ;; Print what kind of function-like object FUNCTION is. |
| 615 | (princ (cond ((or (stringp def) (vectorp def)) | 618 | (princ (cond ((or (stringp def) (vectorp def)) |
| @@ -676,34 +679,42 @@ FILE is the file where FUNCTION was probably defined." | |||
| 676 | (re-search-backward (substitute-command-keys "`\\([^`']+\\)'") | 679 | (re-search-backward (substitute-command-keys "`\\([^`']+\\)'") |
| 677 | nil t) | 680 | nil t) |
| 678 | (help-xref-button 1 'help-function-def function file-name)))) | 681 | (help-xref-button 1 'help-function-def function file-name)))) |
| 679 | (princ ".") | 682 | (princ ".")))) |
| 680 | (with-current-buffer (help-buffer) | 683 | |
| 681 | (fill-region-as-paragraph (save-excursion (goto-char pt1) (forward-line 0) (point)) | 684 | ;;;###autoload |
| 682 | (point))) | 685 | (defun describe-function-1 (function) |
| 683 | (terpri)(terpri) | 686 | (let ((pt1 (with-current-buffer (help-buffer) (point)))) |
| 684 | 687 | (help-fns-function-description-header function) | |
| 685 | (let ((doc-raw (documentation function t)) | 688 | (with-current-buffer (help-buffer) |
| 686 | (key-bindings-buffer (current-buffer))) | 689 | (fill-region-as-paragraph (save-excursion (goto-char pt1) (forward-line 0) (point)) |
| 687 | 690 | (point)))) | |
| 688 | ;; If the function is autoloaded, and its docstring has | 691 | (terpri)(terpri) |
| 689 | ;; key substitution constructs, load the library. | 692 | |
| 690 | (and (autoloadp real-def) doc-raw | 693 | (pcase-let ((`(,real-function ,def ,_aliased ,real-def) |
| 691 | help-enable-auto-load | 694 | (help-fns--analyse-function function)) |
| 692 | (string-match "\\([^\\]=\\|[^=]\\|\\`\\)\\\\[[{<]" doc-raw) | 695 | (doc-raw (documentation function t)) |
| 693 | (autoload-do-load real-def)) | 696 | (key-bindings-buffer (current-buffer))) |
| 694 | 697 | ||
| 695 | (help-fns--key-bindings function) | 698 | ;; If the function is autoloaded, and its docstring has |
| 696 | (with-current-buffer standard-output | 699 | ;; key substitution constructs, load the library. |
| 697 | (let ((doc (help-fns--signature function doc-raw sig-key | 700 | (and (autoloadp real-def) doc-raw |
| 698 | real-function key-bindings-buffer))) | 701 | help-enable-auto-load |
| 699 | (run-hook-with-args 'help-fns-describe-function-functions function) | 702 | (string-match "\\([^\\]=\\|[^=]\\|\\`\\)\\\\[[{<]" doc-raw) |
| 700 | (insert "\n" | 703 | (autoload-do-load real-def)) |
| 701 | (or doc "Not documented.")) | 704 | |
| 702 | ;; Avoid asking the user annoying questions if she decides | 705 | (help-fns--key-bindings function) |
| 703 | ;; to save the help buffer, when her locale's codeset | 706 | (with-current-buffer standard-output |
| 704 | ;; isn't UTF-8. | 707 | (let ((doc (help-fns--signature |
| 705 | (unless (memq text-quoting-style '(straight grave)) | 708 | function doc-raw |
| 706 | (set-buffer-file-coding-system 'utf-8)))))))) | 709 | (if (subrp def) (indirect-function real-def) real-def) |
| 710 | real-function key-bindings-buffer))) | ||
| 711 | (run-hook-with-args 'help-fns-describe-function-functions function) | ||
| 712 | (insert "\n" (or doc "Not documented."))) | ||
| 713 | ;; Avoid asking the user annoying questions if she decides | ||
| 714 | ;; to save the help buffer, when her locale's codeset | ||
| 715 | ;; isn't UTF-8. | ||
| 716 | (unless (memq text-quoting-style '(straight grave)) | ||
| 717 | (set-buffer-file-coding-system 'utf-8))))) | ||
| 707 | 718 | ||
| 708 | ;; Add defaults to `help-fns-describe-function-functions'. | 719 | ;; Add defaults to `help-fns-describe-function-functions'. |
| 709 | (add-hook 'help-fns-describe-function-functions #'help-fns--obsolete) | 720 | (add-hook 'help-fns-describe-function-functions #'help-fns--obsolete) |