From 83e3ed651dca46214855552aa062cfbde019b04a Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Thu, 17 Oct 2024 14:30:31 -0700 Subject: [PATCH] ; Mark interactive Eshell output as such after inserting into the buffer This avoids adding the "output" text properties to strings that may live past the call to 'eshell-interactive-filter'. * lisp/eshell/esh-mode.el (eshell-interactive-output-filter): New function... (eshell-interactive-print): ... call it. (eshell-interactive-filter): Update docstring. * lisp/eshell/esh-proc.el (eshell-interactive-process-filter) (eshell-sentinel): Call 'eshell-interactive-output-filter'. --- lisp/eshell/esh-mode.el | 16 +++++++++++++--- lisp/eshell/esh-proc.el | 12 +++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el index 34ce82cfbc4..ead5a20bec8 100644 --- a/lisp/eshell/esh-mode.el +++ b/lisp/eshell/esh-mode.el @@ -530,8 +530,7 @@ Putting this function on `eshell-pre-command-hook' will mimic Plan 9's (defun eshell-interactive-print (string) "Print STRING to the eshell display buffer." (when string - (eshell--mark-as-output 0 (length string) string) - (eshell-interactive-filter nil string))) + (eshell-interactive-output-filter nil string))) (defsubst eshell-begin-on-new-line () "This function outputs a newline if not at beginning of line." @@ -685,7 +684,7 @@ newline." (custom-add-option 'eshell-input-filter-functions 'eshell-kill-new) (defun eshell-interactive-filter (buffer string) - "Send output (STRING) to the interactive display, using BUFFER. + "Send STRING to the interactive display, using BUFFER. This is done after all necessary filtering has been done." (unless buffer (setq buffer (current-buffer))) @@ -725,6 +724,17 @@ This is done after all necessary filtering has been done." (goto-char opoint) (eshell-run-output-filters)))))) +(defun eshell-interactive-output-filter (buffer string) + "Send STRING to the interactive display as command output, using BUFFER. +This is like `eshell-interactive-filter', but marks the inserted string +as command output (see `eshell--mark-as-output')." + (let ((eshell-output-filter-functions + (cons (lambda () + (eshell--mark-as-output eshell-last-output-start + eshell-last-output-end)) + eshell-output-filter-functions))) + (eshell-interactive-filter buffer string))) + (defun eshell-run-output-filters () "Run the `eshell-output-filter-functions' on the current output." (save-current-buffer diff --git a/lisp/eshell/esh-proc.el b/lisp/eshell/esh-proc.el index b579a93e14c..87c95d39603 100644 --- a/lisp/eshell/esh-proc.el +++ b/lisp/eshell/esh-proc.el @@ -128,7 +128,7 @@ To add or remove elements of this list, see (declare-function eshell-reset "esh-mode" (&optional no-hooks)) (declare-function eshell-send-eof-to-process "esh-mode") -(declare-function eshell-interactive-filter "esh-mode" (buffer string)) +(declare-function eshell-interactive-output-filter "esh-mode" (buffer string)) (declare-function eshell-set-exit-info "esh-cmd" (status result)) (declare-function eshell-tail-process "esh-cmd") @@ -483,10 +483,9 @@ This is done after all necessary filtering has been done." (when string (eshell-debug-command 'process "received output from process `%s'\n\n%s" process string) - (eshell--mark-as-output 0 (length string) string) - (eshell-interactive-filter (if process (process-buffer process) - (current-buffer)) - string))) + (eshell-interactive-output-filter (if process (process-buffer process) + (current-buffer)) + string))) (define-obsolete-function-alias 'eshell-output-filter #'eshell-interactive-process-filter "30.1") @@ -559,8 +558,7 @@ PROC is the process that's exiting. STRING is the exit message." (eshell-interactive-output-p eshell-error-handle handles) (not (string-match "^\\(finished\\|exited\\)" string))) - (eshell--mark-as-output 0 (length string) string) - (eshell-interactive-filter (process-buffer proc) string)) + (eshell-interactive-output-filter (process-buffer proc) string)) (process-put proc :eshell-pending nil) ;; If we're in the middle of handling output from this ;; process then schedule the EOF for later.