Function: ansi-osc-apply-on-region

ansi-osc-apply-on-region is a byte-compiled function defined in ansi-osc.el.gz.

Signature

(ansi-osc-apply-on-region BEGIN END)

Documentation

Interpret OSC escape sequences in region between BEGIN and END.

This function searches for escape sequences of the forms

    ESC ] command ; text BEL
    ESC ] command ; text ESC \

Every occurrence of such escape sequences is removed from the buffer. Then, if command is a key in the alist that is the value of the local variable ansi-osc-handlers, that key's value, which should be a function, is called with command and text as arguments, with point where the escape sequence was located.

Source Code

;; Defined in /usr/src/emacs/lisp/ansi-osc.el.gz
;; The function `ansi-osc-apply-on-region' can set `ansi-osc--marker'
;; to the start position of an escape sequence without termination.

(defun ansi-osc-apply-on-region (begin end)
  "Interpret OSC escape sequences in region between BEGIN and END.
This function searches for escape sequences of the forms

    ESC ] command ; text BEL
    ESC ] command ; text ESC \\

Every occurrence of such escape sequences is removed from the
buffer.  Then, if `command' is a key in the alist that is the
value of the local variable `ansi-osc-handlers', that key's
value, which should be a function, is called with `command' and
`text' as arguments, with point where the escape sequence was
located."
  (save-excursion
    (goto-char (or ansi-osc--marker begin))
    (when (eq (char-before) ?\e) (backward-char))
    (while (re-search-forward "\e]" end t)
      (let ((pos0 (match-beginning 0))
            (code (and (re-search-forward "\\=\\([0-9A-Za-z]*\\);" end t)
                       (match-string 1)))
            (pos1 (point)))
        (if (re-search-forward "\a\\|\e\\\\" end t)
            (let ((text (buffer-substring-no-properties
                         pos1 (match-beginning 0))))
              (setq ansi-osc--marker nil)
              (delete-region pos0 (point))
              (when-let ((fun (cdr (assoc-string code ansi-osc-handlers))))
                (funcall fun code text)))
          (put-text-property pos0 end 'invisible t)
          (setq ansi-osc--marker (copy-marker pos0)))))))