-
Notifications
You must be signed in to change notification settings - Fork 51
/
README.nested-if
125 lines (87 loc) · 2.94 KB
/
README.nested-if
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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.
Dependencies
* mutt-1.5.24
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.
See Also
--------
* NeoMutt project
* cond-date patch
* $index_format
* $status_format
Known Bugs
----------
Patch overwrites $<fmt> handler in
$index_format
Credits
-------
* David Champion <[email protected]>
* Richard Russon <[email protected]>