# vim:ft=diff: This is the ifdef patch by Cedric Duval . This command allows to test if a feature has been compiled in before actually attempting to configure / use it. Syntax: ifdef where can be the name of a variable, function, or command. Examples: ifdef imap-fetch-mail 'source ~/.mutt/imap_setup' ifdef trash set trash=~/Mail/trash * Patch last synced with upstream: - Date: 2007-02-15 - File: http://cedricduval.free.fr/mutt/patches/download/patch-1.5.4.cd.ifdef.1 * Changes made: - Updated to 1.5.13 - Also look for commands - Use mutt_strcmp in favor of ascii_strncasecmp to compare strings. == END PATCH --- a/init.c +++ b/init.c @@ -635,6 +635,65 @@ static int remove_from_rx_list (RX_LIST return (rv); } +static int parse_ifdef (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err) +{ + int i, j, res = 0; + BUFFER token; + + memset (&token, 0, sizeof (token)); + mutt_extract_token (tmp, s, 0); + + /* is the item defined as a variable? */ + res = (mutt_option_index (tmp->data) != -1); + + /* a function? */ + if (!res) + for (i = 0; !res && i < MENU_MAX; i++) + { + struct binding_t *b = km_get_table (Menus[i].value); + + if (!b) + continue; + + for (j = 0; b[j].name; j++) + if (!mutt_strcmp (tmp->data, b[j].name)) + { + res = 1; + break; + } + } + + /* a command? */ + if (!res) + for (i = 0; Commands[i].name; i++) + { + if (!mutt_strcmp (tmp->data, Commands[i].name)) + { + res = 1; + break; + } + } + + if (!MoreArgs (s)) + { + snprintf (err->data, err->dsize, _("ifdef: too few arguments")); + return (-1); + } + mutt_extract_token (tmp, s, M_TOKEN_SPACE); + + if (res) + { + if (mutt_parse_rc_line (tmp->data, &token, err) == -1) + { + mutt_error ("Erreur: %s", err->data); + FREE (&token.data); + return (-1); + } + FREE (&token.data); + } + return 0; +} + static int parse_unignore (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) { do --- a/init.h +++ b/init.h @@ -3413,6 +3413,7 @@ static int parse_lists (BUFFER *, BUFFER static int parse_unlists (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_alias (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_unalias (BUFFER *, BUFFER *, unsigned long, BUFFER *); +static int parse_ifdef (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_ignore (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_unignore (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_source (BUFFER *, BUFFER *, unsigned long, BUFFER *); @@ -3463,6 +3464,7 @@ struct command_t Commands[] = { { "group", parse_group, 0 }, { "ungroup", parse_ungroup, 0 }, { "hdr_order", parse_list, UL &HeaderOrderList }, + { "ifdef", parse_ifdef, 0 }, #ifdef HAVE_ICONV { "iconv-hook", mutt_parse_hook, M_ICONVHOOK }, #endif --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -4087,6 +4087,28 @@ considered to be an executable program f + + +Configuring features conditionally + + +Usage: ifdef item command + + + +This command allows to test if a feature has been compiled in, before +actually executing the command. Item can be either the name of a +function, variable, or command. Example: + + + + +ifdef imap_keepalive 'source ~/.mutt/imap_setup' + + + + + Removing Hooks