Commit 021430f4 authored by Charles A. Roelli's avatar Charles A. Roelli Committed by Eli Zaretskii

New commands: find-library-other-window, find-library-other-frame

* 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'.
parent 1cbbecee
...@@ -356,6 +356,9 @@ use the local Emacs to edit remote files via Tramp. See the node ...@@ -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 ** The new variable 'eval-expression-print-maximum-character' prevents
large integers from being displayed as characters. 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'.
* Editing Changes in Emacs 26.1 * Editing Changes in Emacs 26.1
......
...@@ -271,43 +271,65 @@ TYPE should be nil to find a function, or `defvar' to find a variable." ...@@ -271,43 +271,65 @@ TYPE should be nil to find a function, or `defvar' to find a variable."
(cons (current-buffer) (match-beginning 0)))) (cons (current-buffer) (match-beginning 0))))
;;;###autoload ;;;###autoload
(defun find-library (library &optional other-window) (defun find-library (library)
"Find the Emacs Lisp source of 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 Interactively, prompt for LIBRARY using the one at or near point."
specified, pop to a different window before displaying the (interactive (list (read-library-name)))
buffer." (prog1
(interactive (switch-to-buffer (find-file-noselect (find-library-name library)))
(let* ((dirs (or find-function-source-path load-path)) (run-hooks 'find-function-after-hook)))
(suffixes (find-library-suffixes))
(table (apply-partially 'locate-file-completion-table (defun read-library-name ()
dirs suffixes)) "Read and return a library name, defaulting to the one near point.
(def (if (eq (function-called-at-point) 'require)
;; `function-called-at-point' may return 'require A library name is the filename of an Emacs Lisp library located
;; with `point' anywhere on this line. So wrap the in a directory under `load-path' (or `find-function-source-path',
;; `save-excursion' below in a `condition-case' to if non-nil)."
;; avoid reporting a scan-error here. (let* ((dirs (or find-function-source-path load-path))
(condition-case nil (suffixes (find-library-suffixes))
(save-excursion (table (apply-partially 'locate-file-completion-table
(backward-up-list) dirs suffixes))
(forward-char) (def (if (eq (function-called-at-point) 'require)
(forward-sexp 2) ;; `function-called-at-point' may return 'require
(thing-at-point 'symbol)) ;; with `point' anywhere on this line. So wrap the
(error nil)) ;; `save-excursion' below in a `condition-case' to
(thing-at-point 'symbol)))) ;; avoid reporting a scan-error here.
(when (and def (not (test-completion def table))) (condition-case nil
(setq def nil)) (save-excursion
(list (backward-up-list)
(completing-read (if def (forward-char)
(format "Library name (default %s): " def) (forward-sexp 2)
"Library name: ") (thing-at-point 'symbol))
table nil nil nil nil def) (error nil))
current-prefix-arg))) (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 (prog1
(funcall (if other-window (switch-to-buffer-other-frame (find-file-noselect
'pop-to-buffer (find-library-name library)))
'pop-to-buffer-same-window)
(find-file-noselect (find-library-name library)))
(run-hooks 'find-function-after-hook))) (run-hooks 'find-function-after-hook)))
;;;###autoload ;;;###autoload
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment