all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Wolfgang Jenkner <wjenkner@inode.at>
To: Dima Kogan <dima@secretsauce.net>
Cc: 12792@debbugs.gnu.org
Subject: bug#12792: 24.2.50; shell-mode renders all its output in a yellow face
Date: Fri, 09 Nov 2012 02:50:32 +0100	[thread overview]
Message-ID: <858vaaq27e.fsf@iznogoud.viz> (raw)
In-Reply-To: <871ugbxdyr.fsf@secretsauce.net>

On Tue, Nov 06 2012, Dima Kogan wrote:

>> So, I'd say that the issue at hand is solved.  I'll just try to
>> rewrite the new ansi-color-apply-sequence in a less ugly way.
>
> Sounds good. Thanks a lot.

I hope the patch below is less ugly and also correct.  Perhaps you could
try it.

Note to the maintainers:  This fixes a regression for a feature not
actually present in previous versions of emacs ;-)


2012-11-08  Wolfgang Jenkner  <wjenkner@inode.at>

	* ansi-color.el (ansi-color-apply-sequence): Implement SGR codes
	39 and 49 (bug#12792).	Also, restore the behavior of revisions
	prior to 109621, where unimplemented codes are treated like code 0.


=== modified file 'lisp/ansi-color.el'
--- lisp/ansi-color.el	2012-09-25 04:13:02 +0000
+++ lisp/ansi-color.el	2012-11-09 00:19:00 +0000
@@ -534,34 +534,39 @@
 
 ESCAPE-SEQ is an escape sequence parsed by `ansi-color-parse-sequence'.
 
-If the new codes resulting from ESCAPE-SEQ start with 0, then the
-old codes are discarded and the remaining new codes are
-processed.  Otherwise, for each new code: if it is 21-25 or 27-29
-delete appropriate parameters from the list of codes; any other
-code that makes sense is added to the list of codes.  Finally,
-the so changed list of codes is returned."
+For each new code, the following happens: if it is 1-7, add it to
+the list of codes; if it is 21-25 or 27, delete appropriate
+parameters from the list of codes; if it is 30-37 resp. 39, the
+foreground color code is replaced or added resp. deleted; if it
+is 40-47 resp. 49, the background color code is replaced or added
+resp. deleted; any other code is discarded together with the old
+codes.	Finally, the so changed list of codes is returned."
   (let ((new-codes (ansi-color-parse-sequence escape-sequence)))
     (while new-codes
-      (setq codes
-	    (let ((new (pop new-codes)))
-	      (cond ((zerop new)
-		     nil)
-		    ((or (<= new 20)
-			 (>= new 30))
-		     (if (memq new codes)
-			 codes
-		       (cons new codes)))
-		    ;; The standard says `21 doubly underlined' while
-		    ;; http://en.wikipedia.org/wiki/ANSI_escape_code claims
-		    ;; `21 Bright/Bold: off or Underline: Double'.
-		    ((/= new 26)
-		     (remq (- new 20)
-			   (cond ((= new 22)
-				  (remq 1 codes))
-				 ((= new 25)
-				  (remq 6 codes))
-				 (t codes))))
-		    (t codes)))))
+      (let* ((new (pop new-codes))
+	     (q (/ new 10)))
+	(setq codes
+	      (pcase q
+		(0 (unless (memq new '(0 8 9))
+		     (cons new (remq new codes))))
+		(2 (unless (memq new '(20 26 28 29))
+		     ;; The standard says `21 doubly underlined' while
+		     ;; http://en.wikipedia.org/wiki/ANSI_escape_code claims
+		     ;; `21 Bright/Bold: off or Underline: Double'.
+		     (remq (- new 20) (pcase new
+					(22 (remq 1 codes))
+					(25 (remq 6 codes))
+					(_ codes)))))
+		((or 3 4) (let ((r (mod new 10)))
+			    (unless (= r 8)
+			      (let (beg)
+				(while (and codes (/= q (/ (car codes) 10)))
+				  (push (pop codes) beg))
+				(setq codes (nconc (nreverse beg) (cdr codes)))
+				(if (= r 9)
+				    codes
+				  (cons new codes))))))
+		(_ nil)))))
     codes))
 
 (defun ansi-color-make-color-map ()






  reply	other threads:[~2012-11-09  1:50 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-03  8:55 bug#12792: 24.2.50; shell-mode renders all its output in a yellow face Dima Kogan
2012-11-03 11:16 ` Chong Yidong
2012-11-03 18:08   ` Dima Kogan
2012-11-03 15:37 ` Wolfgang Jenkner
2012-11-03 16:32   ` Eli Zaretskii
2012-11-03 17:59     ` Wolfgang Jenkner
2012-11-04  3:27       ` Wolfgang Jenkner
2012-11-04  7:45         ` Dima Kogan
2012-11-04 13:49           ` Wolfgang Jenkner
2012-11-04 20:24             ` Dima Kogan
2012-11-04 23:39               ` Wolfgang Jenkner
2012-11-05  3:23                 ` Dima Kogan
2012-11-05 15:00                   ` Wolfgang Jenkner
2012-11-05 15:25                     ` Wolfgang Jenkner
2012-11-05 23:57                     ` Dima Kogan
2012-11-06  1:24                       ` Wolfgang Jenkner
2012-11-06  1:31                         ` Dima Kogan
2012-11-09  1:50                           ` Wolfgang Jenkner [this message]
2012-11-09 17:30                             ` Stefan Monnier
2012-11-09 18:20                               ` Wolfgang Jenkner
2012-11-09 20:37                                 ` Stefan Monnier
2012-11-17 15:21 ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=858vaaq27e.fsf@iznogoud.viz \
    --to=wjenkner@inode.at \
    --cc=12792@debbugs.gnu.org \
    --cc=dima@secretsauce.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.