SLY: Fix prompt navigation.

master
Pierre Neidhardt 2021-01-22 21:16:03 +01:00
parent 9baebf4073
commit 0ee966dcb0
1 changed files with 26 additions and 13 deletions

View File

@ -272,22 +272,35 @@ returns a string."
#'ambrevar/sly-new-prompt) #'ambrevar/sly-new-prompt)
(advice-add 'sly-mrepl--insert-prompt :around #'ambrevar/sly-prepare-prompt))) (advice-add 'sly-mrepl--insert-prompt :around #'ambrevar/sly-prepare-prompt)))
(defun ambrevar/sly-end-of-prompt-p ()
(and (not (= (point) (point-min)))
(not (get-text-property (point) 'sly-mrepl--prompt))
(get-text-property (1- (point)) 'sly-mrepl--prompt)))
(defun ambrevar/sly-prompt-line-p ()
(or (ambrevar/sly-end-of-prompt-p)
(save-excursion
(goto-char (line-beginning-position))
(ambrevar/sly-end-of-prompt-p))))
(defun ambrevar/sly-mrepl-previous-prompt () (defun ambrevar/sly-mrepl-previous-prompt ()
"Go to the beginning of the previous REPL prompt." "Go to the beginning of the previous REPL prompt."
(interactive) (interactive)
;; This has two wrinkles around the first prompt: (1) when going to (cl-flet ((go-back ()
;; the first prompt it leaves point at column 0 (1) when called from (goto-char
;; frist prompt goes to beginning of buffer. The correct fix is to (previous-single-char-property-change
;; patch comint.el's comint-next-prompt and comint-previous-prompt (point) 'sly-mrepl--prompt))))
;; anyway... (if (ambrevar/sly-prompt-line-p)
(let* ((inhibit-field-text-motion t) (progn
(pos (previous-single-char-property-change (unless (ambrevar/sly-end-of-prompt-p)
(previous-single-char-property-change (point) (goto-char (line-beginning-position)))
'sly-mrepl--prompt) (go-back)
'sly-mrepl--prompt))) (go-back))
(goto-char pos) (go-back))
(goto-char (line-beginning-position))) (unless (ambrevar/sly-prompt-line-p)
(end-of-line)) ;; We did not end up on a prompt, means we are above the first prompt.
;; Return back.
(ambrevar/sly-mrepl-next-prompt))))
(defun ambrevar/sly-mrepl-next-prompt () (defun ambrevar/sly-mrepl-next-prompt ()
"Go to the beginning of the next REPL prompt." "Go to the beginning of the next REPL prompt."