From f85f4b7ae62e3d05a945dcd46ead51f0a2a89a9b Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Thu, 22 Mar 2012 10:52:49 +0100 Subject: [PATCH] Rework of Editor/defaulteditor, similar to Pager/defaultpager; new env vars. The priority order is: MMHEDITOR (env) > Editor (profile) > VISUAL (env) EDITOR (env) > vi --- man/mh-profile.man5 | 14 +++++++++++++- sbr/context_read.c | 12 ++++++++++++ uip/whatnow.c | 5 ++--- uip/whatnowproc.c | 3 +-- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/man/mh-profile.man5 b/man/mh-profile.man5 index 1f35701..dc37bb9 100644 --- a/man/mh-profile.man5 +++ b/man/mh-profile.man5 @@ -134,7 +134,7 @@ man page for details about private sequences. .RE .PP .BR Editor : -/usr/bin/vi +vi .RS 5 Defines the editor to be used by the commands .BR comp , @@ -142,6 +142,8 @@ Defines the editor to be used by the commands .BR forw , and .BR repl . +This profile entry overrides the $VISUAL and $EDITOR environment variables, +but gets overridden by the $MMHEDITOR environment variabel. (profile, default: vi) .RE .PP @@ -158,6 +160,7 @@ program used by to display message bodies (or message parts) of type text/plain. This profile entry overrides the $PAGER environment variable, but gets overridden by the $MMHPAGER environment variable. +(profile, default: more) .RE .PP .BR Sendmail : @@ -683,6 +686,15 @@ This variable tells the default shell to run .RE .PP +.B $MMHEDITOR +.br +.B $VISUAL +.br +.B $EDITOR +.RS 5 +These variables (in descending priority) define the default editor to use. +.RE +.PP .B $MMHPAGER .br .B $PAGER diff --git a/sbr/context_read.c b/sbr/context_read.c index d1b22ac..5733d3f 100644 --- a/sbr/context_read.c +++ b/sbr/context_read.c @@ -174,6 +174,18 @@ context_read(void) lkfclose(ib, ctxpath); } + /* Set editor */ + if (!(cp = getenv("MMHEDITOR")) || !*cp) { + if (!(cp = context_find("editor")) || !*cp) { + if (!(cp = getenv("VISUAL")) || !*cp) { + if (!(cp = getenv("EDITOR")) || !*cp) { + cp = defaulteditor; + } + } + } + } + defaulteditor = cp; + /* Set pager */ if (!(cp = getenv("MMHPAGER")) || !*cp) { if (!(cp = context_find("pager")) || !*cp) { diff --git a/uip/whatnow.c b/uip/whatnow.c index b809ebe..bd1a3d5 100644 --- a/uip/whatnow.c +++ b/uip/whatnow.c @@ -622,10 +622,9 @@ editfile(char **ed, char **arg, char *file, int use, struct msgs *mp, if ((cp = context_find(cp)) != NULL) *ed = cp; } - } else { + } else if (!*ed) { /* set initial editor */ - if (*ed == NULL && (*ed = context_find("editor")) == NULL) - *ed = defaulteditor; + *ed = defaulteditor; } if (altmsg) { diff --git a/uip/whatnowproc.c b/uip/whatnowproc.c index 1b16e5d..fbea941 100644 --- a/uip/whatnowproc.c +++ b/uip/whatnowproc.c @@ -51,8 +51,7 @@ what_now(char *ed, int nedit, int use, char *file, char *altmsg, int dist, if (nedit) { unputenv("mheditor"); } else { - m_putenv("mheditor", ed ? ed : (ed = context_find("editor")) ? - ed : defaulteditor); + m_putenv("mheditor", ed ? ed : defaulteditor); } snprintf(buffer, sizeof(buffer), "%d", use); m_putenv("mhuse", buffer); -- 1.7.10.4