From 935d50d93d37d2d4649673a5d52ec4efe4abce7b Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Mon, 19 Dec 2016 15:38:36 +0000 Subject: [PATCH] Delay showing Async Shell Command buffer until output (Bug#18133) * lisp/comint.el (comint-input-filter): Add process argument. (comint-output-filter-functions): Add `comint-make-buffer-visible' to the list, document the second argument (the process). (comint-send-input): Call input and output filter functions with process argument. (comint-output-filter): Call output filter functions with process argument. (comint-make-buffer-visible): New hook function, to make Async Shell Command buffer visible. (comint-postoutput-scroll-to-bottom): (comint-watch-for-password-prompt): Add dummy process argument. * lisp/window.el (display-buffer-alist): Add a default entry to hide Async Shell Command output window. * lisp/ansi-color.el (ansi-color-process-output): Add a dummy process argument. --- lisp/comint.el | 22 ++++++++++++++++------ lisp/window.el | 5 ++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lisp/comint.el b/lisp/comint.el index b9c65b0..6fa2fc9 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -1913,12 +1913,12 @@ comint-send-input ;; but that scrolled the buffer in undesirable ways. (run-hook-with-args 'comint-output-filter-functions ""))))) -(defvar comint-preoutput-filter-functions nil +(defvar comint-preoutput-filter-functions '(comint-make-newly-written-buffer-visible) "List of functions to call before inserting Comint output into the buffer. -Each function gets one argument, a string containing the text received -from the subprocess. It should return the string to insert, perhaps -the same string that was received, or perhaps a modified or transformed -string. +Each function gets two argument, a string containing the text received +from the subprocess, and the process. It should return the string to +insert, perhaps the same string that was received, or perhaps a modified or +transformed string. The functions on the list are called sequentially, and each one is given the string returned by the previous one. The string returned by @@ -2023,7 +2023,7 @@ comint-output-filter (let ((functions (default-value 'comint-preoutput-filter-functions))) (while (and functions string) - (setq string (funcall (car functions) string)) + (setq string (funcall (car functions) string process)) (setq functions (cdr functions)))) (setq string (funcall (car functions) string))) (setq functions (cdr functions)))) @@ -2111,6 +2111,16 @@ comint-output-filter (add-text-properties prompt-start (point) '(rear-nonsticky t))) (goto-char saved-point))))))) +(defun comint-make-newly-written-buffer-visible (string process) + "Make the output buffer visible when output is added to an empty buffer. +Useful in `comint-preoutput-filter-functions'." + (let ((buffer (process-buffer process))) + (when (and (= 0 (buffer-size buffer)) + (string-match-p "\\*Async Shell Command\\*" + (buffer-name buffer))) + (display-buffer (process-buffer process)))) + string) + (defun comint-preinput-scroll-to-bottom () "Go to the end of buffer in all windows showing it. Movement occurs if point in the selected window is not after the process mark, diff --git a/lisp/window.el b/lisp/window.el index fdb67ed..a49f4a3 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -6797,7 +6797,10 @@ display-buffer-alist (choice :tag "Condition" regexp (function :tag "Matcher function")) - :value-type ,display-buffer--action-custom-type) + :value-type ,display-buffer--action-custom-type + :options (("\\*Async Shell Command\\*" + (cons + (const display-buffer-no-window) (const nil))))) :risky t :version "24.1" :group 'windows) -- 2.7.4