summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2017-12-10 13:34:06 +0000
committerWilfred Hughes <me@wilfred.me.uk>2017-12-10 14:52:54 +0000
commitabd18254aec76b26e86ae27e91d2c916ec20cc46 (patch)
tree9d346b42760ea3d0bec8224481d09f16a9df79ad /lisp/emacs-lisp
parentab203e36d5f84a99b6d4b04f1a22ba028be750e3 (diff)
downloademacs-abd18254aec76b26e86ae27e91d2c916ec20cc46.tar.gz
emacs-abd18254aec76b26e86ae27e91d2c916ec20cc46.tar.bz2
emacs-abd18254aec76b26e86ae27e91d2c916ec20cc46.zip
Ensure that we can find definitions when buffer is narrowed
find-function-search-for-symbol will reuse the existing buffer if we've already opened the file that contains this symbol. However, if the user has narrowed that buffer, we can't find definitions outside the narrowed area. Instead, search the whole file to find definitions, and teach the help buttons to widen if necessary. * lisp/emacs-lisp/find-func.el (find-function-search-for-symbol): Search the whole buffer for the target symbol. * lisp/help-mode.el: Help buttons now widen the target buffer, if narrowing is in effect and the target position is not in that range.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/find-func.el46
1 files changed, 24 insertions, 22 deletions
diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el
index 29c42f36938..84cc8bc9b72 100644
--- a/lisp/emacs-lisp/find-func.el
+++ b/lisp/emacs-lisp/find-func.el
@@ -368,28 +368,30 @@ The search is done in the source for library LIBRARY."
(concat "\\\\?"
(regexp-quote (symbol-name symbol))))))
(case-fold-search))
- (with-syntax-table emacs-lisp-mode-syntax-table
- (goto-char (point-min))
- (if (if (functionp regexp)
- (funcall regexp symbol)
- (or (re-search-forward regexp nil t)
- ;; `regexp' matches definitions using known forms like
- ;; `defun', or `defvar'. But some functions/variables
- ;; are defined using special macros (or functions), so
- ;; if `regexp' can't find the definition, we look for
- ;; something of the form "(SOMETHING <symbol> ...)".
- ;; This fails to distinguish function definitions from
- ;; variable declarations (or even uses thereof), but is
- ;; a good pragmatic fallback.
- (re-search-forward
- (concat "^([^ ]+" find-function-space-re "['(]?"
- (regexp-quote (symbol-name symbol))
- "\\_>")
- nil t)))
- (progn
- (beginning-of-line)
- (cons (current-buffer) (point)))
- (cons (current-buffer) nil))))))))
+ (save-restriction
+ (widen)
+ (with-syntax-table emacs-lisp-mode-syntax-table
+ (goto-char (point-min))
+ (if (if (functionp regexp)
+ (funcall regexp symbol)
+ (or (re-search-forward regexp nil t)
+ ;; `regexp' matches definitions using known forms like
+ ;; `defun', or `defvar'. But some functions/variables
+ ;; are defined using special macros (or functions), so
+ ;; if `regexp' can't find the definition, we look for
+ ;; something of the form "(SOMETHING <symbol> ...)".
+ ;; This fails to distinguish function definitions from
+ ;; variable declarations (or even uses thereof), but is
+ ;; a good pragmatic fallback.
+ (re-search-forward
+ (concat "^([^ ]+" find-function-space-re "['(]?"
+ (regexp-quote (symbol-name symbol))
+ "\\_>")
+ nil t)))
+ (progn
+ (beginning-of-line)
+ (cons (current-buffer) (point)))
+ (cons (current-buffer) nil)))))))))
(defun find-function-library (function &optional lisp-only verbose)
"Return the pair (ORIG-FUNCTION . LIBRARY) for FUNCTION.