From: Richard Russon Date: Tue, 2 Aug 2016 09:17:01 +0000 (+0100) Subject: docs: nested-if X-Git-Tag: neomutt-20160822~24^2~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8fcb1be882b1b7625c90118605d33ee8daf28927;p=neomutt docs: nested-if --- diff --git a/doc/manual.xml.head b/doc/manual.xml.head index f2d23d98f..3f6e7a72b 100644 --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -4630,6 +4630,18 @@ If the value of sequence_char is non-zero, else_string will be expanded. + +The conditional sequences can also be nested by using the %< and > +operators. The %? notation can still be used but requires quoting. For example: + + + +%<x?true&false> +%<x?%<y?%<z?xyz&xy>&x>&none> + + +For more examples, see + @@ -10124,6 +10136,226 @@ bind index <esc>L limit-current-thread + + Nested If Patch + Allow complex nested conditions in format strings + + + Patch + + + To check if Mutt supports Nested If, look for + patch-nested-if in the mutt version. + See: . + + + + Dependencies: + mutt-1.6.2 + + + This patch is part of the NeoMutt Project. + + + + Introduction + + + Mutt's format strings can contain embedded if-then-else conditions. + They are of the form: + + + +%?VAR?TRUE&FALSE? + + + + If the variable VAR has a value greater than zero, + print the TRUE string, otherwise print the + FALSE string. + + + + e.g. %?S?Size: %S&Empty? + + + Which can be read as: + + +if (%S > 0) { + print "Size: %S" +} else { + print "Empty" +} + + + + These conditions are useful, but in Mutt they cannot be nested + within one another. This patch uses the notation + %<VAR?TRUE&FALSE> and allows them to be nested. + + + + The %<...> notation was used to format the + current local time. but that's not really very useful since mutt + has no means of refreshing the screen periodically. + + + + A simple nested condition might be: + (Some whitespace has been introduced for clarity) + + + +%<x? %<y? XY & X > & %<y? Y & NONE > > Conditions + %<y? XY & X > x>0 + XY x>0,y>0 + X x>0,y=0 + + + +%<x? %<y? XY & X > & %<y? Y & NONE > > Conditions + %<y? Y & NONE > x=0 + Y x=0,y>0 + NONE x=0,y=0 + + + Equivalent to: + + +if (x > 0) { + if (y > 0) { + print 'XY' + } else { + print 'X' + } +} else { + if (y > 0) { + print 'Y' + } else { + print 'NONE' + } +} + + + Examples: + + +set index_format='%4C %Z %{%b %d} %-25.25n %s%> %<M?%M Msgs &%<l?%l Lines&%c Bytes>>' + + + +if a thread is folded + display the number of messages (%M) +else if we know how many lines in the message + display lines in message (%l) +else + display the size of the message in bytes (%c) + + + +set index_format='%4C %Z %{%b %d} %-25.25n %<M?[%M] %s&%s%* %<l?%l&%c>>' + + + +if a thread is folded + display the number of messages (%M) + display the subject (%s) +else if we know how many lines in the message + display lines in message (%l) +else + display the size of the message in bytes (%c) + + + + + + Variables + + The nested-if patch doesn't have any config of its own. + It modifies the behavior of the format strings. + + + + + + + Muttrc + +# Example Mutt config file for the 'nested-if' feature. + +# This patch uses the format: '%<VAR?TRUE&FALSE>' for conditional +# format strings that can be nested. + +# Example 1 +# if a thread is folded +# display the number of messages (%M) +# else if we know how many lines in the message +# display lines in message (%l) +# else display the size of the message in bytes (%c) +set index_format='%4C %Z %{%b %d} %-25.25n %s%> %<M?%M Msgs &%<l?%l Lines&%c Bytes>>' + +# Example 2 +# if a thread is folded +# display the number of messages (%M) +# display the subject (%s) +# else if we know how many lines in the message +# display lines in message (%l) +# else +# display the size of the message in bytes (%c) +set index_format='%4C %Z %{%b %d} %-25.25n %<M?[%M] %s&%s%* %<l?%l&%c>>' + +# vim: syntax=muttrc + + + + + See Also + + + NeoMutt Project + cond-date patch + $index_format + $status_format + + + + + Known Bugs + + Patch overwrites $<fmt> handler in $index_format + + + + + Credits + + David Champion dgc@uchicago.edu + Richard Russon rich@flatcap.org + + + + Sidebar Overview of mailboxes diff --git a/doc/muttrc.nested-if b/doc/muttrc.nested-if new file mode 100644 index 000000000..aee76eb3e --- /dev/null +++ b/doc/muttrc.nested-if @@ -0,0 +1,24 @@ +# Example Mutt config file for the 'nested-if' feature. + +# This patch uses the format: '%' for conditional +# format strings that can be nested. + +# Example 1 +# if a thread is folded +# display the number of messages (%M) +# else if we know how many lines in the message +# display lines in message (%l) +# else display the size of the message in bytes (%c) +set index_format='%4C %Z %{%b %d} %-25.25n %s%> %>' + +# Example 2 +# if a thread is folded +# display the number of messages (%M) +# display the subject (%s) +# else if we know how many lines in the message +# display lines in message (%l) +# else +# display the size of the message in bytes (%c) +set index_format='%4C %Z %{%b %d} %-25.25n %>' + +# vim: syntax=muttrc