Function: comint-redirect-preoutput-filter

comint-redirect-preoutput-filter is a byte-compiled function defined in comint.el.gz.

Signature

(comint-redirect-preoutput-filter INPUT-STRING)

Documentation

Comint filter function which redirects Comint output to a buffer or buffers.

The variable comint-redirect-output-buffer says which buffer(s) to place output in.

INPUT-STRING is the input from the Comint process.

This function does not need to be invoked by the end user.

Source Code

;; Defined in /usr/src/emacs/lisp/comint.el.gz
(defun comint-redirect-preoutput-filter (input-string)
  "Comint filter function which redirects Comint output to a buffer or buffers.
The variable `comint-redirect-output-buffer' says which buffer(s) to
place output in.

INPUT-STRING is the input from the Comint process.

This function does not need to be invoked by the end user."
  (let ((output-buffer-list
	 (if (listp comint-redirect-output-buffer)
             comint-redirect-output-buffer
	   (list comint-redirect-output-buffer)))
	(filtered-input-string input-string))

    ;; If there are any filter functions, give them a chance to modify
    ;; the string.
    (let ((functions comint-redirect-filter-functions))
      (while (and functions filtered-input-string)
	(if (eq (car functions) t)
	    ;; If a local value says "use the default value too",
	    ;; do that.
	    (let ((functions
                   (default-value 'comint-redirect-filter-functions)))
	      (while (and functions filtered-input-string)
		(setq filtered-input-string
		      (funcall (car functions) filtered-input-string))
		(setq functions (cdr functions))))
	  (setq filtered-input-string
		(funcall (car functions) filtered-input-string)))
	(setq functions (cdr functions))))

    ;; Clobber `comint-redirect-finished-regexp'
    (or comint-redirect-insert-matching-regexp
	(and (string-match comint-redirect-finished-regexp filtered-input-string)
	     (setq filtered-input-string
		   (replace-match "" nil nil filtered-input-string))))

    ;; Send output to all registered buffers
    (save-excursion
      (dolist (buf output-buffer-list)
	;; Set this buffer to the output buffer
	(set-buffer (get-buffer-create buf))
	;; Go to the end of the buffer
	(goto-char (point-max))
	;; Insert the output
	(let ((inhibit-read-only comint-redirect-subvert-readonly))
	  (insert filtered-input-string))))

    ;; Message
    (and comint-redirect-verbose
	 (message "Redirected output to buffer(s) %s" output-buffer-list))

    ;; If we see the prompt, tidy up
    ;; We'll look for the prompt in the original string, so nobody can
    ;; clobber it
    (and (string-match comint-redirect-finished-regexp
                       (concat comint-redirect-previous-input-string
                               input-string))
	 (progn
	   (and comint-redirect-verbose
		(message "Redirection completed"))
	   (comint-redirect-cleanup)
	   (run-hooks 'comint-redirect-hook)))
    (setq comint-redirect-previous-input-string input-string)

    ;; Echo input?
    (if comint-redirect-echo-input
	filtered-input-string
      "")))