From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Karl Chen" Newsgroups: gmane.emacs.bugs Subject: Re: ansi-color.el changes Date: Sun, 28 Apr 2002 18:05:17 -0700 Organization: University of California, Berkeley Sender: bug-gnu-emacs-admin@gnu.org Message-ID: References: NNTP-Posting-Host: localhost.gmane.org X-Trace: main.gmane.org 1020042400 27160 127.0.0.1 (29 Apr 2002 01:06:40 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 29 Apr 2002 01:06:40 +0000 (UTC) Return-path: Original-Received: from fencepost.gnu.org ([199.232.76.164]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 171zcl-00073x-00 for ; Mon, 29 Apr 2002 03:06:39 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 171zcZ-0003Jq-00; Sun, 28 Apr 2002 21:06:27 -0400 Original-Received: from agate.berkeley.edu ([128.32.206.40]) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 171zbT-0003HV-00 for ; Sun, 28 Apr 2002 21:05:19 -0400 Original-Received: (from news@localhost) by agate.berkeley.edu (8.11.6/8.11.3) id g3T15Id82128 ; Sun, 28 Apr 2002 18:05:18 -0700 (PDT) (envelope-from news) Original-To: gnu-emacs-bug@prep.ai.mit.edu Original-Path: not-for-mail Original-Newsgroups: gnu.emacs.bug Original-Lines: 165 Original-NNTP-Posting-Host: star.cs.berkeley.edu Original-X-Trace: agate.berkeley.edu 1020042318 82126 128.32.42.27 (29 Apr 2002 01:05:18 GMT) Original-X-Complaints-To: usenet@agate.berkeley.edu Original-NNTP-Posting-Date: Mon, 29 Apr 2002 01:05:18 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Errors-To: bug-gnu-emacs-admin@gnu.org X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.0.9 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Bug reports for GNU Emacs, the Swiss army knife of text editors List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.bugs:1017 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:1017 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)