From: Ken Hornstein Date: Tue, 15 Jan 2013 20:30:17 +0000 (-0500) Subject: Support the VISUAL and EDITOR environment variables, and remove support X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/0cf508d41a7198d5f4f399de72f31468f5417892?hp=--cc Support the VISUAL and EDITOR environment variables, and remove support for configuring a default editor with --with-editor. --- 0cf508d41a7198d5f4f399de72f31468f5417892 diff --git a/Makefile.am b/Makefile.am index 55886bb9..0fbf441a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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' >> $@ diff --git a/config/config.c b/config/config.c index f78c1478..02265c0a 100644 --- a/config/config.c +++ b/config/config.c @@ -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). diff --git a/configure.ac b/configure.ac index 15f509f7..3bb692ef 100644 --- a/configure.ac +++ b/configure.ac @@ -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"], diff --git a/docs/pending-release-notes b/docs/pending-release-notes index 63d38bae..9b280927 100644 --- a/docs/pending-release-notes +++ b/docs/pending-release-notes @@ -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 5bf279ab..2cd546b1 100644 --- 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 09683efb..3b91e2c3 100644 --- a/h/nmh.h +++ b/h/nmh.h @@ -66,5 +66,6 @@ */ #define DEFAULT_PAGER "more" +#define DEFAULT_EDITOR "vi" #include diff --git a/h/prototypes.h b/h/prototypes.h index d62fb7a1..443479f6 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -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 *); diff --git a/man/mh-profile.man b/man/mh-profile.man index 8d77900d..d7b03841 100644 --- a/man/mh-profile.man +++ b/man/mh-profile.man @@ -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 index 00000000..6c285da9 --- /dev/null +++ b/sbr/geteditor.c @@ -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 +#include + +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); +} diff --git a/uip/whatnowproc.c b/uip/whatnowproc.c index fc8783d0..05dc8ff3 100644 --- a/uip/whatnowproc.c +++ b/uip/whatnowproc.c @@ -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); diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index 86ff81df..9a9fec1b 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -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) {