From ac814964e1885d005746e98f5010a2b400293810 Mon Sep 17 00:00:00 2001 From: Rahguzar Date: Fri, 12 May 2023 09:00:34 +0200 Subject: [PATCH] (Bug#61602) Tweak comint-mode redirection * lisp/comint.el (redirection): New optional argument for 'comint-redirect-send-command-to-process' to explicitly set the regexp to end redirection. Define 'comint-redirect-hook' for easier discovery. Miscellaneous documentation fixes. --- lisp/comint.el | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lisp/comint.el b/lisp/comint.el index 682b555a33c..e6ce31f231c 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -161,7 +161,10 @@ comint-prompt-regexp Defaults to \"^\", the null string at BOL. This variable is only used if the variable -`comint-use-prompt-regexp' is non-nil. +`comint-use-prompt-regexp' is non-nil. An exception to +this is redirection. Many commands including +`comint-redirect-send-command-to-process' use `comint-prompt-regexp' +to detect the end of redirection. Good choices: Canonical Lisp: \"^[^> \\n]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp) @@ -3637,7 +3640,13 @@ comint-redirect-output-buffer (defvar comint-redirect-finished-regexp nil "Regular expression that determines when to stop redirection in Comint. When the redirection filter function is given output that matches this regexp, -the output is inserted as usual, and redirection is completed.") +the output is inserted as usual, and redirection is completed. + +This is an internal variable set by `comint-redirect-setup' and setting it +directly has no effect.") + +(defvar comint-redirect-hook nil + "Normal hook run when a redirection finishes.") (defvar comint-redirect-insert-matching-regexp nil "If non-nil, the text that ends a redirection is included in it. @@ -3833,11 +3842,14 @@ comint-redirect-send-command ;;;###autoload (defun comint-redirect-send-command-to-process - (command output-buffer process echo &optional no-display) + (command output-buffer process echo &optional no-display finished-regexp) "Send COMMAND to PROCESS, with output to OUTPUT-BUFFER. With prefix arg, echo output in process buffer. -If NO-DISPLAY is non-nil, do not show the output buffer." +If NO-DISPLAY is non-nil, do not show the output buffer. +FINISHED-REGEP is set as `comint-redirect-finished-regexp' +when it is non-nil, otherwise `comint-prompt-regexp' is used +as `comint-redirect-finished-regexp'." (interactive "sCommand: \nBOutput Buffer: \nbProcess Buffer: \nP") (let* (;; The process buffer (process-buffer (if (processp process) @@ -3857,9 +3869,9 @@ comint-redirect-send-command-to-process ;; Set up for redirection (comint-redirect-setup output-buffer - (current-buffer) ; Comint Buffer - comint-prompt-regexp ; Finished Regexp - echo) ; Echo input + (current-buffer) ; Comint Buffer + (or finished-regexp comint-prompt-regexp) ; Finished Regexp + echo) ; Echo input ;; Set the filter. (add-function :around (process-filter proc) #'comint-redirect-filter) -- 2.40.1