dgc / Mutt custom message-tagging
dgc / Mutt custom message-tagging

The "X-Label" patch provides two new expanders for the $index_format configuration variable, and a new pattern-matching selector. %y and %Y expand (in slightly different ways) to the value of a message's X-Label: header field, and ~y performs regular-expression matching on the value of a message's X-Label: field. The following texts are from messages posted to the Mutt developers' mailing list:

Message 1:
From: David Champion
Subject: Three patches: kerberos, keymap_defs.h, hdr_format
To: The Mutt Developers List
Date: Thu, 23 Mar 2000 04:10:58 -0600
Message-ID: <20000323041058.B20382@smack.uchicago.edu>

...
           fluff, but it's useful to me.  The patch makes
           parse.c:mutt_read_rfc822_header() cache any X-Label: header
           present in a message's header block.  %y then expands to the
           value of that header.  I use this for marking mailing
           lists.  (The "subscribe" and "lists" directives are not
           really what I want; I want procmail to be able to mark
           message lists or categories however I choose, and mutt to
           label messages accordingly.)  I use this hdr_format string:
                "%Z %4C %[%y%m%d] %-18.18F [%4c] %?y?[%y] ?%s%| " This
           makes the X-Label label show in brackets iff it is present,
           and the message is not a descendent in a threaded tree
           diagram.  (If it is, or the label is absent, "%?y?[%y] ?"
           expands to nothing.)

Message 2:
From: David Champion
Subject: Re: X-Label and %y
To: The Mutt Developers List
References: <20000323041058.B20382@smack.uchicago.edu>
	<20000323041058.B20382@smack.uchicago.edu>
	<20000323115532.A20372@sobolev.rhein.de> <20000323195733.D10666@chamber.dna.fi>
	<20000324012154.C28736@faveve.uni-stuttgart.de>
	<20000323194020.A4437@smack.uchicago.edu>
	<20000324084827.E28519@sobolev.rhein.de>

...
+ %y expands to the X-Label's value, no matter what.
+ %?y tests true if X-Label is present — if %y would have value.
+ %Y expands to the X-Label if X-Label exists, and any of these is true:
        1. this message is unthreaded
        2. this message is at the top of its thread
        3. a. this message is its parent's first child, and its parent has
              no X-Label
        3. b. this message is its parent's first child, and its parent's
              X-Label is different
        4. a. this message is not its parent's first child, and its previous
              sibling has no X-Label
        4. b. this message is not its parent's first child, and its previous
              sibling's X-Label is different
+ %?Y tests true if %Y would have value
+ ~y just regex-matches the X-Label's value

As Aaron Schwab noted, it's hard to tell a %Y with no X-Label from a %Y
whose predecessor's X-Label is the same.  All I can say is:
"%y?%Y&none?".

Here are some examples I threw together.  I wasn't sure where in the
docs they might fit.  These are all variations on the default
$index_format.

  ## If X-Label is present, show it in [brackets], regardless of tree view.
  ##    Warning!  This will mess up tree diagramming characters!
  #set index_format="%4C %Z %{%b %d} %-15.15L (%4l) [%y] %s"

  ## Same thing, but always use up exactly 8 columns for the label
  #set index_format="%4C %Z %{%b %d} %-15.15L (%4l) [%-8.8y] %s"

  ## Same thing, but fill the gap with dashes if no X-Label is present
  #set index_format="%4C %Z %{%b %d} %-15.15L (%4l) [%?y?%-8.8y&--------?] %s"

  ## If X-Label is present, show any X-Label that is at the top of a tree,
  ##    or which is different from its predecessor's X-Label.  Use a
  ##    fixed-width field to preserve sanity of tree diagrams.
  #set index_format="%4C %Z %{%b %d} %-15.15L (%4l) %?y?[%-5.5Y] ?%s"

  ## If X-Label is present and different from its predecessor's X-Label,
  ##    show its first 5 characters, left-justified in a 5-column field,
  ##    enclosed in [brackets].  Otherwise, fill an equivalent span with
  ##    whitespace.
  #set index_format="%4C %Z %{%b %d} %-15.15L (%4l) %?Y?[%-5.5Y] & %-5.0Z  ?%s"

  ## Same as previous, but do not respect tree diagrams at all.  Show
  ##    X-Labels that are different from their predecessors in the tree
  ##    view, or which are not tree members, and do not consume any space
  ##    otherwise.  This is nice when the X-labels are not expected to
  ##    vary within a tree (e.g., for mailing lists).
  #set index_format="%4C %Z %{%b %d} %-15.15L (%4l) %?Y?[%Y] ?%s"


$Id: %y.html4,v 1.2 2003/10/16 19:34:47 dgc Exp $
Mail: dgc@uchicago.edu