aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharles A. Roelli2017-05-20 14:41:53 +0300
committerEli Zaretskii2017-05-20 14:41:53 +0300
commit021430f4b48ceb43a443fe805cfe0b21e7829760 (patch)
tree17a047198c856e9b10c9cba4ed3d4f62fe3bb8e6
parent1cbbecee66617a232d6ed361f842128564599e70 (diff)
downloademacs-021430f4b48ceb43a443fe805cfe0b21e7829760.tar.gz
emacs-021430f4b48ceb43a443fe805cfe0b21e7829760.zip
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'.
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/emacs-lisp/find-func.el92
2 files changed, 60 insertions, 35 deletions
diff --git a/etc/NEWS b/etc/NEWS
index aa579b11c7a..2a4b7014d4e 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -356,6 +356,9 @@ use the local Emacs to edit remote files via Tramp. See the node
356** The new variable 'eval-expression-print-maximum-character' prevents 356** The new variable 'eval-expression-print-maximum-character' prevents
357large integers from being displayed as characters. 357large integers from being displayed as characters.
358 358
359** Two new commands for finding the source code of Emacs Lisp
360libraries: 'find-library-other-window' and 'find-library-other-frame'.
361
359 362
360* Editing Changes in Emacs 26.1 363* Editing Changes in Emacs 26.1
361 364
diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el
index d0acc147752..9b98f05ae81 100644
--- a/lisp/emacs-lisp/find-func.el
+++ b/lisp/emacs-lisp/find-func.el
@@ -271,43 +271,65 @@ TYPE should be nil to find a function, or `defvar' to find a variable."
271 (cons (current-buffer) (match-beginning 0)))) 271 (cons (current-buffer) (match-beginning 0))))
272 272
273;;;###autoload 273;;;###autoload
274(defun find-library (library &optional other-window) 274(defun find-library (library)
275 "Find the Emacs Lisp source of LIBRARY. 275 "Find the Emacs Lisp source of LIBRARY.
276LIBRARY should be a string (the name of the library). If the 276
277optional OTHER-WINDOW argument (i.e., the command argument) is 277Interactively, prompt for LIBRARY using the one at or near point."
278specified, pop to a different window before displaying the 278 (interactive (list (read-library-name)))
279buffer." 279 (prog1
280 (interactive 280 (switch-to-buffer (find-file-noselect (find-library-name library)))
281 (let* ((dirs (or find-function-source-path load-path)) 281 (run-hooks 'find-function-after-hook)))
282 (suffixes (find-library-suffixes)) 282
283 (table (apply-partially 'locate-file-completion-table 283(defun read-library-name ()
284 dirs suffixes)) 284 "Read and return a library name, defaulting to the one near point.
285 (def (if (eq (function-called-at-point) 'require) 285
286 ;; `function-called-at-point' may return 'require 286A library name is the filename of an Emacs Lisp library located
287 ;; with `point' anywhere on this line. So wrap the 287in a directory under `load-path' (or `find-function-source-path',
288 ;; `save-excursion' below in a `condition-case' to 288if non-nil)."
289 ;; avoid reporting a scan-error here. 289 (let* ((dirs (or find-function-source-path load-path))
290 (condition-case nil 290 (suffixes (find-library-suffixes))
291 (save-excursion 291 (table (apply-partially 'locate-file-completion-table
292 (backward-up-list) 292 dirs suffixes))
293 (forward-char) 293 (def (if (eq (function-called-at-point) 'require)
294 (forward-sexp 2) 294 ;; `function-called-at-point' may return 'require
295 (thing-at-point 'symbol)) 295 ;; with `point' anywhere on this line. So wrap the
296 (error nil)) 296 ;; `save-excursion' below in a `condition-case' to
297 (thing-at-point 'symbol)))) 297 ;; avoid reporting a scan-error here.
298 (when (and def (not (test-completion def table))) 298 (condition-case nil
299 (setq def nil)) 299 (save-excursion
300 (list 300 (backward-up-list)
301 (completing-read (if def 301 (forward-char)
302 (format "Library name (default %s): " def) 302 (forward-sexp 2)
303 "Library name: ") 303 (thing-at-point 'symbol))
304 table nil nil nil nil def) 304 (error nil))
305 current-prefix-arg))) 305 (thing-at-point 'symbol))))
306 (when (and def (not (test-completion def table)))
307 (setq def nil))
308 (completing-read (if def
309 (format "Library name (default %s): " def)
310 "Library name: ")
311 table nil nil nil nil def)))
312
313;;;###autoload
314(defun find-library-other-window (library)
315 "Find the Emacs Lisp source of LIBRARY in another window.
316
317See `find-library' for more details."
318 (interactive (list (read-library-name)))
319 (prog1
320 (switch-to-buffer-other-window (find-file-noselect
321 (find-library-name library)))
322 (run-hooks 'find-function-after-hook)))
323
324;;;###autoload
325(defun find-library-other-frame (library)
326 "Find the Emacs Lisp source of LIBRARY in another frame.
327
328See `find-library' for more details."
329 (interactive (list (read-library-name)))
306 (prog1 330 (prog1
307 (funcall (if other-window 331 (switch-to-buffer-other-frame (find-file-noselect
308 'pop-to-buffer 332 (find-library-name library)))
309 'pop-to-buffer-same-window)
310 (find-file-noselect (find-library-name library)))
311 (run-hooks 'find-function-after-hook))) 333 (run-hooks 'find-function-after-hook)))
312 334
313;;;###autoload 335;;;###autoload