From: miha--- via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: Jim Porter <jporterbugs@gmail.com>, 50806@debbugs.gnu.org
Subject: bug#50806: 27.2; [PATCH] Optimize ansi-color.el
Date: Tue, 05 Oct 2021 13:18:02 +0200 [thread overview]
Message-ID: <87h7dv7mad.fsf@miha-pc> (raw)
In-Reply-To: <87bl447yeg.fsf@gnus.org>
[-- Attachment #1.1: Type: text/plain, Size: 534 bytes --]
Lars Ingebrigtsen <larsi@gnus.org> writes:
> <miha@kamnitnik.top> 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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Documentation-fixes-for-recent-ansi-color-additions.patch --]
[-- Type: text/x-patch, Size: 2041 bytes --]
From a5dcb656893330cfed57ccadc48bfa9c96321a55 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miha=20Rihtar=C5=A1i=C4=8D?= <miha@kamnitnik.top>
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).
---
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
--- 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'
-ended with, currently a list of the form
+ended with, currently a list of the form:
-(BASIC-FACES FG BG).
+ (BASIC-FACES FG BG).
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
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -723,7 +723,7 @@ term-ansi-current-reverse
(defvar term-ansi-current-invisible nil)
(make-obsolete-variable 'term-ansi-face-already-done
- "it doesn't have any effect." "28.1")
+ "it doesn't have any effect." "29.1")
;;; Faces
(defvar ansi-term-color-vector
@@ -3346,7 +3346,7 @@ term--color-as-hex
;; have any bold/underline/fg/bg/reverse combination. -mm
(defun term-handle-colors-array (parameter)
- (declare (obsolete term--handle-colors-list "28.1"))
+ (declare (obsolete term--handle-colors-list "29.1"))
(term--handle-colors-list (list parameter)))
(defun term--handle-colors-list (parameters)
--
2.33.0
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.3: 0002-Add-tests-for-incomplete-escape-sequences-in-ansi-co.patch --]
[-- Type: text/x-patch, Size: 4623 bytes --]
From c73b559cc705ef3f01eb04ad62947a59ed316657 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miha=20Rihtar=C5=A1i=C4=8D?= <miha@kamnitnik.top>
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).
---
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
--- a/test/lisp/ansi-color-tests.el
+++ b/test/lisp/ansi-color-tests.el
@@ -24,6 +24,7 @@
;;; Code:
(require 'ansi-color)
+(eval-when-compile (require 'cl-lib))
(defvar ansi-color-tests--strings
(let ((bright-yellow (face-foreground 'ansi-color-bright-yellow nil 'default))
@@ -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))))))
+(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))))))
+(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)
;;; ansi-color-tests.el ends here
--
2.33.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
next prev parent reply other threads:[~2021-10-05 11:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-25 22:32 bug#50806: 27.2; [PATCH] Optimize ansi-color.el miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-03 16:31 ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-03 17:53 ` Jim Porter
2021-10-03 19:54 ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-03 20:16 ` Jim Porter
2021-10-04 10:17 ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-03 19:59 ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-04 9:27 ` Lars Ingebrigtsen
2021-10-04 10:07 ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-05 6:56 ` Lars Ingebrigtsen
2021-10-05 11:18 ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-10-06 8:51 ` Lars Ingebrigtsen
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h7dv7mad.fsf@miha-pc \
--to=bug-gnu-emacs@gnu.org \
--cc=50806@debbugs.gnu.org \
--cc=jporterbugs@gmail.com \
--cc=larsi@gnus.org \
--cc=miha@kamnitnik.top \
/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 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).