1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

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.
This commit is contained in:
Wilfred Hughes 2017-12-10 13:34:06 +00:00
parent ab203e36d5
commit abd18254ae
2 changed files with 56 additions and 35 deletions

View file

@ -368,6 +368,8 @@ The search is done in the source for library LIBRARY."
(concat "\\\\?"
(regexp-quote (symbol-name symbol))))))
(case-fold-search))
(save-restriction
(widen)
(with-syntax-table emacs-lisp-mode-syntax-table
(goto-char (point-min))
(if (if (functionp regexp)
@ -389,7 +391,7 @@ The search is done in the source for library LIBRARY."
(progn
(beginning-of-line)
(cons (current-buffer) (point)))
(cons (current-buffer) nil))))))))
(cons (current-buffer) nil)))))))))
(defun find-function-library (function &optional lisp-only verbose)
"Return the pair (ORIG-FUNCTION . LIBRARY) for FUNCTION.

View file

@ -203,12 +203,18 @@ The format is (FUNCTION ARGS...).")
(help-C-file-name (indirect-function fun) 'fun)))
;; Don't use find-function-noselect because it follows
;; aliases (which fails for built-in functions).
(let ((location
(find-function-search-for-symbol fun type file)))
(let* ((location
(find-function-search-for-symbol fun type file))
(position (cdr location)))
(pop-to-buffer (car location))
(run-hooks 'find-function-after-hook)
(if (cdr location)
(goto-char (cdr location))
(if position
(progn
;; Widen the buffer if necessary to go to this position.
(when (or (< position (point-min))
(> position (point-max)))
(widen))
(goto-char position))
(message "Unable to find location in file")))))
'help-echo (purecopy "mouse-2, RET: find function's definition"))
@ -219,6 +225,7 @@ The format is (FUNCTION ARGS...).")
(if (and file (file-readable-p file))
(progn
(pop-to-buffer (find-file-noselect file))
(widen)
(goto-char (point-min))
(if (re-search-forward
(format "^[ \t]*(\\(cl-\\)?define-compiler-macro[ \t]+%s"
@ -234,11 +241,17 @@ The format is (FUNCTION ARGS...).")
'help-function (lambda (var &optional file)
(when (eq file 'C-source)
(setq file (help-C-file-name var 'var)))
(let ((location (find-variable-noselect var file)))
(let* ((location (find-variable-noselect var file))
(position (cdr location)))
(pop-to-buffer (car location))
(run-hooks 'find-function-after-hook)
(if (cdr location)
(goto-char (cdr location))
(if position
(progn
;; Widen the buffer if necessary to go to this position.
(when (or (< position (point-min))
(> position (point-max)))
(widen))
(goto-char position))
(message "Unable to find location in file"))))
'help-echo (purecopy "mouse-2, RET: find variable's definition"))
@ -248,11 +261,17 @@ The format is (FUNCTION ARGS...).")
(require 'find-func)
;; Don't use find-function-noselect because it follows
;; aliases (which fails for built-in functions).
(let ((location
(find-function-search-for-symbol fun 'defface file)))
(let* ((location
(find-function-search-for-symbol fun 'defface file))
(position (cdr location)))
(pop-to-buffer (car location))
(if (cdr location)
(goto-char (cdr location))
(if position
(progn
;; Widen the buffer if necessary to go to this position.
(when (or (< position (point-min))
(> position (point-max)))
(widen))
(goto-char position))
(message "Unable to find location in file"))))
'help-echo (purecopy "mouse-2, RET: find face's definition"))