From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Leo Newsgroups: gmane.emacs.bugs Subject: bug#7485: 23.2; Fix removing unrecognized ANSI sequences in ansi-color-apply Date: Fri, 26 Nov 2010 22:41:31 +0000 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1290811506 29325 80.91.229.12 (26 Nov 2010 22:45:06 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 26 Nov 2010 22:45:06 +0000 (UTC) Cc: bug-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Nov 26 23:45:01 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PM72K-0001Ju-M1 for geb-bug-gnu-emacs@m.gmane.org; Fri, 26 Nov 2010 23:45:01 +0100 Original-Received: from localhost ([127.0.0.1]:33539 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PM72K-0007Vg-3v for geb-bug-gnu-emacs@m.gmane.org; Fri, 26 Nov 2010 17:45:00 -0500 Original-Received: from [140.186.70.92] (port=38619 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PM72A-0007T0-5Y for bug-gnu-emacs@gnu.org; Fri, 26 Nov 2010 17:44:54 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PM729-0000EC-3o for bug-gnu-emacs@gnu.org; Fri, 26 Nov 2010 17:44:50 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54452) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PM729-0000E0-08 for bug-gnu-emacs@gnu.org; Fri, 26 Nov 2010 17:44:49 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1PM6uc-0001Bm-8R; Fri, 26 Nov 2010 17:37:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Leo Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 26 Nov 2010 22:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 7485 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by submit@debbugs.gnu.org id=B.12908109774516 (code B ref -1); Fri, 26 Nov 2010 22:37:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 26 Nov 2010 22:36:17 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PM6ts-0001An-Ky for submit@debbugs.gnu.org; Fri, 26 Nov 2010 17:36:17 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PM6tr-0001AX-3O for submit@debbugs.gnu.org; Fri, 26 Nov 2010 17:36:15 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PM6z7-00084t-6l for submit@debbugs.gnu.org; Fri, 26 Nov 2010 17:41:42 -0500 Original-Received: from lists.gnu.org ([199.232.76.165]:58718) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PM6z7-00084p-4A for submit@debbugs.gnu.org; Fri, 26 Nov 2010 17:41:41 -0500 Original-Received: from [140.186.70.92] (port=52741 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PM6z6-0007Fx-3f for bug-gnu-emacs@gnu.org; Fri, 26 Nov 2010 17:41:41 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PM6z5-00084Z-3q for bug-gnu-emacs@gnu.org; Fri, 26 Nov 2010 17:41:39 -0500 Original-Received: from ppsw-51.csi.cam.ac.uk ([131.111.8.151]:52891) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PM6z4-00084R-KO for bug-gnu-emacs@gnu.org; Fri, 26 Nov 2010 17:41:39 -0500 X-Cam-AntiVirus: no malware found X-Cam-SpamDetails: not scanned X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Original-Received: from cpc1-cmbg13-0-0-cust596.5-4.cable.virginmedia.com ([86.9.122.85]:60162 helo=Victoria.local) by ppsw-51.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.158]:587) with esmtpsa (PLAIN:sl392) (TLSv1:DHE-RSA-AES128-SHA:128) id 1PM6yz-0000xd-Ws (Exim 4.72) (return-path ); Fri, 26 Nov 2010 22:41:33 +0000 In-Reply-To: (Stefan Monnier's message of "Fri, 26 Nov 2010 13:55:16 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (Mac OS X 10.6.5) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Fri, 26 Nov 2010 17:37:02 -0500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:41903 Archived-At: On 2010-11-26 18:55 +0000, Stefan Monnier wrote: >> In ansi-color-apply, (string-match "\033" string start) finds the wrong >> portion of context if unrecognized ANSI sequences is not removed before >> the match. > > You mean, because \033 can appear in that unrecognized ANSI sequence? Yes. >> This can cause, for example, eshell's prompt to disappear if >> ansi-color-apply is used in eshell-preoutput-filter-functions. >> The attached patch tries to fix this. > > I don't quite understand your patch. And your saying "tries to fix" > doesn't make me more confident. which means I only briefly tested the patch and it seems not to make things worse while fixing a bug that annoys me ;) >> diff --git a/lisp/ansi-color.el b/lisp/ansi-color.el >> index 00162c9..40c0066 100644 >> *** a/lisp/ansi-color.el >> --- b/lisp/ansi-color.el >> *************** >> *** 341,352 **** >> (put-text-property start (length string) 'ansi-color t string) >> (put-text-property start (length string) 'face face string)) >> ;; save context, add the remainder of the string to the result >> ! (let (fragment) >> ! (if (string-match "\033" string start) >> (let ((pos (match-beginning 0))) >> ! (setq fragment (substring string pos)) >> ! (push (substring string start pos) result)) >> ! (push (substring string start) result)) >> (if (or face fragment) >> (setq ansi-color-context (list face fragment)) >> (setq ansi-color-context nil))) >> --- 341,355 ---- >> (put-text-property start (length string) 'ansi-color t string) >> (put-text-property start (length string) 'face face string)) >> ;; save context, add the remainder of the string to the result >> ! (let ((remaining (substring string start)) >> ! fragment) >> ! (while (string-match ansi-color-drop-regexp remaining) >> ! (setq remaining (replace-match "" nil nil remaining))) >> ! (if (string-match "\033" remaining) >> (let ((pos (match-beginning 0))) >> ! (setq fragment (substring remaining pos)) >> ! (push (substring remaining 0 pos) result)) >> ! (push remaining result)) >> (if (or face fragment) >> (setq ansi-color-context (list face fragment)) >> (setq ansi-color-context nil))) > > This appears to "drop control sequences" even tho they weren't dropped > before, so it does more than "ignore false-positive \033 from > unrecognized control sequences". IIUC those unrecognized control > sequences are dropped elsewhere, right? So are maybe suggesting that > they are currently not dropped at the right time (i.e. dropped too > late), or that the \033 handling takes place too early, or that we > currently forget to drop those control sequences or ... ? > > > Stefan Unrecognized control sequences also begin with char \033. The FRAGMENT part of ansi-color-context wasn't supposed to contain actual text, otherwise they might get lost. It should always be a fragment of a whole ansi control sequence if non-nil. Let me show how this stops eshell prompt from showing. Assume ansi-color-apply is in eshell-preoutput-filter-functions. Suppose the output of shell command 'ack linux' ends with an unrecognized control sequence ^[[K. The whole output string that goes through ansi-color-apply is output of 'ack linux' + 'eshell prompt'. After 'ack linux' finishes, the FRAGMENT of ansi-color-context becomes: #("^[[K\n~/.emacs.d $ " 4 17 (read-only t face eshell-prompt rear-nonsticky (face read-only))) The string after being processed by ansi-color-apply is thus without an eshell prompt. Leo