2 This is the ifdef patch by Cedric Duval <cedricduval@free.fr>.
4 This command allows to test if a feature has been compiled in before actually
5 attempting to configure / use it.
11 where <item> can be the name of a variable, function, or command.
15 ifdef imap-fetch-mail 'source ~/.mutt/imap_setup'
16 ifdef trash set trash=~/Mail/trash
18 * Patch last synced with upstream:
21 http://cedricduval.free.fr/mutt/patches/download/patch-1.5.4.cd.ifdef.1
25 - Also look for commands
26 - Use mutt_strcmp in favor of ascii_strncasecmp to compare strings.
35 +static int parse_ifdef (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
40 + memset (&token, 0, sizeof (token));
41 + mutt_extract_token (tmp, s, 0);
43 + /* is the item defined as a variable? */
44 + res = (mutt_option_index (tmp->data) != -1);
48 + for (i = 0; !res && i < MENU_MAX; i++)
50 + struct binding_t *b = km_get_table (Menus[i].value);
55 + for (j = 0; b[j].name; j++)
56 + if (!mutt_strcmp (tmp->data, b[j].name))
65 + for (i = 0; Commands[i].name; i++)
67 + if (!mutt_strcmp (tmp->data, Commands[i].name))
76 + snprintf (err->data, err->dsize, _("ifdef: too few arguments"));
79 + mutt_extract_token (tmp, s, M_TOKEN_SPACE);
83 + if (mutt_parse_rc_line (tmp->data, &token, err) == -1)
85 + mutt_error ("Erreur: %s", err->data);
94 static int parse_unignore (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
100 static int parse_unlists (BUFFER *, BUFFER *, unsigned long, BUFFER *);
101 static int parse_alias (BUFFER *, BUFFER *, unsigned long, BUFFER *);
102 static int parse_unalias (BUFFER *, BUFFER *, unsigned long, BUFFER *);
103 +static int parse_ifdef (BUFFER *, BUFFER *, unsigned long, BUFFER *);
104 static int parse_ignore (BUFFER *, BUFFER *, unsigned long, BUFFER *);
105 static int parse_unignore (BUFFER *, BUFFER *, unsigned long, BUFFER *);
106 static int parse_source (BUFFER *, BUFFER *, unsigned long, BUFFER *);
107 @@ -3401,6 +3402,7 @@
108 { "group", parse_group, 0 },
109 { "ungroup", parse_ungroup, 0 },
110 { "hdr_order", parse_list, UL &HeaderOrderList },
111 + { "ifdef", parse_ifdef, 0 },
113 { "iconv-hook", mutt_parse_hook, M_ICONVHOOK },
115 --- a/doc/manual.xml.head
116 +++ b/doc/manual.xml.head
117 @@ -3816,6 +3816,28 @@
123 +<title>Configuring features conditionnaly</title>
126 +Usage: <literal>ifdef</literal> <emphasis>item</emphasis> <emphasis>command</emphasis>
130 +This command allows to test if a feature has been compiled in, before
131 +actually executing the command. Item can be either the name of a
132 +function, variable, or command. Example:
137 +ifdef imap_keepalive 'source ~/.mutt/imap_setup'
144 <title>Removing hooks</title>
149 +patch-1.5.13.cd.ifdef.2