diff options
author | Juri Linkov <juri@linkov.net> | 2020-10-31 21:38:26 +0200 |
---|---|---|
committer | Juri Linkov <juri@linkov.net> | 2020-10-31 21:39:28 +0200 |
commit | 80a87af1357492b16a057c1f31d0e9a8b501d7d0 (patch) | |
tree | 14e29a5f872e0edbb1e731482f50100bce2421bc | |
parent | 71795c6c4a61817f60e001702ed01785d2da3faf (diff) | |
download | emacs-80a87af1357492b16a057c1f31d0e9a8b501d7d0.tar.gz |
Improve goto-line in regard to narrowed buffers (bug#44294)
* lisp/simple.el (goto-line): Rewrite to first find the position
of the line where to go, then later don't widen the buffer
when the found position is still inside narrowed part of buffer.
* lisp/isearch.el (isearch-message-prefix): Warn about narrowed buffer
in case of no more matches found.
-rw-r--r-- | lisp/isearch.el | 2 | ||||
-rw-r--r-- | lisp/simple.el | 26 |
2 files changed, 16 insertions, 12 deletions
diff --git a/lisp/isearch.el b/lisp/isearch.el index c3d5ff2d313..245bf452b1f 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -3262,6 +3262,8 @@ the word mode." (< (point) isearch-opoint))) "over") (if isearch-wrapped "wrapped ") + (if (and (not isearch-success) (buffer-narrowed-p) widen-automatically) + "narrowed-buffer " "") (if (and (not isearch-success) (not isearch-case-fold-search)) "case-sensitive ") (let ((prefix "")) diff --git a/lisp/simple.el b/lisp/simple.el index d871be104cf..e96c7c9a6ea 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -1344,18 +1344,20 @@ rather than line counts." ;; Leave mark at previous position (or (region-active-p) (push-mark)) ;; Move to the specified line number in that buffer. - (if (and (not relative) (not widen-automatically)) - (save-restriction - (widen) - (goto-char (point-min)) - (if (eq selective-display t) - (re-search-forward "[\n\C-m]" nil 'end (1- line)) - (forward-line (1- line)))) - (unless relative (widen)) - (goto-char (point-min)) - (if (eq selective-display t) - (re-search-forward "[\n\C-m]" nil 'end (1- line)) - (forward-line (1- line))))) + (let ((pos (save-restriction + (unless relative (widen)) + (goto-char (point-min)) + (if (eq selective-display t) + (re-search-forward "[\n\C-m]" nil 'end (1- line)) + (forward-line (1- line))) + (point)))) + (when (and (not relative) + (buffer-narrowed-p) + widen-automatically + ;; Position is outside narrowed part of buffer + (or (> (point-min) pos) (> pos (point-max)))) + (widen)) + (goto-char pos))) (defun goto-line-relative (line &optional buffer) "Go to LINE, counting from line at (point-min). |