Skip to content

Commit

Permalink
Update a use of ansi-color-apply-on-region
Browse files Browse the repository at this point in the history
Account for the `PRESERVER-SEQUENCES` argument in Emacs >= 28.1.

* jupyter-mime.el (jupyter--ansi-color-apply-on-region): New function.
(jupyter-ansi-color-apply-on-region): Use it.
  • Loading branch information
nnicandro committed Oct 10, 2024
1 parent 4fdc254 commit 8774c80
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions jupyter-mime.el
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,26 @@ function."

;;; Special handling of ANSI sequences

(defalias 'jupyter--ansi-color-apply-on-region
(if (version< emacs-version "28.1")
(lambda (begin end)
(cl-letf (((symbol-function #'delete-and-extract-region)
(lambda (beg end)
(add-text-properties beg end '(invisible t jupyter-invisible t))
(buffer-substring beg end))))
(ansi-color-apply-on-region begin end)))
(lambda (begin end)
(ansi-color-apply-on-region begin end t)
(dolist (ov (overlays-in begin end))
(when (and (overlay-get ov 'invisible)
(<= begin (overlay-start ov)
(overlay-end ov) end))
;; Assume invisible overlay added by
;; `ansi-color-apply-on-region'.
(add-text-properties (overlay-start ov) (overlay-end ov)
'(invisible t jupyter-invisible t))
(delete-overlay ov))))))

(defun jupyter-ansi-color-apply-on-region (begin end &optional face-prop)
"`ansi-color-apply-on-region' with Jupyter specific modifications.
In particular, does not delete escape sequences between BEGIN and
Expand All @@ -218,10 +238,7 @@ invisible property by adding it to `char-property-alias-alist'."
(setq face (list face))
(font-lock-prepend-text-property beg end 'face face)
(put-text-property beg end (or face-prop 'font-lock-face) face)))))
(cl-letf (((symbol-function #'delete-region)
(lambda (beg end)
(add-text-properties beg end '(invisible t jupyter-invisible t)))))
(ansi-color-apply-on-region begin end))))
(jupyter--ansi-color-apply-on-region begin end)))

;;; `jupyter-insert' method

Expand Down

0 comments on commit 8774c80

Please sign in to comment.