bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ansi-color.el changes


From: Karl Chen
Subject: ansi-color.el changes
Date: Sun, 28 Apr 2002 17:28:52 -0700

Suggested changes to ansi-color.el.

`ansi-color-apply-sequence''s functionality is unneccessarily split into a
`ansi-color-get-face' (a-c-apply-sequence is the only function that calls
a-c-get-face). a-c-get-face's result list is conditionally appended/replaced
to the context face list. The problem is that the resulting list will have
multiple foreground-color, bold, etc. properties. (I regularly get 30 color
changes without a color "reset" (SGR ^[[0m).) Also the "default" keyword in
the middle of the list won't get processed properly. The diffs below show
how to apply changes to the current font face directly.

*** ansi-color.el 2002/04/26 23:17:21 1.3
--- ansi-color.el 2002/04/29 00:16:13 1.5
***************
*** 606,619 ****
  If `ansi-color-get-face' returns nil, then we either got a
  null-sequence, or we stumbled upon some garbage.  In either
  case we return nil."
!   (let ((new-faces (ansi-color-get-face escape-sequence)))
!     (cond ((null new-faces)
!     nil)
!    ((eq (car new-faces) 'default)
!     (cdr new-faces))
!    (t
!     (append new-faces faces)))))

  (defun ansi-color-make-color-map ()
    "Creates a vector of face definitions and returns it.

--- 606,670 ----
  If `ansi-color-get-face' returns nil, then we either got a
  null-sequence, or we stumbled upon some garbage.  In either
  case we return nil."
!   ;;(let ((new-faces (ansi-color-get-face escape-sequence)))
!   ;;  (cond ((null new-faces)
!   ;;         nil)
!   ;;        ((eq (car new-faces) 'default)
!   ;;         (cdr new-faces))
!   ;;        (t
!   ;;         ;;(append new-faces faces)
!   ;;         (kc-add-alist-to-alist (copy-sequence faces) (copy-sequence
new-faces))
!   ;;         ))))
!
!   (let ((ansi-color-r "[0-9][0-9]?")
!         (i 0)
!         f val)
!     (while (string-match ansi-color-r escape-sequence i)
!       (setq i (match-end 0)
!      val (ansi-color-get-face-1
!    (string-to-int (match-string 0 escape-sequence) 10)))
!       (cond ((not val))
!      ((eq val 'default)
!       (setq f nil))
!      (t
!       (kc-add-to-alist 'f val))))
!     f))

+ (defun kc-add-to-alist (alist-var p)
+   "Add an element to an alist symbol.
+
+ If the element is a cons:
+   If there exists an element in the value of ALIST-VAR whose car matches
the
+ new element's car, replace its cdr. Else prepend the whole element to the
+ list.
+
+ If the element is not a cons:
+   If the element does not already exist, prepend it. (Equivalent to
+ `add-to-list' in this case.)"
+   (if (consp p)
+       (let ((alist (symbol-value alist-var))
+             (pname (car p)))
+         (when pname
+           (while alist
+             (let ((p0 (car alist)))
+               (setq alist (cdr alist))
+               (when (and (consp p0) (eq (car p0) pname))
+                 (setcdr p0 (cdr p))
+             (setq alist nil)
+             (setq pname nil))))
+           (when pname
+             (set alist-var (cons p (symbol-value alist-var)))
+             )))
+     (add-to-list alist-var p)))
+
+ (defun kc-add-alist-to-alist (alist new-alist)
+   "Apply NEW-ALIST on ALIST by calling `add-to-alist' on each entry."
+   (while new-alist
+     (kc-add-to-alist 'alist (car new-alist))
+     (setq new-alist (cdr new-alist))
+     )
+   alist)
+
  (defun ansi-color-make-color-map ()
    "Creates a vector of face definitions and returns it.

***************
*** 676,702 ****
        (aref ansi-color-map ansi-code)
      ('args-out-of-range nil)))

! (defun ansi-color-get-face (escape-seq)
!   "Create a new face by applying all the parameters in ESCAPE-SEQ.

! Should any of the parameters result in the default face (usually this is
! the parameter 0), then the effect of all previous parameters is cancelled.

! ESCAPE-SEQ is a SGR control sequences such as \\033[34m.  The parameter
! 34 is used by `ansi-color-get-face-1' to return a face definition."
!   (let ((ansi-color-r "[0-9][0-9]?")
!         (i 0)
!         f val)
!     (while (string-match ansi-color-r escape-seq i)
!       (setq i (match-end 0)
!      val (ansi-color-get-face-1
!    (string-to-int (match-string 0 escape-seq) 10)))
!       (cond ((not val))
!      ((eq val 'default)
!       (setq f (list val)))
!      (t
!       (add-to-list 'f val))))
!     f))

  (provide 'ansi-color)

--- 727,753 ----
        (aref ansi-color-map ansi-code)
      ('args-out-of-range nil)))

! ;;(defun ansi-color-get-face (escape-seq)
! ;;  "Create a new face by applying all the parameters in ESCAPE-SEQ.

! ;;Should any of the parameters result in the default face (usually this is
! ;;the parameter 0), then the effect of all previous parameters is
cancelled.

! ;;ESCAPE-SEQ is a SGR control sequences such as \\033[34m.  The parameter
! ;;34 is used by `ansi-color-get-face-1' to return a face definition."
! ;;  (let ((ansi-color-r "[0-9][0-9]?")
! ;;        (i 0)
! ;;        f val)
! ;;    (while (string-match ansi-color-r escape-seq i)
! ;;      (setq i (match-end 0)
! ;;     val (ansi-color-get-face-1
! ;;   (string-to-int (match-string 0 escape-seq) 10)))
! ;;      (cond ((not val))
! ;;     ((eq val 'default)
! ;;      (setq f (list val)))
! ;;     (t
! ;;      (add-to-list 'f val))))
! ;;    f))

  (provide 'ansi-color)







reply via email to

[Prev in Thread] Current Thread [Next in Thread]