Discussion:
Color headers in pager based on message patterns
Scott Kostyshak
2018-02-07 06:05:25 UTC
Permalink
I would like to color all header lines in the pager if a message pattern
matches.

As an example, I can use the following to color the index if a message
was sent to me and not sent to a list:

color index yellow black ~p!~l

But I cannot do the following:

color header yellow black ~p!~l

to color all headers in the pager if a message was sent to me and not
sent to a list. This is understandable, as the pattern is matched
against each header.

As for why I would like to do this, I rarely look at the index. I
configure mutt to go directly to the pager, so that I focus on one email
at a time. However, I find the message pattern matching useful so I
would like to be able to use them to color headers in the pager.

Is it possible to use the message pattern mechanism to color headers
showing in the pager?

Thanks,

Scott
--
Scott Kostyshak
Assistant Professor of Economics
University of Florida
https://people.clas.ufl.edu/skostyshak/
Cameron Simpson
2018-02-07 22:00:33 UTC
Permalink
Post by Scott Kostyshak
I would like to color all header lines in the pager if a message pattern
matches.
As an example, I can use the following to color the index if a message
color index yellow black ~p!~l
color header yellow black ~p!~l
to color all headers in the pager if a message was sent to me and not
sent to a list. This is understandable, as the pattern is matched
against each header.
As for why I would like to do this, I rarely look at the index. I
configure mutt to go directly to the pager, so that I focus on one email
at a time. However, I find the message pattern matching useful so I
would like to be able to use them to color headers in the pager.
Is it possible to use the message pattern mechanism to color headers
showing in the pager?
Yes, you need to be a little indirect.

My setup has these lines:

color header $colour_hl1 default "^(from|subject):"
color header $colour_hl1 default "^(x-spam-status):"

Where $colour_hl1 happens to be cyan. What you want to do is, instead of
defining your header rules once, define them per message via a message-hook.
Example (untested):

message-hook . 'set my_hdr_colour=green'
message-hook ~p!~l 'set my_hdr_colour=yellow'
message-hook . 'color header $my_hdr_colour default'

so that a colour is chosen per message, then applied to your settings.

Cheers,
Cameron Simpson <***@cskk.id.au> (formerly ***@zip.com.au)
Scott Kostyshak
2018-02-08 01:35:20 UTC
Permalink
Post by Cameron Simpson
Post by Scott Kostyshak
I would like to color all header lines in the pager if a message pattern
matches.
As an example, I can use the following to color the index if a message
color index yellow black ~p!~l
color header yellow black ~p!~l
to color all headers in the pager if a message was sent to me and not
sent to a list. This is understandable, as the pattern is matched
against each header.
As for why I would like to do this, I rarely look at the index. I
configure mutt to go directly to the pager, so that I focus on one email
at a time. However, I find the message pattern matching useful so I
would like to be able to use them to color headers in the pager.
Is it possible to use the message pattern mechanism to color headers
showing in the pager?
Yes, you need to be a little indirect.
color header $colour_hl1 default "^(from|subject):"
color header $colour_hl1 default "^(x-spam-status):"
Where $colour_hl1 happens to be cyan. What you want to do is, instead of
defining your header rules once, define them per message via a message-hook.
message-hook . 'set my_hdr_colour=green'
message-hook ~p!~l 'set my_hdr_colour=yellow'
message-hook . 'color header $my_hdr_colour default'
so that a colour is chosen per message, then applied to your settings.
Cheers,
I think that does the trick! I had to change the last of the three hooks
to be the following (note the dot at the end):

message-hook . 'color header $my_hdr_colour default .'

Thank you very much for taking the time to understand what I was trying
to achieve, and for the helpful solution, Cameron.

Best,

Scott
--
Scott Kostyshak
Assistant Professor of Economics
University of Florida
https://people.clas.ufl.edu/skostyshak/
Cameron Simpson
2018-02-08 02:06:19 UTC
Permalink
Post by Scott Kostyshak
Post by Cameron Simpson
message-hook . 'set my_hdr_colour=green'
message-hook ~p!~l 'set my_hdr_colour=yellow'
message-hook . 'color header $my_hdr_colour default'
so that a colour is chosen per message, then applied to your settings.
I think that does the trick! I had to change the last of the three hooks
message-hook . 'color header $my_hdr_colour default .'
Ah, yes.
Post by Scott Kostyshak
Thank you very much for taking the time to understand what I was trying
to achieve, and for the helpful solution, Cameron.
Glad to be of service,
Cameron Simpson <***@cskk.id.au> (formerly ***@zip.com.au)

All the doors in this ship have nice sunny dispositions. It is their
pleasure to open for you, and their satisfaction to close with the knowledge
of a job well done. - Marvin _The Hitchhiker's Guide to the Galaxy_
Loading...