mirror of
https://github.com/neovim/neovim.git
synced 2025-09-26 21:18:34 +00:00
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)
137374fd65
This commit is contained in:
@@ -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,
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user