From: Juri Linkov Date: Sat, 31 Oct 2020 19:38:26 +0000 (+0200) Subject: Improve goto-line in regard to narrowed buffers (bug#44294) X-Git-Tag: emacs-28.0.90~5305 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=80a87af1357492b16a057c1f31d0e9a8b501d7d0;p=emacs.git 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. --- 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).