]> git.eshelyaron.com Git - emacs.git/commitdiff
find-func.el: Multi commands
authorEshel Yaron <me@eshelyaron.com>
Wed, 22 May 2024 20:26:46 +0000 (22:26 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 22 May 2024 20:26:46 +0000 (22:26 +0200)
lisp/emacs-lisp/find-func.el

index 411602ef166897dc475f51e83789770899278549..ffcd3196259c7df08c472e722933758078389aa0 100644 (file)
@@ -307,6 +307,19 @@ TYPE should be nil to find a function, or `defvar' to find a variable."
       (error "Can't find source for %s" fun-or-var))
     (cons (current-buffer) (match-beginning 0))))
 
+(defun display-library (library)
+  "Display the Emacs Lisp source of LIBRARY.
+
+Interactively, prompt for LIBRARY using the one at or near point.
+
+This function searches `find-library-source-path' if non-nil, and
+`load-path' otherwise.
+
+See the `find-library-include-other-files' user option for
+customizing the candidate completions."
+  (interactive (list (read-library-name)))
+  (display-buffer (find-file-noselect (find-library-name library))))
+
 ;;;###autoload
 (defun find-library (library)
   "Find the Emacs Lisp source of LIBRARY.
@@ -323,6 +336,8 @@ customizing the candidate completions."
       (switch-to-buffer (find-file-noselect (find-library-name library)))
     (run-hooks 'find-function-after-hook)))
 
+(put 'find-library 'minibuffer-action '(display-library . "find"))
+
 ;;;###autoload
 (defun read-library-name ()
   "Read and return a library name, defaulting to the one near point.
@@ -379,6 +394,8 @@ See `find-library' for more details."
                                       (find-library-name library)))
     (run-hooks 'find-function-after-hook)))
 
+(put 'find-library-other-window 'minibuffer-action 'find-library)
+
 ;;;###autoload
 (defun find-library-other-frame (library)
   "Find the Emacs Lisp source of LIBRARY in another frame.
@@ -390,6 +407,8 @@ See `find-library' for more details."
                                      (find-library-name library)))
     (run-hooks 'find-function-after-hook)))
 
+(put 'find-library-other-frame 'minibuffer-action 'find-library)
+
 ;;;###autoload
 (defun find-function-search-for-symbol (symbol type library)
   "Search for SYMBOL's definition of type TYPE in LIBRARY.
@@ -593,11 +612,19 @@ otherwise uses `variable-at-point'."
          (prompt-type (cdr (assq type '((nil . "function")
                                         (defvar . "variable")
                                         (defface . "face")))))
+         (action this-command)
          (enable-recursive-minibuffers t))
-    (list (intern (completing-read
-                   (format-prompt "Find %s" symb prompt-type)
-                   obarray predicate
-                   'lambda nil nil (and symb (symbol-name symb)))))))
+    (list (intern
+           (minibuffer-with-setup-hook
+               (lambda () (setq minibuffer-completion-action
+                                (cons (lambda (s)
+                                        (save-selected-window
+                                          (funcall action (intern s))))
+                                      "find")))
+             (completing-read
+              (format-prompt "Find %s" symb prompt-type)
+              obarray predicate
+              'lambda nil nil (and symb (symbol-name symb))))))))
 
 (defun find-function-do-it (symbol type switch-fn)
   "Find Emacs Lisp SYMBOL in a buffer and display it.