From 47e52ab86ff45225388bff458189f5311153eefa Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 3 Jul 2025 15:42:33 +0200 Subject: [PATCH] feat(:term): move cursor to prompt on self-insert-command It's better UX than spewing unhelpful read-only errors. --- lisp/doom-ui.el | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lisp/doom-ui.el b/lisp/doom-ui.el index b93cfda64..de45d7f09 100644 --- a/lisp/doom-ui.el +++ b/lisp/doom-ui.el @@ -390,7 +390,20 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original ;; Protect fence (newline of input, just before output). (when (eq (char-before start-marker) ?\n) (remove-text-properties (1- start-marker) start-marker '(rear-nonsticky)) - (add-text-properties (1- start-marker) start-marker '(read-only t)))))))) + (add-text-properties (1- start-marker) start-marker '(read-only t))))))) + + ;; UX: If the user is anywhere but the last prompt, typing should move them + ;; there instead of unhelpfully spew read-only errors at them. + (defun doom--comint-move-cursor-to-prompt-h () + (and (eq this-command 'self-insert-command) + comint-last-prompt + (> (cdr comint-last-prompt) (point)) + (goto-char (cdr comint-last-prompt)))) + + (add-hook! 'comint-mode-hook + (defun doom--comint-init-move-cursor-to-prompt-h () + (add-hook 'pre-command-hook #'doom--comint-move-cursor-to-prompt-h + nil t)))) (after! compile