Function: ansi-color-filter-region

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

Signature

(ansi-color-filter-region BEGIN END)

Documentation

Filter out all ANSI control sequences from region BEGIN to END.

Every call to this function will set and use the buffer-local variable ansi-color-context-region to save position. This information will be used for the next call to ansi-color-apply-on-region. Specifically, it will override BEGIN, the start of the region. Set ansi-color-context-region to nil if you don't want this.

Source Code

;; Defined in /usr/src/emacs/lisp/ansi-color.el.gz
(defun ansi-color-filter-region (begin end)
  "Filter out all ANSI control sequences from region BEGIN to END.

Every call to this function will set and use the buffer-local variable
`ansi-color-context-region' to save position.  This information will be
used for the next call to `ansi-color-apply-on-region'.  Specifically,
it will override BEGIN, the start of the region.  Set
`ansi-color-context-region' to nil if you don't want this."
  (let ((end-marker (copy-marker end))
	(start (or (cadr ansi-color-context-region) begin)))
    (save-excursion
      (goto-char start)
      ;; Delete escape sequences.
      (while (re-search-forward ansi-color-control-seq-regexp end-marker t)
        (delete-region (match-beginning 0) (match-end 0)))
      ;; save context, add the remainder of the string to the result
      (if (re-search-forward "\033" end-marker t)
	  (setq ansi-color-context-region (list nil (match-beginning 0)))
	(setq ansi-color-context-region nil)))))