summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-05-13 15:59:50 +0200
committerBram Moolenaar <Bram@vim.org>2018-05-13 15:59:50 +0200
commit137374fd6538cf9dee0cb22907728d8fdecb5832 (patch)
tree300180a61a2e24db7bd4a085f99c710988b4632b
parent8b62e31003693fee4b288e7aea49170f032aeef3 (diff)
patch 8.0.1832: cannot use :unlet for an environment variablev8.0.1832
Problem: Cannot use :unlet for an environment variable. Solution: Make it work. Use unsetenv() if available. (Ken Takata, closes #2855)
-rw-r--r--runtime/doc/eval.txt8
-rwxr-xr-xsrc/auto/configure2
-rw-r--r--src/config.h.in1
-rw-r--r--src/configure.ac2
-rw-r--r--src/eval.c14
-rw-r--r--src/misc1.c11
-rw-r--r--src/proto/misc1.pro1
-rw-r--r--src/testdir/test_unlet.vim24
-rw-r--r--src/version.c2
9 files changed, 63 insertions, 2 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 050b48960a..730a5d11c4 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -9939,6 +9939,14 @@ This does NOT work: >
variables are automatically deleted when the function
ends.
+:unl[et] ${env-name} ... *:unlet-environment* *:unlet-$*
+ Remove environment variable {env-name}.
+ Can mix {name} and ${env-name} in one :unlet command.
+ No error message is given for a non-existing
+ variable, also without !.
+ If the system does not support deleting an environment
+ variable, it is made emtpy.
+
:lockv[ar][!] [depth] {name} ... *:lockvar* *:lockv*
Lock the internal variable {name}. Locking means that
it can no longer be changed (until it is unlocked).
diff --git a/src/auto/configure b/src/auto/configure
index e65884c80a..1628b940e3 100755
--- a/src/auto/configure
+++ b/src/auto/configure
@@ -12609,7 +12609,7 @@ for ac_func in fchdir fchown fchmod fsync getcwd getpseudotty \
getpgid setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
sigprocmask sigvec strcasecmp strerror strftime stricmp strncasecmp \
strnicmp strpbrk strtol tgetent towlower towupper iswupper \
- usleep utime utimes mblen ftruncate
+ usleep utime utimes mblen ftruncate unsetenv
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/src/config.h.in b/src/config.h.in
index 7d6122058f..00117cf8ca 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -211,6 +211,7 @@
#undef HAVE_TOWLOWER
#undef HAVE_TOWUPPER
#undef HAVE_ISWUPPER
+#undef HAVE_UNSETENV
#undef HAVE_USLEEP
#undef HAVE_UTIME
#undef HAVE_BIND_TEXTDOMAIN_CODESET
diff --git a/src/configure.ac b/src/configure.ac
index cfc3b1be1b..107c170ecb 100644
--- a/src/configure.ac
+++ b/src/configure.ac
@@ -3709,7 +3709,7 @@ AC_CHECK_FUNCS(fchdir fchown fchmod fsync getcwd getpseudotty \
getpgid setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
sigprocmask sigvec strcasecmp strerror strftime stricmp strncasecmp \
strnicmp strpbrk strtol tgetent towlower towupper iswupper \
- usleep utime utimes mblen ftruncate)
+ usleep utime utimes mblen ftruncate unsetenv)
AC_FUNC_FSEEKO
dnl define _LARGE_FILES, _FILE_OFFSET_BITS and _LARGEFILE_SOURCE when
diff --git a/src/eval.c b/src/eval.c
index b787474d10..2ba9e82a80 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -2758,6 +2758,20 @@ ex_unletlock(
do
{
+ if (*arg == '$')
+ {
+ char_u *name = ++arg;
+
+ if (get_env_len(&arg) == 0)
+ {
+ EMSG2(_(e_invarg2), name - 1);
+ return;
+ }
+ vim_unsetenv(name);
+ arg = skipwhite(arg);
+ continue;
+ }
+
/* Parse the name and find the end. */
name_end = get_lval(arg, NULL, &lv, TRUE, eap->skip || error, 0,
FNE_CHECK_START);
diff --git a/src/misc1.c b/src/misc1.c
index 6c77f4b0d2..1ab55f0862 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -4479,6 +4479,17 @@ remove_tail(char_u *p, char_u *pend, char_u *name)
return pend;
}
+ void
+vim_unsetenv(char_u *var)
+{
+#ifdef HAVE_UNSETENV
+ unsetenv((char *)var);
+#else
+ mch_setenv((char *)var, "", 0);
+#endif
+}
+
+
/*
* Our portable version of setenv.
*/
diff --git a/src/proto/misc1.pro b/src/proto/misc1.pro
index 4e299e5f9a..4b613e6b1a 100644
--- a/src/proto/misc1.pro
+++ b/src/proto/misc1.pro
@@ -60,6 +60,7 @@ void expand_env(char_u *src, char_u *dst, int dstlen);
void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, int esc, int one, char_u *startstr);
char_u *vim_getenv(char_u *name, int *mustfree);
void vim_setenv(char_u *name, char_u *val);
+void vim_unsetenv(char_u *name);
char_u *get_env_name(expand_T *xp, int idx);
char_u *get_users(expand_T *xp, int idx);
int match_user(char_u *name);
diff --git a/src/testdir/test_unlet.vim b/src/testdir/test_unlet.vim
index c20b0beb7f..6636f6d66b 100644
--- a/src/testdir/test_unlet.vim
+++ b/src/testdir/test_unlet.vim
@@ -21,3 +21,27 @@ endfunc
func Test_unlet_fails()
call assert_fails('unlet v:["count"]', 'E46:')
endfunc
+
+func Test_unlet_env()
+ let envcmd = has('win32') ? 'set' : 'env'
+
+ let $FOOBAR = 'test'
+ let found = 0
+ for kv in split(system(envcmd), "\r*\n")
+ if kv == 'FOOBAR=test'
+ let found = 1
+ endif
+ endfor
+ call assert_equal(1, found)
+
+ unlet $FOOBAR
+ let found = 0
+ for kv in split(system(envcmd), "\r*\n")
+ if kv == 'FOOBAR=test'
+ let found = 1
+ endif
+ endfor
+ call assert_equal(0, found)
+
+ unlet $MUST_NOT_BE_AN_ERROR
+endfunc
diff --git a/src/version.c b/src/version.c
index ac41ff30fb..080ba72e38 100644
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1832,
+/**/
1831,
/**/
1830,