Skip to content

Instantly share code, notes, and snippets.

@erikarvstedt
Created April 26, 2022 00:00
Show Gist options
  • Save erikarvstedt/f3b8b4a866ca3a18e293abea2bea45df to your computer and use it in GitHub Desktop.
Save erikarvstedt/f3b8b4a866ca3a18e293abea2bea45df to your computer and use it in GitHub Desktop.
--- a.el 2022-04-26 01:58:00.191401081 +0200
+++ b.el 2022-04-26 01:58:00.191401081 +0200
@@ -42,10 +42,18 @@
;; Store new start position.
(set-marker start-marker (point)))
(match-beginning 0) (ansi-color--find-face codes))
- ;; If this is a color sequence,
- (when (eq (aref esc-seq (1- (length esc-seq))) ?m)
- ;; update the list of ansi codes.
- (setq codes (ansi-color-apply-sequence esc-seq codes)))))
+ (let ((last-char (aref esc-seq (1- (length esc-seq)))))
+ (pcase last-char
+ ;; A color sequence
+ (`?m
+ ;; update the list of ansi codes.
+ (setq codes (ansi-color-apply-sequence esc-seq codes)))
+ ;; A cursor back (CUB) sequence
+ (`?D
+ (let ((n (string-to-number (substring esc-seq 2 -1)))
+ (line-start (let ((inhibit-field-text-motion t))
+ (line-beginning-position))))
+ (delete-region (max line-start (- (point) n)) (point))))))))
;; search for the possible start of a new escape sequence
(if (re-search-forward "\033" end-marker t)
(progn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment