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 ((context (ansi-color--ensure-context 'ansi-color-context nil))
(start 0) end result)
;; if context was saved and is a string, prepend it
(setq string (concat (cadr context) string))
(setcar (cdr context) "")
;; 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
(concat "\\(?:"
ansi-color--control-seq-fragment-regexp
"\\)\\'")
string start)
(let ((pos (match-beginning 0)))
(setq fragment (substring string pos))
pos)
nil))
result)
(setcar (cdr context) fragment))
(apply #'concat (nreverse result))))