]> granicus.if.org Git - neomutt/commitdiff
Respect environment VISUAL and EDITOR variables
authorAustin Ray <austin@austinray.io>
Wed, 25 Apr 2018 10:34:04 +0000 (06:34 -0400)
committerRichard Russon <rich@flatcap.org>
Wed, 25 Apr 2018 10:34:04 +0000 (11:34 +0100)
* 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

diff --git a/init.c b/init.c
index 08e23b20bb0c204b6177c4b6e7f8da94ad98bdbd..c440b8b787ed60308723bfb2119c8f52cbdd308c 100644 (file)
--- 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