]> diplodocus.org Git - nmh/commitdiff
Support the VISUAL and EDITOR environment variables, and remove support
authorKen Hornstein <kenh@pobox.com>
Tue, 15 Jan 2013 20:30:17 +0000 (15:30 -0500)
committerKen Hornstein <kenh@pobox.com>
Tue, 15 Jan 2013 20:30:17 +0000 (15:30 -0500)
for configuring a default editor with --with-editor.

Makefile.am
config/config.c
configure.ac
docs/pending-release-notes
h/mh.h
h/nmh.h
h/prototypes.h
man/mh-profile.man
sbr/geteditor.c [new file with mode: 0644]
uip/whatnowproc.c
uip/whatnowsbr.c

index 55886bb9494bd0c42c1393e8effd1f7a91bfd8dd..0fbf441a49515ab0036d56d0da1b7b7cce21d002 100644 (file)
@@ -485,7 +485,8 @@ sbr_libmh_a_SOURCES = sbr/addrsbr.c sbr/ambigsw.c sbr/atooi.c sbr/base64.c \
                      sbr/folder_free.c sbr/folder_pack.c \
                      sbr/folder_read.c sbr/folder_realloc.c sbr/gans.c \
                      sbr/getans.c sbr/getanswer.c sbr/getarguments.c \
-                     sbr/getcpy.c sbr/getfolder.c sbr/getpass.c \
+                     sbr/getcpy.c sbr/geteditor.c sbr/getfolder.c \
+                     sbr/getpass.c \
                      sbr/fmt_addr.c sbr/fmt_compile.c sbr/fmt_new.c \
                      sbr/fmt_rfc2047.c sbr/fmt_scan.c sbr/lock_file.c \
                      sbr/m_atoi.c sbr/m_backup.c sbr/m_convert.c \
@@ -511,8 +512,7 @@ sbr_libmh_a_SOURCES = sbr/addrsbr.c sbr/ambigsw.c sbr/atooi.c sbr/base64.c \
 sbr_libmh_a_CPPFLAGS = -I./sbr -DNMHETCDIR='"$(sysconfdir)"' \
                -DMAILSPOOL='"$(mailspool)"' \
                -DSENDMAILPATH='"$(sendmailpath)"' -DNMHBINDIR='"$(bindir)"' \
-               -DNMHLIBDIR='"$(libdir)"' \
-               -DDEFAULT_EDITOR='"$(editorpath)"'
+               -DNMHLIBDIR='"$(libdir)"'
 
 sbr_libdtimep_a_SOURCES = sbr/dtimep.l
 sbr_libdtimep_a_CFLAGS = $(sbr_libmh_a_CPPFLAGS) \
@@ -541,7 +541,6 @@ man/man.sed: Makefile
        @echo 's,%mandir%,$(mandir),g' >> $@
        @echo 's,%mailspool%,$(mailspool),g' >> $@
        @echo 's,%sendmailpath%,$(sendmailpath),g' >> $@
-       @echo 's,%default_editor%,$(editorpath),g' >> $@
        @echo 's,%manext1%,$(manext1),g' >> $@
        @echo 's,%manext5%,$(manext5),g' >> $@
        @echo 's,%manext7%,$(manext7),g' >> $@
index f78c1478ef112a35e197c12a7574bcb790c844bb..02265c0a6befb8457041cec19a3f4f7d93162cef 100644 (file)
@@ -318,14 +318,6 @@ char *whatnowproc = nmhbindir (/whatnow);
 
 char *whomproc = nmhbindir (/whom);
 
-/*
- * This is the editor invoked by the various message
- * composition programs.  It SHOULD be a full screen
- * editor, such as vi or emacs, but any editor will work.
- */
-
-char *defaulteditor = DEFAULT_EDITOR;
-
 /* 
  * This is the global nmh alias file.  It is somewhat obsolete, since
  * global aliases should be handled by the Mail Transport Agent (MTA).
index 15f509f7ad79b9ee548e653676b3999ce77581f5..3bb692ef6763ac529d421aee07c03a28e94d53cb 100644 (file)
@@ -54,12 +54,6 @@ AS_IF([test x"$with_tls" != x -a x"$with_tls" != x"no"],[
       AC_DEFINE([TLS_SUPPORT], [1], [Support TLS for session encryption.])dnl
       tls_support=yes],[tls_support=no])
 
-dnl What should be the default editor?
-AC_ARG_WITH([editor],
-  AS_HELP_STRING([--with-editor=EDITOR],[specify the default editor]))
-
-AS_IF([test -n "$with_editor"], [editorpath="$with_editor"])
-
 dnl Set the backup prefix
 AC_ARG_WITH([hash-backup],
   AS_HELP_STRING([--with-hash-backup],[use # as the backup prefix (default: ,)]))
@@ -317,15 +311,6 @@ dnl Look for `sendmail'
 pathtmp=/usr/lib:/usr/sbin:/usr/etc:/usr/ucblib:/usr/bin:/bin
 AC_PATH_PROG([sendmailpath], [sendmail], [/usr/sbin/sendmail], [$pathtmp])
 
-dnl Look for `vi'
-pathtmp=/usr/bin:/bin:/usr/ucb:/usr/local/bin
-AC_PATH_PROG([vipath], [vi], [/bin/vi], [$pathtmp])
-
-dnl If editor is not specified yet,
-dnl then use `vi' as the default.
-AS_IF([test -z "$editorpath"], [editorpath="$vipath"])
-AC_SUBST([editorpath])dnl
-
 dnl Cygwin FAT filesystems do not support hard links.  So default to
 dnl cp instead, even if running on an NTFS or other filesystem.
 AS_CASE(["$host_os"],
index 63d38bae188319765d91cf23e8ed693aa8350d67..9b280927656e8c7494423ea1fd8a8271a8cd5b5b 100644 (file)
@@ -32,6 +32,8 @@ NEW FEATURES
 - inc(1) now supports a -port switch to specify the port used by the
   POP server.
 - pick(1) now decodes MIME-encoded header fields before searching.
+- The VISUAL and EDITOR environment variables are now supported as fallbacks
+  if the user does not configure an editor entry in their profile.
 
 
 ----------------------------
@@ -74,6 +76,8 @@ OBSOLETE/DEPRECATED FEATURES
 - The configure flag --with-pager has been removed; the default pager
   is now hardcoded as "more".  Users are still free to override the
   default using the PAGER environment variable or entries in .mh_profile.
+- The configure flag --with-editor has been removed; the fallback editor
+  if none is configured is "vi".
 
 ---------
 BUG FIXES
diff --git a/h/mh.h b/h/mh.h
index 5bf279abe6b4cbf34b0506180e1bd6eef955ee4f..2cd546b11a03a8bafe5277ae1938171bdf2f6215 100644 (file)
--- a/h/mh.h
+++ b/h/mh.h
@@ -367,7 +367,6 @@ extern char *catproc;
 extern char *components;
 extern char *context;
 extern char *current;
-extern char *defaulteditor;
 extern char *defaultfolder;
 extern char *digestcomps;
 extern char *distcomps;
diff --git a/h/nmh.h b/h/nmh.h
index 09683efbb0590042082a87b065bd2fedc10c1366..3b91e2c3ad6e5e76acf06863dad240af52896c92 100644 (file)
--- a/h/nmh.h
+++ b/h/nmh.h
@@ -66,5 +66,6 @@
  */
 
 #define DEFAULT_PAGER "more"
+#define DEFAULT_EDITOR "vi"
 
 #include <signal.h>
index d62fb7a1f585a0dc90bcb68fe5b7a3ce4a15e410..443479f67c0b3fd8f14d4ee16aa14321263a987c 100644 (file)
@@ -66,6 +66,7 @@ int getanswer (char *);
 char **getarguments (char *, int, char **, int);
 char *get_charset(void);
 char *getcpy (char *);
+char *get_default_editor(void);
 char *getfolder(int);
 int lkclose(int, char*);
 int lkfclose(FILE *, char *);
index 8d77900d8b3193759cbd7f59f809c1b1414cbdc0..d7b03841874a605ed6646793ec44ed2c54070769 100644 (file)
@@ -145,7 +145,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 ,
@@ -153,7 +153,9 @@ Defines the editor to be used by the commands
 .BR forw ,
 and
 .BR repl .
-(profile, default: %default_editor%)
+If not set in profile the value will be taken from the VISUAL and
+EDITOR environment variables.
+(profile, default: vi)
 .RE
 .PP
 .BR automimeproc :
diff --git a/sbr/geteditor.c b/sbr/geteditor.c
new file mode 100644 (file)
index 0000000..6c285da
--- /dev/null
@@ -0,0 +1,29 @@
+
+/*
+ * geteditor.c -- Determine the default editor to use
+ *
+ * This code is Copyright (c) 2013, by the authors of nmh.  See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
+ */
+
+#include <h/mh.h>
+#include <h/utils.h>
+
+static char *default_editor = NULL;
+
+char *
+get_default_editor(void)
+{
+    char *str;
+
+    if (default_editor)
+       return default_editor;
+
+    if (!(str = context_find("editor")) && !(str = getenv("VISUAL")) &&
+       !(str = getenv("EDITOR"))) {
+       str = DEFAULT_EDITOR;
+    }
+
+    return (default_editor = str);
+}
index fc8783d0b8df0267a9e3c84cf0c3f15f3c4c5719..05dc8ff3f67bcb896d86201a1fe88f224f038304 100644 (file)
@@ -55,8 +55,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 : (ed = get_default_editor()));
     }
     snprintf (buffer, sizeof(buffer), "%d", use);
     m_putenv ("mhuse", buffer);
index 86ff81df035adbc90bd090de4225a94e9a4524cb..9a9fec1b4f3ee4709695112ba9bd624a44251c9d 100644 (file)
@@ -665,8 +665,8 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
        }
     } else {
        /* set initial editor */
-       if (*ed == NULL && (*ed = context_find ("editor")) == NULL)
-           *ed = defaulteditor;
+       if (*ed == NULL)
+           *ed = get_default_editor();
     }
 
     if (altmsg) {