diff options
Diffstat (limited to 'lisp/emacs-lisp/find-func.el')
-rw-r--r-- | lisp/emacs-lisp/find-func.el | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el index 2022d3ab7d4..efae0d1cdc8 100644 --- a/lisp/emacs-lisp/find-func.el +++ b/lisp/emacs-lisp/find-func.el @@ -10,10 +10,10 @@ ;; This file is part of GNU Emacs. -;; GNU Emacs is free software; you can redistribute it and/or modify +;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 3, or (at your option) -;; any later version. +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -21,9 +21,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -;; Boston, MA 02110-1301, USA. +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. ;;; Commentary: ;; @@ -46,8 +44,6 @@ ;;; Code: -(require 'loadhist) - ;;; User variables: (defgroup find-function nil @@ -152,10 +148,14 @@ See the functions `find-function' and `find-variable'." ;; the same name. (if (string-match "\\.el\\(c\\(\\..*\\)?\\)\\'" library) (setq library (replace-match "" t t library))) - (or (locate-file library - (or find-function-source-path load-path) - (append (find-library-suffixes) load-file-rep-suffixes)) - (error "Can't find library %s" library))) + (or + (locate-file library + (or find-function-source-path load-path) + (find-library-suffixes)) + (locate-file library + (or find-function-source-path load-path) + load-file-rep-suffixes) + (error "Can't find library %s" library))) (defvar find-function-C-source-directory (let ((dir (expand-file-name "src" source-directory))) @@ -195,21 +195,31 @@ TYPE should be nil to find a function, or `defvar' to find a variable." (defun find-library (library) "Find the elisp source of LIBRARY." (interactive - (let* ((path (cons (or find-function-source-path load-path) - (find-library-suffixes))) + (let* ((dirs (or find-function-source-path load-path)) + (suffixes (find-library-suffixes)) (def (if (eq (function-called-at-point) 'require) - (save-excursion - (backward-up-list) - (forward-char) - (backward-sexp -2) - (thing-at-point 'symbol)) + ;; `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 def - (setq def (and (locate-file-completion def path 'test) def))) + (setq def (and (locate-file-completion-table + dirs suffixes def nil 'lambda) + def))) (list (completing-read (if def (format "Library name (default %s): " def) "Library name: ") - 'locate-file-completion path nil nil nil def)))) + (apply-partially 'locate-file-completion-table + dirs suffixes) + nil nil nil nil def)))) (let ((buf (find-file-noselect (find-library-name library)))) (condition-case nil (switch-to-buffer buf) (error (pop-to-buffer buf))))) |