Add shell prompt navigation commands

* eat.el (eat--post-prompt): Add special text property on the
last character of shell prompt.
* eat.el (eat-previous-shell-prompt, eat-next-shell-prompt):
New command.
* eat.el (eat-mode-map): Bind 'eat-previous-shell-prompt' and
'eat-next-shell-prompt' to 'C-c C-p' and 'C-c C-n'
respectively.
This commit is contained in:
Akib Azmain Turja 2022-12-06 22:03:33 +06:00
parent a04999011f
commit 2c6afa4dc0
No known key found for this signature in database
GPG key ID: 5535FCF54D88616B

41
eat.el
View file

@ -4279,7 +4279,10 @@ If HOST isn't the host Emacs is running on, don't do anything."
(list 'eat--before-string before-str
'eat--shell-prompt-mark-id identifier
'eat--shell-prompt-mark-overlay ov))
(push ov eat--shell-prompt-mark-overlays)))
(push ov eat--shell-prompt-mark-overlays))
;; Put a text property to allow previous or next prompts.
(put-text-property (1- (point)) (point)
'eat--shell-prompt-end t))
(setq eat--shell-prompt-begin nil)))))
(defun eat--update-shell-prompt-mark-overlays (buffer)
@ -4351,6 +4354,40 @@ BUFFER is the terminal buffer."
;; We'll update the mark later when the prompt appears.
(setq eat--shell-command-status code)))
(defun eat-previous-shell-prompt (&optional arg)
"Go to the previous shell prompt.
When numeric prefix argument, ARG, is given, go to ARGth previous
shell prompt."
(interactive "p")
(dotimes (_ (or arg 1))
(let ((previous (previous-single-property-change
(point) 'eat--shell-prompt-end)))
(goto-char (or previous (point-min)))
(when (get-text-property (point) 'eat--shell-prompt-end)
(setq previous (previous-single-property-change
(point) 'eat--shell-prompt-end))
(goto-char (or previous (point-min))))
(unless previous
(user-error "No previous prompt")))))
(defun eat-next-shell-prompt (&optional arg)
"Go to the next shell prompt.
When numeric prefix argument, ARG, is given, go to ARGth next shell
prompt."
(interactive "p")
(dotimes (_ (or arg 1))
(let ((next (next-single-property-change
(point) 'eat--shell-prompt-end)))
(goto-char (or next (point-max)))
(when (get-text-property (point) 'eat--shell-prompt-end)
(goto-char (or (next-single-property-change
(point) 'eat--shell-prompt-end)
(point-max))))
(unless next
(user-error "No next prompt")))))
;;;;; Input.
@ -4548,6 +4585,8 @@ ARG is passed to `yank-pop', which see."
(define-key map [?\C-c ?\M-d] #'eat-char-mode)
(define-key map [?\C-c ?\C-j] #'eat-semi-char-mode)
(define-key map [?\C-c ?\C-k] #'eat-kill-process)
(define-key map [?\C-c ?\C-p] #'eat-previous-shell-prompt)
(define-key map [?\C-c ?\C-n] #'eat-next-shell-prompt)
map)
"Keymap for Eat mode.")