aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJim Porter2024-06-13 21:26:53 -0700
committerJim Porter2024-06-20 19:01:20 -0700
commite22b072423a6764632328d4e0fecc06a6e7efe9b (patch)
treee1280eda53f6731f0c6af09580cbef6cd5d928f4 /lisp
parent1a55e957ae57ec32ae960eabdb170b5b427392d4 (diff)
downloademacs-e22b072423a6764632328d4e0fecc06a6e7efe9b.tar.gz
emacs-e22b072423a6764632328d4e0fecc06a6e7efe9b.zip
Ensure navigating by paragraphs in Eshell stops at prompts and paragraphs
The previous implementation in 6ae2b74ed20 only stopped at prompts, which isn't the right behavior (bug#61545). * lisp/eshell/em-prompt.el (eshell-forward-paragraph) (eshell-backward-paragraph): Reimplement to handle prompts and paragraphs (the latter by calling the original 'forward-paragraph'). * test/lisp/eshell/em-prompt-tests.el (em-prompt-test/next-previous-prompt/multiline): Rename. (em-prompt-test/forward-backward-paragraph-1): New function. (em-prompt-test/forward-backward-paragraph) (em-prompt-test/forward-backward-paragraph/multiline): New tests.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/eshell/em-prompt.el32
1 files changed, 27 insertions, 5 deletions
diff --git a/lisp/eshell/em-prompt.el b/lisp/eshell/em-prompt.el
index b6556d29544..7de2bd4dc21 100644
--- a/lisp/eshell/em-prompt.el
+++ b/lisp/eshell/em-prompt.el
@@ -167,17 +167,39 @@ negative, find the Nth next match."
167 167
168(defun eshell-forward-paragraph (&optional n) 168(defun eshell-forward-paragraph (&optional n)
169 "Move to the beginning of the Nth next prompt in the buffer. 169 "Move to the beginning of the Nth next prompt in the buffer.
170Like `forward-paragraph', but navigates using fields." 170Like `forward-paragraph', but also stops at the beginning of each prompt."
171 (interactive "p") 171 (interactive "p")
172 (eshell-next-prompt n) 172 (unless n (setq n 1))
173 (goto-char (field-beginning (point) t))) 173 (let (;; We'll handle the "paragraph" starts ourselves.
174 (paragraph-start regexp-unmatchable)
175 (inhibit-field-text-motion t))
176 (cond
177 ((> n 0)
178 (while (and (> n 0) (< (point) (point-max)))
179 (let ((next-paragraph (save-excursion (forward-paragraph) (point)))
180 (next-prompt (save-excursion
181 (if-let ((match (text-property-search-forward
182 'field 'prompt t t)))
183 (prop-match-beginning match)
184 (point-max)))))
185 (goto-char (min next-paragraph next-prompt)))
186 (setq n (1- n))))
187 ((< n 0)
188 (while (and (< n 0) (> (point) (point-min)))
189 (let ((prev-paragraph (save-excursion (backward-paragraph) (point)))
190 (prev-prompt (save-excursion
191 (if (text-property-search-backward
192 'field 'prompt t)
193 (point)
194 (point-min)))))
195 (goto-char (max prev-paragraph prev-prompt)))
196 (setq n (1+ n)))))))
174 197
175(defun eshell-backward-paragraph (&optional n) 198(defun eshell-backward-paragraph (&optional n)
176 "Move to the beginning of the Nth previous prompt in the buffer. 199 "Move to the beginning of the Nth previous prompt in the buffer.
177Like `backward-paragraph', but navigates using fields." 200Like `backward-paragraph', but navigates using fields."
178 (interactive "p") 201 (interactive "p")
179 (eshell-previous-prompt n) 202 (eshell-forward-paragraph (- (or n 1))))
180 (goto-char (field-beginning (point) t)))
181 203
182(defun eshell-next-prompt (&optional n) 204(defun eshell-next-prompt (&optional n)
183 "Move to end of Nth next prompt in the buffer." 205 "Move to end of Nth next prompt in the buffer."