]> git.eshelyaron.com Git - emacs.git/commitdiff
New commands: find-library-other-window, find-library-other-frame
authorCharles A. Roelli <charles@aurox.ch>
Sat, 20 May 2017 11:41:53 +0000 (14:41 +0300)
committerEli Zaretskii <eliz@gnu.org>
Sat, 20 May 2017 11:41:53 +0000 (14:41 +0300)
* lisp/emacs-lisp/find-func.el (find-library-other-window)
(find-library-other-frame): New commands to complement the
existing 'find-library' command.  (Bug#26712)
(read-library-name): New function to read a library name.
* etc/NEWS: Mention 'find-library-other-window' and
'find-library-other-frame'.

etc/NEWS
lisp/emacs-lisp/find-func.el

index aa579b11c7a6b284680e958156e7f9e7a49d1424..2a4b7014d4ec7bcbc5eafe6e65ed4a8c804b7342 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -356,6 +356,9 @@ use the local Emacs to edit remote files via Tramp.  See the node
 ** The new variable 'eval-expression-print-maximum-character' prevents
 large integers from being displayed as characters.
 
+** Two new commands for finding the source code of Emacs Lisp
+libraries: 'find-library-other-window' and 'find-library-other-frame'.
+
 \f
 * Editing Changes in Emacs 26.1
 
index d0acc147752cf37da880ec9315da24fc5f665605..9b98f05ae810bb361fe60b7a6f26614400508759 100644 (file)
@@ -271,43 +271,65 @@ TYPE should be nil to find a function, or `defvar' to find a variable."
     (cons (current-buffer) (match-beginning 0))))
 
 ;;;###autoload
-(defun find-library (library &optional other-window)
+(defun find-library (library)
   "Find the Emacs Lisp source of LIBRARY.
-LIBRARY should be a string (the name of the library).  If the
-optional OTHER-WINDOW argument (i.e., the command argument) is
-specified, pop to a different window before displaying the
-buffer."
-  (interactive
-   (let* ((dirs (or find-function-source-path load-path))
-          (suffixes (find-library-suffixes))
-          (table (apply-partially 'locate-file-completion-table
-                                  dirs suffixes))
-         (def (if (eq (function-called-at-point) 'require)
-                  ;; `function-called-at-point' may return 'require
-                  ;; with `point' anywhere on this line.  So wrap the
-                  ;; `save-excursion' below in a `condition-case' to
-                  ;; avoid reporting a scan-error here.
-                  (condition-case nil
-                      (save-excursion
-                        (backward-up-list)
-                        (forward-char)
-                        (forward-sexp 2)
-                        (thing-at-point 'symbol))
-                    (error nil))
-                (thing-at-point 'symbol))))
-     (when (and def (not (test-completion def table)))
-       (setq def nil))
-     (list
-      (completing-read (if def
-                           (format "Library name (default %s): " def)
-                        "Library name: ")
-                      table nil nil nil nil def)
-      current-prefix-arg)))
+
+Interactively, prompt for LIBRARY using the one at or near point."
+  (interactive (list (read-library-name)))
+  (prog1
+      (switch-to-buffer (find-file-noselect (find-library-name library)))
+    (run-hooks 'find-function-after-hook)))
+
+(defun read-library-name ()
+  "Read and return a library name, defaulting to the one near point.
+
+A library name is the filename of an Emacs Lisp library located
+in a directory under `load-path' (or `find-function-source-path',
+if non-nil)."
+  (let* ((dirs (or find-function-source-path load-path))
+         (suffixes (find-library-suffixes))
+         (table (apply-partially 'locate-file-completion-table
+                                 dirs suffixes))
+         (def (if (eq (function-called-at-point) 'require)
+                  ;; `function-called-at-point' may return 'require
+                  ;; with `point' anywhere on this line.  So wrap the
+                  ;; `save-excursion' below in a `condition-case' to
+                  ;; avoid reporting a scan-error here.
+                  (condition-case nil
+                      (save-excursion
+                        (backward-up-list)
+                        (forward-char)
+                        (forward-sexp 2)
+                        (thing-at-point 'symbol))
+                    (error nil))
+                (thing-at-point 'symbol))))
+    (when (and def (not (test-completion def table)))
+      (setq def nil))
+    (completing-read (if def
+                         (format "Library name (default %s): " def)
+                       "Library name: ")
+                     table nil nil nil nil def)))
+
+;;;###autoload
+(defun find-library-other-window (library)
+  "Find the Emacs Lisp source of LIBRARY in another window.
+
+See `find-library' for more details."
+  (interactive (list (read-library-name)))
+  (prog1
+      (switch-to-buffer-other-window (find-file-noselect
+                                      (find-library-name library)))
+    (run-hooks 'find-function-after-hook)))
+
+;;;###autoload
+(defun find-library-other-frame (library)
+  "Find the Emacs Lisp source of LIBRARY in another frame.
+
+See `find-library' for more details."
+  (interactive (list (read-library-name)))
   (prog1
-      (funcall (if other-window
-                   'pop-to-buffer
-                 'pop-to-buffer-same-window)
-               (find-file-noselect (find-library-name library)))
+      (switch-to-buffer-other-frame (find-file-noselect
+                                     (find-library-name library)))
     (run-hooks 'find-function-after-hook)))
 
 ;;;###autoload