From e215b591fedbe2cede32f8be97166b4b34d33373 Mon Sep 17 00:00:00 2001 From: Austin Ray Date: Wed, 25 Apr 2018 06:34:04 -0400 Subject: [PATCH] Respect environment VISUAL and EDITOR variables * Respect environment VISUAL and EDITOR variables Commit 0ef255e repositioned where Neomutt set its standard defaults in init.c to after the logic for loading the VISUAL and EDITOR variables. As a result, Neomutt overrides the values it retrieved from the environment with the ones from the configuration file. This matches the desired precedence of config->environment->code. However, if `editor` is not set in the configuration file then Neomutt does not retrieve EDITOR and VISUAL again. This results in Neomutt falling back to the editor specified in the code. Thus the precedence is config->code. This commit returns the standard default set loop to its initial location allowing for the environment variables to be usable. Fixes #1162 --- init.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/init.c b/init.c index 08e23b20b..c440b8b78 100644 --- a/init.c +++ b/init.c @@ -3905,11 +3905,22 @@ int mutt_init(int skip_sys_rc, struct ListHead *commands) Matches = mutt_mem_calloc(MatchesListsize, sizeof(char *)); + /* Set standard defaults */ + for (int i = 0; MuttVars[i].name; i++) + { + set_default(&MuttVars[i]); + restore_default(&MuttVars[i]); + } + /* "$mailcap_path" precedence: config file, environment, code */ - MailcapPath = mutt_str_strdup(mutt_str_getenv("MAILCAPS")); + const char *env_mc = mutt_str_getenv("MAILCAPS"); + if (env_mc) + MailcapPath = mutt_str_strdup(env_mc); /* "$tmpdir" precedence: config file, environment, code */ - Tmpdir = mutt_str_strdup(mutt_str_getenv("TMPDIR")); + const char *env_tmp = mutt_str_getenv("TMPDIR"); + if (env_tmp) + Tmpdir = mutt_str_strdup(env_tmp); /* "$visual", "$editor" precedence: config file, environment, code */ const char *env_ed = mutt_str_getenv("VISUAL"); @@ -3921,13 +3932,6 @@ int mutt_init(int skip_sys_rc, struct ListHead *commands) mutt_str_replace(&Visual, env_ed); } - /* Set standard defaults */ - for (int i = 0; MuttVars[i].name; i++) - { - set_default(&MuttVars[i]); - restore_default(&MuttVars[i]); - } - CurrentMenu = MENU_MAIN; #ifndef LOCALES_HACK -- 2.50.1