Subject: other-window/frame versions of find-library
From: "Charles A. Roelli" <[email-masked]>
To: [email-masked]
Date: Sat, 29 Apr 2017 21:46:22 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Attached is a patch to add other-window/frames version of the 
`find-library' command.

BTW, after I added the two new commands and rebuilt Emacs (with just 
`make'), I could not complete to them with `M-x find-library- TAB'.  I 
could only do this after loading the `find-func' library that contains 
them.  So I ran `make bootstrap' instead and then I could complete to 
them as expected.  I guess this means the autoloads had not been updated 
with just `make'... which command should I have run?  Bootstrapping 
takes awhile.
From 9e4f4ba788635240b84ccdaa336760aacaa93417 Mon Sep 17 00:00:00 2001
From: Charles A. Roelli <[email-masked]>
Date: Sat, 29 Apr 2017 19:40:11 +0200
Subject: [PATCH] find-library-other-window, find-library-other-frame: New
 commands

* lisp/emacs-lisp/find-func.el (find-library-other-window)
(find-library-other-frame): New commands to complement the existing
`find-library' command.
(find-library-read): New function to read a library name.
(find-function-do-it): Fix indentation.
; * etc/NEWS (Changes in Emacs 26.1): Mention the new commands.
---
 etc/NEWS                     |    3 +
 lisp/emacs-lisp/find-func.el |  100 +++++++++++++++++++++++++-----------------
 2 files changed, 63 insertions(+), 40 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 9d4c72d..0425996 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -340,6 +340,9 @@ want to reverse the direction of the scroll, customize
 ** Emacsclient has a new option -u/--suppress-output.  The option
 suppresses display of return values from the server process.
 
+** Two new commands 'find-library-other-window' and
+'find-library-other-frame'.
+
 
 * Editing Changes in Emacs 26.1
 
diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el
index d0acc14..1aea30c 100644
--- a/lisp/emacs-lisp/find-func.el
+++ b/lisp/emacs-lisp/find-func.el
@@ -271,42 +271,62 @@ find-function-C-source
     (cons (current-buffer) (match-beginning 0))))
 
 ;;;###autoload
-(defun find-library (library &optional other-window)
-  "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)))
+(defun find-library (library)
+  "Find the Emacs Lisp source of the LIBRARY near point.
+
+LIBRARY should be a string (the name of the library)."
+  (interactive (find-library-read))
+  (prog1
+      (funcall 'switch-to-buffer
+               (find-file-noselect (find-library-name library)))
+    (run-hooks 'find-function-after-hook)))
+
+(defun find-library-read ()
+  "Read and return a library name, defaulting to the one near point."
+  (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))))
+
+;;;###autoload
+(defun find-library-other-window (library)
+  "Find, in another window, the file defining LIBRARY at or near point.
+
+See `find-library' for more details."
+  (interactive (find-library-read))
+  (prog1
+      (funcall '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, in another frame, the file defining LIBRARY at or near point.
+
+See `find-library' for more details."
+  (interactive (find-library-read))
   (prog1
-      (funcall (if other-window
-                   'pop-to-buffer
-                 'pop-to-buffer-same-window)
+      (funcall 'switch-to-buffer-other-frame
                (find-file-noselect (find-library-name library)))
     (run-hooks 'find-function-after-hook)))
 
@@ -470,11 +490,11 @@ find-function-do-it
 
 Set mark before moving, if the buffer already existed."
   (let* ((orig-point (point))
-	(orig-buffers (buffer-list))
-	(buffer-point (save-excursion
-			(find-definition-noselect symbol type)))
-	(new-buf (car buffer-point))
-	(new-point (cdr buffer-point)))
+         (orig-buffers (buffer-list))
+         (buffer-point (save-excursion
+                         (find-definition-noselect symbol type)))
+         (new-buf (car buffer-point))
+         (new-point (cdr buffer-point)))
     (when buffer-point
       (when (memq new-buf orig-buffers)
 	(push-mark orig-point))
-- 
1.7.4.4