aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Edmund Lazo <janedmundlazo@hotmail.com>2018-10-01 22:57:49 -0400
committerJan Edmund Lazo <janedmundlazo@hotmail.com>2018-10-02 20:44:48 -0400
commit07fbdf4acc3b15ff97acb5c90243c61d938f8541 (patch)
treef43de17d8d0a663c93a711933115cc72afdc8b06
parent65206714bc0990a469da5efd2edbe52e81903014 (diff)
downloadrneovim-07fbdf4acc3b15ff97acb5c90243c61d938f8541.tar.gz
rneovim-07fbdf4acc3b15ff97acb5c90243c61d938f8541.tar.bz2
rneovim-07fbdf4acc3b15ff97acb5c90243c61d938f8541.zip
vim-patch:8.0.1832: cannot use :unlet for an environment variable
Problem: Cannot use :unlet for an environment variable. Solution: Make it work. Use unsetenv() if available. (Yasuhiro Matsumoto, closes vim/vim#2855) https://github.com/vim/vim/commit/137374fd6538cf9dee0cb22907728d8fdecb5832
-rw-r--r--runtime/doc/eval.txt8
-rw-r--r--src/nvim/eval.c12
-rw-r--r--src/nvim/testdir/test_unlet.vim24
3 files changed, 44 insertions, 0 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 064c08c190..2e1d89c524 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -9136,6 +9136,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/nvim/eval.c b/src/nvim/eval.c
index 41a9eeeb40..2aab2d72a7 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -2818,6 +2818,18 @@ static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep)
lval_T lv;
do {
+ if (*arg == '$') {
+ const char *name = (char *)++arg;
+
+ if (get_env_len((const char_u **)&arg) == 0) {
+ EMSG2(_(e_invarg2), name - 1);
+ return;
+ }
+ os_unsetenv(name);
+ arg = skipwhite(arg);
+ continue;
+ }
+
// Parse the name and find the end.
char_u *const name_end = (char_u *)get_lval(arg, NULL, &lv, true,
eap->skip || error,
diff --git a/src/nvim/testdir/test_unlet.vim b/src/nvim/testdir/test_unlet.vim
index 3f06058d03..dbddffb492 100644
--- a/src/nvim/testdir/test_unlet.vim
+++ b/src/nvim/testdir/test_unlet.vim
@@ -28,3 +28,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