From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: miha--- via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#50806: 27.2; [PATCH] Optimize ansi-color.el Date: Tue, 05 Oct 2021 13:18:02 +0200 Message-ID: <87h7dv7mad.fsf@miha-pc> References: <87tui8wakb.fsf@miha-pc> <25ed8125-3f78-c9c9-9324-d75e48e702c6@gmail.com> <87fsthc21u.fsf@miha-pc> <87czolp2bd.fsf@gnus.org> <87v92df6ia.fsf@miha-pc> <87bl447yeg.fsf@gnus.org> Reply-To: Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26586"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Jim Porter , 50806@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 05 13:15:40 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mXiQ8-0006iY-0v for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 05 Oct 2021 13:15:40 +0200 Original-Received: from localhost ([::1]:45670 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mXiQ6-0004PZ-HF for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 05 Oct 2021 07:15:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXiPX-0004OO-1z for bug-gnu-emacs@gnu.org; Tue, 05 Oct 2021 07:15:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55872) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mXiPW-0007jh-QX for bug-gnu-emacs@gnu.org; Tue, 05 Oct 2021 07:15:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mXiPW-0002Nr-Gb for bug-gnu-emacs@gnu.org; Tue, 05 Oct 2021 07:15:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 05 Oct 2021 11:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50806 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 50806-submit@debbugs.gnu.org id=B50806.16334324739097 (code B ref 50806); Tue, 05 Oct 2021 11:15:02 +0000 Original-Received: (at 50806) by debbugs.gnu.org; 5 Oct 2021 11:14:33 +0000 Original-Received: from localhost ([127.0.0.1]:39185 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mXiP3-0002Mf-2W for submit@debbugs.gnu.org; Tue, 05 Oct 2021 07:14:33 -0400 Original-Received: from kamnitnik.top ([209.250.245.214]:47020) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mXiP0-0002MU-8R for 50806@debbugs.gnu.org; Tue, 05 Oct 2021 07:14:31 -0400 Original-Received: from localhost (BSN-77-156-43.static.siol.net [193.77.156.43]) by kamnitnik.top (Postfix) with ESMTPSA id BA42F9C707; Tue, 5 Oct 2021 11:14:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kamnitnik.top; s=mail; t=1633432468; bh=1jRgct1BDLnwr/NLfnZg+/L1Ciq2iJfMbAQIOTBYfus=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=DL8QIGj6uHSf/jqIIdIzZMYj7gVZez7+jwu8A2Q1Hpva0POcMiEV4969VRmV3MQ8H GD9t1Kr6mLlr2/p2ANGZzy0sFD+dd7VvhU/RDT88sGQ0b6szN1ZC4KAV+SLuUK/Qs3 YrN/woWdrhZ5fM3IslU55Gv4LNh2UY1HOYVUhBwgAVNWHdgqtMwp/kBiCZp2GIzVKJ flhnln3neS3CGAGPq6sDVgzfRe4+/Ap20uzT9e2YnvSmXXtj61mGPgEzxX2o/lmJGH cBXrRoU8IcHZD3QTr4VpJd7pWQDnd5EIFaVKSqo4Vut0kUwUuOYucJFoFcd5U8QT2A 5Xql6KDy5Kqow== In-Reply-To: <87bl447yeg.fsf@gnus.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:216436 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Lars Ingebrigtsen writes: > writes: > >> Yes, [PATCH] Optimize ansi-color.el (from my second e-mail) >> and [PATCH 2/4] Add support for 256-color and 24bit ANSI colors in ansi-color >> >> are meant to be applied to Emacs 29 on top of each-other. > > Thanks; I've now applied all the patches, I think, and pushed to the > trunk. > Thanks. Here, I attach two more patches, one with minor documentation fixes and one with a new test for incomplete ANSI escape sequences. Thanks and best regards. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Documentation-fixes-for-recent-ansi-color-additions.patch Content-Transfer-Encoding: quoted-printable From=20a5dcb656893330cfed57ccadc48bfa9c96321a55 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Miha=3D20Rihtar=3DC5=3DA1i=3DC4=3D8D?=3D Date: Tue, 5 Oct 2021 11:14:22 +0200 Subject: [PATCH 1/2] Documentation fixes for recent ansi-color additions * lisp/ansi-color.el (ansi-color-context-region): Improve formatting. * lisp/term.el (term-ansi-face-already-done): (term-handle-colors-array): Fix obsoleting version (bug#50806). =2D-- lisp/ansi-color.el | 4 ++-- lisp/term.el | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lisp/ansi-color.el b/lisp/ansi-color.el index aaaf60cd00..2e51264ec3 100644 =2D-- a/lisp/ansi-color.el +++ b/lisp/ansi-color.el @@ -656,9 +656,9 @@ ansi-color-context-region "Context saved between two calls to `ansi-color-apply-on-region'. This is a list of the form (FACE-VEC MARKER) or nil. FACE-VEC represents the state the last call to `ansi-color-apply-on-region' =2Dended with, currently a list of the form +ended with, currently a list of the form: =20 =2D(BASIC-FACES FG BG). + (BASIC-FACES FG BG). =20 BASIC-FACES is a bool-vector that specifies which basic faces from `ansi-color-basic-faces-vector' to apply. FG and BG are diff --git a/lisp/term.el b/lisp/term.el index ce086c379b..0e36e877e6 100644 =2D-- a/lisp/term.el +++ b/lisp/term.el @@ -723,7 +723,7 @@ term-ansi-current-reverse (defvar term-ansi-current-invisible nil) =20 (make-obsolete-variable 'term-ansi-face-already-done =2D "it doesn't have any effect." "28.1") + "it doesn't have any effect." "29.1") =20 ;;; Faces (defvar ansi-term-color-vector @@ -3346,7 +3346,7 @@ term--color-as-hex ;; have any bold/underline/fg/bg/reverse combination. -mm =20 (defun term-handle-colors-array (parameter) =2D (declare (obsolete term--handle-colors-list "28.1")) + (declare (obsolete term--handle-colors-list "29.1")) (term--handle-colors-list (list parameter))) =20 (defun term--handle-colors-list (parameters) =2D-=20 2.33.0 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0002-Add-tests-for-incomplete-escape-sequences-in-ansi-co.patch Content-Transfer-Encoding: quoted-printable From=20c73b559cc705ef3f01eb04ad62947a59ed316657 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Miha=3D20Rihtar=3DC5=3DA1i=3DC4=3D8D?=3D Date: Tue, 5 Oct 2021 12:20:45 +0200 Subject: [PATCH 2/2] Add tests for incomplete escape sequences in ansi-color-tests * test/lisp/ansi-color-tests.el (ansi-color-tests-equal-props): New function. (ansi-color-incomplete-sequences-test): New ert test (bug#50806). =2D-- test/lisp/ansi-color-tests.el | 82 +++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/test/lisp/ansi-color-tests.el b/test/lisp/ansi-color-tests.el index 16a1ba4a89..14a14ca4f0 100644 =2D-- a/test/lisp/ansi-color-tests.el +++ b/test/lisp/ansi-color-tests.el @@ -24,6 +24,7 @@ ;;; Code: =20 (require 'ansi-color) +(eval-when-compile (require 'cl-lib)) =20 (defvar ansi-color-tests--strings (let ((bright-yellow (face-foreground 'ansi-color-bright-yellow nil 'def= ault)) @@ -61,6 +62,17 @@ ansi-color-tests--strings ("\e[48;2;135;255;255;1mHello World\e[0m" "Hello World" (ansi-color-bold (:background ,custom-color)))))) =20 +(defun ansi-color-tests-equal-props (o1 o2) + "Return t if two Lisp objects have similar structure and contents. +While `equal-including-properties' compares text properties of +strings with `eq', this function compares them with `equal'." + (or (equal-including-properties o1 o2) + (and (stringp o1) + (equal o1 o2) + (cl-loop for i below (length o1) + always (equal (text-properties-at i o1) + (text-properties-at i o2)))))) + (ert-deftest ansi-color-apply-on-region-test () (pcase-dolist (`(,input ,text ,face) ansi-color-tests--strings) (with-temp-buffer @@ -91,6 +103,76 @@ ansi-color-apply-on-region-preserving-test (ansi-color-apply-on-region (point-min) (point-max) t) (should (equal (buffer-string) (car pair)))))) =20 +(ert-deftest ansi-color-incomplete-sequences-test () + (let* ((strs (list "\e[" "2;31m Hello World " + "\e" "[108;5;12" "3m" "Greetings" + "\e[0m\e[35;6m" "Hello")) + (complete-str (apply #'concat strs)) + (filtered-str) + (propertized-str) + (ansi-color-apply-face-function + #'ansi-color-apply-text-property-face) + (ansi-filt (lambda (str) (ansi-color-filter-apply + (copy-sequence str)))) + (ansi-app (lambda (str) (ansi-color-apply + (copy-sequence str))))) + + (with-temp-buffer + (setq filtered-str + (replace-regexp-in-string "\e\\[.*?m" "" complete-str)) + (setq propertized-str (funcall ansi-app complete-str)) + + (should-not (ansi-color-tests-equal-props + filtered-str propertized-str)) + (should (equal filtered-str propertized-str))) + + ;; Tests for `ansi-color-filter-apply' + (with-temp-buffer + (should (equal-including-properties + filtered-str + (funcall ansi-filt complete-str)))) + + (with-temp-buffer + (should (equal-including-properties + filtered-str + (mapconcat ansi-filt strs "")))) + + ;; Tests for `ansi-color-filter-region' + (with-temp-buffer + (insert complete-str) + (ansi-color-filter-region (point-min) (point-max)) + (should (equal-including-properties + filtered-str (buffer-string)))) + + (with-temp-buffer + (dolist (str strs) + (let ((opoint (point))) + (insert str) + (ansi-color-filter-region opoint (point)))) + (should (equal-including-properties + filtered-str (buffer-string)))) + + ;; Test for `ansi-color-apply' + (with-temp-buffer + (should (ansi-color-tests-equal-props + propertized-str + (mapconcat ansi-app strs "")))) + + ;; Tests for `ansi-color-apply-on-region' + (with-temp-buffer + (insert complete-str) + (ansi-color-apply-on-region (point-min) (point-max)) + (should (ansi-color-tests-equal-props + propertized-str (buffer-string)))) + + (with-temp-buffer + (dolist (str strs) + (let ((opoint (point))) + (insert str) + (ansi-color-apply-on-region opoint (point)))) + (should (ansi-color-tests-equal-props + propertized-str (buffer-string)))))) + (provide 'ansi-color-tests) =20 ;;; ansi-color-tests.el ends here =2D-=20 2.33.0 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJHBAEBCAAxFiEEmxVnesoT5rQXvVXnswkaGpIVmT8FAmFcNGoTHG1paGFAa2Ft bml0bmlrLnRvcAAKCRCzCRoakhWZP9C1D/sH+2iktD83lYTmo4TGRKTRi125PGWA vDUGcKHTzEKn5vpwJYVyU0V5UV/clhdgT1M+Wib3hVslQwbWbQd0/VwNfYYUlP4W bUrq8MCcyBtStRvISai1dAvmjpRDsGBi6lXzxS7IQDyUMzbyObhHfbDFCwxAHEyR agawn5Is18sfBFDMsPL8F3NSiQQLrg8WJ2qDUJtaCavOaeGKV/yr1aQN7VrO5U7j xAzjjSnIdAKPKEBc8ZxmxdwDgXznHFtqqdLvdUfhcFlJ0hHAmUBmznNXeoPkiodu Uv6nnvGBYr+3MzQWbw6rEJNKHfl9AC/OzBbJwZtiA9pje+phb2KrdbRkEU5M4kN+ U126Zij19QH1u0O322/rLNahTknUllAB/oiTDRRbPEe0nl0aZnw2C7/jEk6nDRwl vP6Cd5X0tpa90FC0fOy4XIkFw4h0O0fxLrqa596dVv0TmbmYaiRQ8ahyGPhgLPmB a5om5bfzLJbHm4NNJ10oJFecrlV124NF3gbgrkQoREtrKD4DKX8M4t+zldr8j7A/ VU/fPt88vV3NCYmcl3PkjpWpc8lLKZd6WOAvWppsyk7pxjGmTJJXv8TdxHhzhkH8 IqNOD1PHckXldehkFCzoG0SF5RhOsGiQQ08Jm32wKK1uNb2/zT0R/J3vvDNWy+Mq dF5ctg0s+eNECQ== =/47p -----END PGP SIGNATURE----- --==-=-=--