summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuri Linkov <juri@linkov.net>2020-10-31 21:38:26 +0200
committerJuri Linkov <juri@linkov.net>2020-10-31 21:39:28 +0200
commit80a87af1357492b16a057c1f31d0e9a8b501d7d0 (patch)
tree14e29a5f872e0edbb1e731482f50100bce2421bc
parent71795c6c4a61817f60e001702ed01785d2da3faf (diff)
downloademacs-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.el2
-rw-r--r--lisp/simple.el26
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).