fix(:term): ensure process-buffer is current

This commit is contained in:
DennieTeMolder
2025-07-14 14:39:22 +02:00
committed by Henrik Lissner
parent ed9190ef00
commit cf278cab55

View File

@@ -356,13 +356,14 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
(add-hook 'comint-exec-hook #'buffer-disable-undo) (add-hook 'comint-exec-hook #'buffer-disable-undo)
(defadvice! doom--comint-enable-undo-a (process _string) (defadvice! doom--comint-enable-undo-a (process _string)
:after #'comint-output-filter :after #'comint-output-filter
(with-current-buffer (process-buffer process)
(let ((start-marker comint-last-output-start)) (let ((start-marker comint-last-output-start))
(when (and (< start-marker (when (and (< start-marker
(or (if process (process-mark process)) (or (if process (process-mark process))
(point-max-marker))) (point-max-marker)))
(eq (char-before start-marker) ?\n)) ;; Account for some of the IELMs wilderness. (eq (char-before start-marker) ?\n)) ;; Account for some of the IELMs wilderness.
(buffer-enable-undo) (buffer-enable-undo)
(setq buffer-undo-list nil)))) (setq buffer-undo-list nil)))))
;; Protect prompts from accidental modifications. ;; Protect prompts from accidental modifications.
(setq-default comint-prompt-read-only t) (setq-default comint-prompt-read-only t)
@@ -375,6 +376,7 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
(defadvice! doom--comint-protect-output-in-visual-modes-a (process _string) (defadvice! doom--comint-protect-output-in-visual-modes-a (process _string)
:after #'comint-output-filter :after #'comint-output-filter
;; Adapted from https://github.com/michalrus/dotfiles/blob/c4421e361400c4184ea90a021254766372a1f301/.emacs.d/init.d/040-terminal.el.symlink#L33-L49 ;; Adapted from https://github.com/michalrus/dotfiles/blob/c4421e361400c4184ea90a021254766372a1f301/.emacs.d/init.d/040-terminal.el.symlink#L33-L49
(with-current-buffer (process-buffer process)
(let* ((start-marker comint-last-output-start) (let* ((start-marker comint-last-output-start)
(end-marker (or (if process (process-mark process)) (end-marker (or (if process (process-mark process))
(point-max-marker)))) (point-max-marker))))
@@ -390,7 +392,7 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
;; Protect fence (newline of input, just before output). ;; Protect fence (newline of input, just before output).
(when (eq (char-before start-marker) ?\n) (when (eq (char-before start-marker) ?\n)
(remove-text-properties (1- start-marker) start-marker '(rear-nonsticky)) (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 ;; UX: If the user is anywhere but the last prompt, typing should move them
;; there instead of unhelpfully spew read-only errors at them. ;; there instead of unhelpfully spew read-only errors at them.