Skip to content

Commit 053a78d

Browse files
committed
jupyter-ansi-color-apply-on-region: Support newer Emacs versions
Closes #380
1 parent 841c2ff commit 053a78d

File tree

1 file changed

+10
-46
lines changed

1 file changed

+10
-46
lines changed

jupyter-mime.el

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -212,52 +212,16 @@ a value of t. This is mainly for modes like `org-mode' which
212212
strip invisible properties during fontification. In such cases,
213213
the jupyter-invisible property can act as an alias to the
214214
invisible property by adding it to `char-property-alias-alist'."
215-
(let ((codes (car ansi-color-context-region))
216-
(start-marker (or (cadr ansi-color-context-region)
217-
(copy-marker begin)))
218-
(end-marker (copy-marker end))
219-
(ansi-color-apply-face-function
220-
(lambda (beg end face)
221-
(when face
222-
(setq face (list face))
223-
(font-lock-prepend-text-property beg end 'face face)
224-
(put-text-property beg end (or face-prop 'font-lock-face) face)))))
225-
(save-excursion
226-
(goto-char start-marker)
227-
;; Find the next escape sequence.
228-
(while (re-search-forward ansi-color-control-seq-regexp end-marker t)
229-
;; Remove escape sequence.
230-
(let ((esc-seq (prog1 (buffer-substring-no-properties
231-
(match-beginning 0) (point))
232-
;; FIXME: Not removing escape sequences adds in a lot
233-
;; of invisible characters that slows down Emacs on
234-
;; large ANSI coded regions and seems mostly related
235-
;; to redisplay since hiding the region behind an
236-
;; invisible overlay removes the slowdown.
237-
(add-text-properties
238-
(match-beginning 0) (point)
239-
'(invisible t jupyter-invisible t)))))
240-
;; Colorize the old block from start to end using old face.
241-
(funcall ansi-color-apply-face-function
242-
(prog1 (marker-position start-marker)
243-
;; Store new start position.
244-
(set-marker start-marker (point)))
245-
(match-beginning 0) (ansi-color--find-face codes))
246-
;; If this is a color sequence,
247-
(when (eq (aref esc-seq (1- (length esc-seq))) ?m)
248-
;; update the list of ansi codes.
249-
(setq codes (ansi-color-apply-sequence esc-seq codes)))))
250-
;; search for the possible start of a new escape sequence
251-
(if (re-search-forward "\033" end-marker t)
252-
(progn
253-
;; if the rest of the region should have a face, put it there
254-
(funcall ansi-color-apply-face-function
255-
start-marker end-marker (ansi-color--find-face codes))
256-
(setq ansi-color-context-region (if codes (list codes))))
257-
;; if the rest of the region should have a face, put it there
258-
(funcall ansi-color-apply-face-function
259-
start-marker end-marker (ansi-color--find-face codes))
260-
(setq ansi-color-context-region (if codes (list codes)))))))
215+
(cl-letf (((symbol-function #'delete-region)
216+
(lambda (beg end)
217+
(add-text-properties beg end '(invisible t jupyter-invisible t))))
218+
(ansi-color-apply-face-function
219+
(lambda (beg end face)
220+
(when face
221+
(setq face (list face))
222+
(font-lock-prepend-text-property beg end 'face face)
223+
(put-text-property beg end (or face-prop 'font-lock-face) face)))))
224+
(ansi-color-apply-on-region begin end)))
261225

262226
;;; `jupyter-insert' method
263227

0 commit comments

Comments
 (0)