* ansi-color.el changes
@ 2002-04-29 0:28 Karl Chen
2002-04-29 1:05 ` Karl Chen
0 siblings, 1 reply; 3+ messages in thread
From: Karl Chen @ 2002-04-29 0:28 UTC (permalink / raw)
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)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ansi-color.el changes
2002-04-29 0:28 ansi-color.el changes Karl Chen
@ 2002-04-29 1:05 ` Karl Chen
2002-04-29 4:34 ` Karl Chen
0 siblings, 1 reply; 3+ messages in thread
From: Karl Chen @ 2002-04-29 1:05 UTC (permalink / raw)
Previous post had a bug, please ignore.
> 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 01:02:09 1.6
***************
*** 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,672 ----
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 faces) 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 (copy-cons-if-cons val)))))
! f))
!
! (defun copy-cons-if-cons (p) (if (consp p) (cons (car p) (cdr p)) p))
+ (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)
--- 729,755 ----
(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)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ansi-color.el changes
2002-04-29 1:05 ` Karl Chen
@ 2002-04-29 4:34 ` Karl Chen
0 siblings, 0 replies; 3+ messages in thread
From: Karl Chen @ 2002-04-29 4:34 UTC (permalink / raw)
Sorry, another related bug. (Hopefully) works now.
> 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.
>
Diff against version v3.4.5 from
http://www.emacswiki.org/cgi-bin/wiki.pl?AnsiColor :
*** ansi-color.el 2002/04/26 23:17:21 1.3
--- ansi-color.el 2002/04/29 04:33:18 1.8
***************
*** 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,675 ----
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 (copy-alist-sequence faces)) 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 (copy-cons-if-cons val)))))
! f))
!
! (defun copy-alist-sequence (alist)
! (mapcar 'copy-cons-if-cons alist))
+ (defun copy-cons-if-cons (p) (if (consp p) (cons (car p) (cdr p)) p))
+
+ (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)
--- 732,758 ----
(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)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-04-29 4:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-29 0:28 ansi-color.el changes Karl Chen
2002-04-29 1:05 ` Karl Chen
2002-04-29 4:34 ` Karl Chen
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).