]> git.eshelyaron.com Git - emacs.git/commitdiff
Add minibuffer alternative actions for 'C-h f' and 'C-h v'
authorEshel Yaron <me@eshelyaron.com>
Tue, 16 Jul 2024 17:27:16 +0000 (19:27 +0200)
committerEshel Yaron <me@eshelyaron.com>
Tue, 16 Jul 2024 17:27:16 +0000 (19:27 +0200)
lisp/help-fns.el

index b31d2c34ffd6a28e65f752a799235d3f7265d1b1..187d1dd6a4130f3627b5e5c2e641af9b191af9f3 100644 (file)
@@ -276,18 +276,35 @@ interactive command."
                                     "Describe command"
                                   "Describe function")
                                 fn))
-         (val (completing-read
-               prompt
-               #'help--symbol-completion-table
-               (lambda (f) (if want-command
-                          (commandp f)
-                        (or (fboundp f) (get f 'function-documentation))))
-               ;; We used `confirm' for a while because we may want to see the
-               ;; meta-info about a function even if the function itself is not
-               ;; defined, but this use case is too marginal and rarely tested,
-               ;; not worth the trouble (bug#64902).
-               t nil nil
-               (and fn (symbol-name fn)))))
+         (val
+          (minibuffer-with-setup-hook
+              (lambda ()
+                (setq minibuffer-alternative-action
+                      (cons (lambda (c)
+                              (let* ((buffer-point
+                                      (save-excursion
+                                       (find-function-noselect (intern c))))
+                                    (new-buf (car buffer-point))
+                                    (new-point (cdr buffer-point)))
+                                (if buffer-point
+                                    (with-selected-window (display-buffer new-buf)
+                                      (when new-point (goto-char new-point))
+                                      (run-hooks 'find-function-after-hook))
+                                  (minibuffer-message
+                                   "Don't know where `%s' is defined" c))))
+                            "find")))
+            (completing-read
+             prompt #'help--symbol-completion-table
+             (lambda (f)
+               (if want-command
+                   (commandp f)
+                 (or (fboundp f) (get f 'function-documentation))))
+             ;; We used `confirm' for a while because we may want to see the
+             ;; meta-info about a function even if the function itself is not
+             ;; defined, but this use case is too marginal and rarely tested,
+             ;; not worth the trouble (bug#64902).
+             t nil nil
+             (and fn (symbol-name fn))))))
     (unless (equal val "")
       (setq fn (intern val)))
     ;; These error messages are intended to be less technical for the
@@ -1325,18 +1342,35 @@ it is displayed along with the global value."
    (let ((v (variable-at-point))
          (orig-buffer (current-buffer))
         val)
-     (setq val (completing-read
-                (format-prompt "Describe variable" (and (symbolp v) v))
-                #'help--symbol-completion-table
-                (lambda (vv)
-                  (or (get vv 'variable-documentation)
-                      (and (not (keywordp vv))
-                           ;; Since the variable may only exist in the
-                           ;; original buffer, we have to look for it
-                           ;; there.
-                           (buffer-local-boundp vv orig-buffer))))
-                t nil nil
-                (if (symbolp v) (symbol-name v))))
+     (setq val
+           (minibuffer-with-setup-hook
+               (lambda ()
+                 (setq minibuffer-alternative-action
+                       (cons (lambda (c)
+                               (let* ((buffer-point
+                                       (save-excursion
+                                        (find-variable-noselect (intern c))))
+                                     (new-buf (car buffer-point))
+                                     (new-point (cdr buffer-point)))
+                                 (if buffer-point
+                                     (with-selected-window (display-buffer new-buf)
+                                       (when new-point (goto-char new-point))
+                                       (run-hooks 'find-function-after-hook))
+                                   (minibuffer-message
+                                    "Don't know where `%s' is defined" c))))
+                             "find")))
+             (completing-read
+              (format-prompt "Describe variable" (and (symbolp v) v))
+              #'help--symbol-completion-table
+              (lambda (vv)
+                (or (get vv 'variable-documentation)
+                    (and (not (keywordp vv))
+                         ;; Since the variable may only exist in the
+                         ;; original buffer, we have to look for it
+                         ;; there.
+                         (buffer-local-boundp vv orig-buffer))))
+              t nil nil
+              (if (symbolp v) (symbol-name v)))))
      (list (if (equal val "")
               v (intern val)))))
   (let (file-name