[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 80a87af 2/2: Improve goto-line in regard to narrowed buffers (bug
From: |
Juri Linkov |
Subject: |
master 80a87af 2/2: Improve goto-line in regard to narrowed buffers (bug#44294) |
Date: |
Sat, 31 Oct 2020 15:40:28 -0400 (EDT) |
branch: master
commit 80a87af1357492b16a057c1f31d0e9a8b501d7d0
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>
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.
---
lisp/isearch.el | 2 ++
lisp/simple.el | 26 ++++++++++++++------------
2 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/lisp/isearch.el b/lisp/isearch.el
index c3d5ff2..245bf45 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 d871be1..e96c7c9 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).