* bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode
@ 2021-07-17 19:37 Ivan Sokolov
2021-07-17 19:48 ` Ivan Sokolov
2021-07-17 20:57 ` Jim Porter
0 siblings, 2 replies; 15+ messages in thread
From: Ivan Sokolov @ 2021-07-17 19:37 UTC (permalink / raw)
To: 49609
^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode
2021-07-17 19:37 bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode Ivan Sokolov
@ 2021-07-17 19:48 ` Ivan Sokolov
2021-07-18 0:18 ` Lars Ingebrigtsen
2021-07-17 20:57 ` Jim Porter
1 sibling, 1 reply; 15+ messages in thread
From: Ivan Sokolov @ 2021-07-17 19:48 UTC (permalink / raw)
To: 49609
[-- Attachment #1: Type: text/plain, Size: 112 bytes --]
I don't have much to say about the patch -- it's a well known solution,
I don't know why we don't have it yet.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-option-for-handling-SGR-control-sequences-in-com.patch --]
[-- Type: text/x-patch, Size: 2367 bytes --]
From e41f7bfa24c0fac575ebd7513ea5c527aa4c38ac Mon Sep 17 00:00:00 2001
From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
Date: Sat, 17 Jul 2021 21:56:37 +0300
Subject: [PATCH] Add option for handling SGR control sequences in
compilation-mode
---
lisp/ansi-color.el | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/lisp/ansi-color.el b/lisp/ansi-color.el
index 44dc0351d4..013f2a8c5d 100644
--- a/lisp/ansi-color.el
+++ b/lisp/ansi-color.el
@@ -75,6 +75,7 @@
;;; Code:
(defvar comint-last-output-start)
+(defvar compilation-filter-start)
;; Customization
@@ -181,6 +182,21 @@ ansi-color-for-comint-mode
:group 'ansi-colors
:version "23.2")
+(defcustom ansi-color-for-compilation-mode t
+ "Determines what to do with compilation output.
+If nil, do nothing.
+If the symbol `filter', then filter all SGR control sequences.
+If anything else (such as t), then translate SGR control sequences
+into text properties.
+
+In order for this to have any effect, `ansi-color-compilation-filter'
+must be in `compilation-filter-hook'."
+ :type '(choice (const :tag "Do nothing" nil)
+ (const :tag "Filter" filter)
+ (other :tag "Translate" t))
+ :group 'ansi-colors
+ :version "28.1")
+
(defvar ansi-color-apply-face-function #'ansi-color-apply-overlay-face
"Function for applying an Ansi Color face to text in a buffer.
This function should accept three arguments: BEG, END, and FACE,
@@ -228,6 +244,22 @@ ansi-color-process-output
(t
(ansi-color-apply-on-region start-marker end-marker)))))
+;;;###autoload
+(defun ansi-color-compilation-filter ()
+ "Maybe translate SGR control sequences into text properties.
+Depending on variable `ansi-color-for-compilation-mode' the
+compilation output is either nor processed, SGR control sequences
+are filtered using `ansi-color-filter-region', or SGR control
+sequences are translated into text properties using
+`ansi-color-apply-on-region'."
+ (let ((inhibit-read-only t))
+ (pcase ansi-color-for-compilation-mode
+ ('nil nil)
+ ('filter
+ (ansi-color-filter-region compilation-filter-start (point)))
+ (_
+ (ansi-color-apply-on-region compilation-filter-start (point))))))
+
(define-obsolete-function-alias 'ansi-color-unfontify-region
'font-lock-default-unfontify-region "24.1")
--
2.32.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode
2021-07-17 19:37 bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode Ivan Sokolov
2021-07-17 19:48 ` Ivan Sokolov
@ 2021-07-17 20:57 ` Jim Porter
1 sibling, 0 replies; 15+ messages in thread
From: Jim Porter @ 2021-07-17 20:57 UTC (permalink / raw)
To: 49609
One issue I've seen with handling SGR control sequences in
compilation-mode is that it can sometimes cause issues with grep-mode
and other similar modes in third-party packages. `grep-filter' also
handles SGR control sequences, but only works with full lines; this is
a simplification to (mostly) ensure that both the start and end of a
"match" highlight are present at the same time, so that `grep-filter'
can just use a simple regexp.
However, as far as I understand it, `ansi-color-apply-on-region' has
no such limitation and can handle parsing the *start* of some
highlighted text in one call to the function, and then handle the end
of it in another call. If, when grep is printing results, the output
is flushed in the middle of a match highlight, this results in the SGR
sequence to start a highlight being stripped by the time `grep-filter'
runs, so it's not able to fontify the match.
It might be nice if `grep-filter' were smart enough to work with the
output as-is rather than only operating on whole lines. That would
probably be more robust. However, for this patch, maybe it would be
enough to locally set `ansi-color-for-compilation-mode' to nil for
grep-mode.
^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode
2021-07-17 19:48 ` Ivan Sokolov
@ 2021-07-18 0:18 ` Lars Ingebrigtsen
2021-07-18 0:45 ` Ivan Sokolov
0 siblings, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2021-07-18 0:18 UTC (permalink / raw)
To: Ivan Sokolov; +Cc: 49609
Ivan Sokolov <ivan-p-sokolov@ya.ru> writes:
> +If the symbol `filter', then filter all SGR control sequences.
Perhaps this should say what "SGR" is?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode
2021-07-18 0:18 ` Lars Ingebrigtsen
@ 2021-07-18 0:45 ` Ivan Sokolov
2021-07-18 6:52 ` Eli Zaretskii
0 siblings, 1 reply; 15+ messages in thread
From: Ivan Sokolov @ 2021-07-18 0:45 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 49609
Lars Ingebrigtsen <larsi@gnus.org> writes:
> Ivan Sokolov <ivan-p-sokolov@ya.ru> writes:
>
>> +If the symbol `filter', then filter all SGR control sequences.
>
> Perhaps this should say what "SGR" is?
One of the ANSI escape sequences.
^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode
2021-07-18 0:45 ` Ivan Sokolov
@ 2021-07-18 6:52 ` Eli Zaretskii
2021-07-19 13:53 ` Lars Ingebrigtsen
0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2021-07-18 6:52 UTC (permalink / raw)
To: Ivan Sokolov; +Cc: larsi, 49609
> From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
> Date: Sun, 18 Jul 2021 03:45:58 +0300
> Cc: 49609@debbugs.gnu.org
>
> Lars Ingebrigtsen <larsi@gnus.org> writes:
>
> > Ivan Sokolov <ivan-p-sokolov@ya.ru> writes:
> >
> >> +If the symbol `filter', then filter all SGR control sequences.
> >
> > Perhaps this should say what "SGR" is?
>
> One of the ANSI escape sequences.
SGR = Select Graphic Rendition.
^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode
2021-07-18 6:52 ` Eli Zaretskii
@ 2021-07-19 13:53 ` Lars Ingebrigtsen
2021-07-19 15:45 ` Eli Zaretskii
0 siblings, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2021-07-19 13:53 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Ivan Sokolov, 49609
Eli Zaretskii <eliz@gnu.org> writes:
>> >> +If the symbol `filter', then filter all SGR control sequences.
>> >
>> > Perhaps this should say what "SGR" is?
>>
>> One of the ANSI escape sequences.
>
> SGR = Select Graphic Rendition.
I see. And these are control sequences that are output by... gcc? As
opposed to ... other ANSI escape sequences?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode
2021-07-19 13:53 ` Lars Ingebrigtsen
@ 2021-07-19 15:45 ` Eli Zaretskii
2021-07-19 15:53 ` Lars Ingebrigtsen
0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2021-07-19 15:45 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: ivan-p-sokolov, 49609
> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: Ivan Sokolov <ivan-p-sokolov@ya.ru>, 49609@debbugs.gnu.org
> Date: Mon, 19 Jul 2021 15:53:26 +0200
>
> >> >> +If the symbol `filter', then filter all SGR control sequences.
> >> >
> >> > Perhaps this should say what "SGR" is?
> >>
> >> One of the ANSI escape sequences.
> >
> > SGR = Select Graphic Rendition.
>
> I see. And these are control sequences that are output by... gcc? As
> opposed to ... other ANSI escape sequences?
No, these two terms are synonyms, AFAIK. GCC doesn't emit any SGR
sequences that other similar applications, like Grep, don't. They are
just sequences to produced colors and other attributes: bold,
underline, etc. The intent is to make the important parts of the
output easier to spot.
^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode
2021-07-19 15:45 ` Eli Zaretskii
@ 2021-07-19 15:53 ` Lars Ingebrigtsen
2021-07-19 16:38 ` Eli Zaretskii
2021-07-19 20:19 ` Ivan Sokolov
0 siblings, 2 replies; 15+ messages in thread
From: Lars Ingebrigtsen @ 2021-07-19 15:53 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: ivan-p-sokolov, 49609
Eli Zaretskii <eliz@gnu.org> writes:
> No, these two terms are synonyms, AFAIK. GCC doesn't emit any SGR
> sequences that other similar applications, like Grep, don't. They are
> just sequences to produced colors and other attributes: bold,
> underline, etc. The intent is to make the important parts of the
> output easier to spot.
Right. Then we should just say "ANSI control sequences" here -- whether
they're SGR or not seems irrelevant?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode
2021-07-19 15:53 ` Lars Ingebrigtsen
@ 2021-07-19 16:38 ` Eli Zaretskii
2021-07-19 16:55 ` Lars Ingebrigtsen
2021-07-19 20:19 ` Ivan Sokolov
1 sibling, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2021-07-19 16:38 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: ivan-p-sokolov, 49609
> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: ivan-p-sokolov@ya.ru, 49609@debbugs.gnu.org
> Date: Mon, 19 Jul 2021 17:53:54 +0200
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> > No, these two terms are synonyms, AFAIK. GCC doesn't emit any SGR
> > sequences that other similar applications, like Grep, don't. They are
> > just sequences to produced colors and other attributes: bold,
> > underline, etc. The intent is to make the important parts of the
> > output easier to spot.
>
> Right. Then we should just say "ANSI control sequences" here -- whether
> they're SGR or not seems irrelevant?
That'd be fine, I think.
^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode
2021-07-19 16:38 ` Eli Zaretskii
@ 2021-07-19 16:55 ` Lars Ingebrigtsen
2021-07-19 17:20 ` Eli Zaretskii
2021-07-19 21:47 ` Ivan Sokolov
0 siblings, 2 replies; 15+ messages in thread
From: Lars Ingebrigtsen @ 2021-07-19 16:55 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: ivan-p-sokolov, 49609
Eli Zaretskii <eliz@gnu.org> writes:
>> Right. Then we should just say "ANSI control sequences" here -- whether
>> they're SGR or not seems irrelevant?
>
> That'd be fine, I think.
I've now applied the patch (with some doc string changes and NEWS
entries).
I wonder whether `ansi-color-compilation-filter' should be in
`compilation-filter-hook' by default?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode
2021-07-19 16:55 ` Lars Ingebrigtsen
@ 2021-07-19 17:20 ` Eli Zaretskii
2021-07-19 21:47 ` Ivan Sokolov
1 sibling, 0 replies; 15+ messages in thread
From: Eli Zaretskii @ 2021-07-19 17:20 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: ivan-p-sokolov, 49609
> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: ivan-p-sokolov@ya.ru, 49609@debbugs.gnu.org
> Date: Mon, 19 Jul 2021 18:55:19 +0200
>
> I wonder whether `ansi-color-compilation-filter' should be in
> `compilation-filter-hook' by default?
Doesn't it depend on the compiler?
^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode
2021-07-19 15:53 ` Lars Ingebrigtsen
2021-07-19 16:38 ` Eli Zaretskii
@ 2021-07-19 20:19 ` Ivan Sokolov
1 sibling, 0 replies; 15+ messages in thread
From: Ivan Sokolov @ 2021-07-19 20:19 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 49609
Lars Ingebrigtsen <larsi@gnus.org> writes:
> Eli Zaretskii <eliz@gnu.org> writes:
>
>> No, these two terms are synonyms, AFAIK. GCC doesn't emit any SGR
>> sequences that other similar applications, like Grep, don't. They are
>> just sequences to produced colors and other attributes: bold,
>> underline, etc. The intent is to make the important parts of the
>> output easier to spot.
>
> Right. Then we should just say "ANSI control sequences" here -- whether
> they're SGR or not seems irrelevant?
SGR is one particular control sequence, the ansi-colors package does not
handle others.
^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode
2021-07-19 16:55 ` Lars Ingebrigtsen
2021-07-19 17:20 ` Eli Zaretskii
@ 2021-07-19 21:47 ` Ivan Sokolov
2021-07-20 11:35 ` Lars Ingebrigtsen
1 sibling, 1 reply; 15+ messages in thread
From: Ivan Sokolov @ 2021-07-19 21:47 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 49609
Lars Ingebrigtsen <larsi@gnus.org> writes:
> I wonder whether `ansi-color-compilation-filter' should be in
> `compilation-filter-hook' by default?
I don't think so. Well designed (machine readable) output can be parsed
and colored by compilation-mode itself, this filter is most usable in
two cases.
First, if the output is exclusively human readable and cannot be parsed,
it would be nice to have at least a native coloring. Examples: Elixir.
Second, if the output is machine redable, but the tool cannot detect
that the terminal is non-interactive and/or it does not have an option
to turn off colorization, `filter' will allow compilation-mode to
process the output.
^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode
2021-07-19 21:47 ` Ivan Sokolov
@ 2021-07-20 11:35 ` Lars Ingebrigtsen
0 siblings, 0 replies; 15+ messages in thread
From: Lars Ingebrigtsen @ 2021-07-20 11:35 UTC (permalink / raw)
To: Ivan Sokolov; +Cc: 49609
Ivan Sokolov <ivan-p-sokolov@ya.ru> writes:
>> I wonder whether `ansi-color-compilation-filter' should be in
>> `compilation-filter-hook' by default?
>
> I don't think so. Well designed (machine readable) output can be parsed
> and colored by compilation-mode itself, this filter is most usable in
> two cases.
>
> First, if the output is exclusively human readable and cannot be parsed,
> it would be nice to have at least a native coloring. Examples: Elixir.
>
> Second, if the output is machine redable, but the tool cannot detect
> that the terminal is non-interactive and/or it does not have an option
> to turn off colorization, `filter' will allow compilation-mode to
> process the output.
OK; makes sense. Thanks for the explanation.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2021-07-20 11:35 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-17 19:37 bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode Ivan Sokolov
2021-07-17 19:48 ` Ivan Sokolov
2021-07-18 0:18 ` Lars Ingebrigtsen
2021-07-18 0:45 ` Ivan Sokolov
2021-07-18 6:52 ` Eli Zaretskii
2021-07-19 13:53 ` Lars Ingebrigtsen
2021-07-19 15:45 ` Eli Zaretskii
2021-07-19 15:53 ` Lars Ingebrigtsen
2021-07-19 16:38 ` Eli Zaretskii
2021-07-19 16:55 ` Lars Ingebrigtsen
2021-07-19 17:20 ` Eli Zaretskii
2021-07-19 21:47 ` Ivan Sokolov
2021-07-20 11:35 ` Lars Ingebrigtsen
2021-07-19 20:19 ` Ivan Sokolov
2021-07-17 20:57 ` Jim Porter
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.