From 0ee966dcb0d40ee347c1a8ea1a50609aa3aa1e28 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Fri, 22 Jan 2021 21:16:03 +0100 Subject: [PATCH] SLY: Fix prompt navigation. --- .emacs.d/lisp/init-sly.el | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/.emacs.d/lisp/init-sly.el b/.emacs.d/lisp/init-sly.el index 5600b4f1..36d5b9b1 100644 --- a/.emacs.d/lisp/init-sly.el +++ b/.emacs.d/lisp/init-sly.el @@ -272,22 +272,35 @@ returns a string." #'ambrevar/sly-new-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 () "Go to the beginning of the previous REPL prompt." (interactive) - ;; This has two wrinkles around the first prompt: (1) when going to - ;; the first prompt it leaves point at column 0 (1) when called from - ;; frist prompt goes to beginning of buffer. The correct fix is to - ;; patch comint.el's comint-next-prompt and comint-previous-prompt - ;; anyway... - (let* ((inhibit-field-text-motion t) - (pos (previous-single-char-property-change - (previous-single-char-property-change (point) - 'sly-mrepl--prompt) - 'sly-mrepl--prompt))) - (goto-char pos) - (goto-char (line-beginning-position))) - (end-of-line)) + (cl-flet ((go-back () + (goto-char + (previous-single-char-property-change + (point) 'sly-mrepl--prompt)))) + (if (ambrevar/sly-prompt-line-p) + (progn + (unless (ambrevar/sly-end-of-prompt-p) + (goto-char (line-beginning-position))) + (go-back) + (go-back)) + (go-back)) + (unless (ambrevar/sly-prompt-line-p) + ;; 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 () "Go to the beginning of the next REPL prompt."