Function: ansi-color-filter-apply

ansi-color-filter-apply is a byte-compiled function defined in ansi-color.el.gz.

Signature

(ansi-color-filter-apply STRING)

Documentation

Filter out all ANSI control sequences from STRING.

Every call to this function will set and use the buffer-local variable ansi-color-context to save partial escape sequences. This information will be used for the next call to ansi-color-apply. Set ansi-color-context to nil if you don't want this.

This function can be added to comint-preoutput-filter-functions.

Aliases

python-comint-output-filter-function (obsolete since 25.1)

Source Code

;; Defined in /usr/src/emacs/lisp/ansi-color.el.gz
(defun ansi-color-filter-apply (string)
  "Filter out all ANSI control sequences from STRING.

Every call to this function will set and use the buffer-local variable
`ansi-color-context' to save partial escape sequences.  This information
will be used for the next call to `ansi-color-apply'.  Set
`ansi-color-context' to nil if you don't want this.

This function can be added to `comint-preoutput-filter-functions'."
  (let ((start 0) end result)
    ;; if context was saved and is a string, prepend it
    (if (cadr ansi-color-context)
        (setq string (concat (cadr ansi-color-context) string)
              ansi-color-context nil))
    ;; find the next escape sequence
    (while (setq end (string-match ansi-color-control-seq-regexp string start))
      (push (substring string start end) result)
      (setq start (match-end 0)))
    ;; save context, add the remainder of the string to the result
    (let (fragment)
      (push (substring string start
                       (if (string-match "\033" string start)
                           (let ((pos (match-beginning 0)))
                             (setq fragment (substring string pos))
                             pos)
                         nil))
            result)
      (setq ansi-color-context (if fragment (list nil fragment))))
    (apply #'concat (nreverse result))))