Patch 8.2.0605
Problem: Vim9: cannot unlet an environment variable.
Solution: Implement unlet for $VAR.
Files: src/vim9.h, src/vim9compile.c, src/vim9execute.c,
src/testdir/test_vim9_script.vim,
src/testdir/test_vim9_disassemble.vim
*** ../vim-8.2.0604/src/vim9.h 2020-04-19 16:28:55.292496003 +0200
--- src/vim9.h 2020-04-19 18:20:37.972973537 +0200
***************
*** 45,50 ****
--- 45,51 ----
ISN_STORENR, // store number into local variable
isn_arg.storenr.stnr_idx
ISN_UNLET, // unlet variable isn_arg.unlet.ul_name
+ ISN_UNLETENV, // unlet environment variable isn_arg.unlet.ul_name
// constants
ISN_PUSHNR, // push number isn_arg.number
*** ../vim-8.2.0604/src/vim9compile.c 2020-04-19 16:28:55.292496003 +0200
--- src/vim9compile.c 2020-04-19 18:23:16.836569064 +0200
***************
*** 990,1001 ****
* Generate an ISN_UNLET instruction.
*/
static int
! generate_UNLET(cctx_T *cctx, char_u *name, int forceit)
{
isn_T *isn;
RETURN_OK_IF_SKIP(cctx);
! if ((isn = generate_instr(cctx, ISN_UNLET)) == NULL)
return FAIL;
isn->isn_arg.unlet.ul_name = vim_strsave(name);
isn->isn_arg.unlet.ul_forceit = forceit;
--- 990,1001 ----
* Generate an ISN_UNLET instruction.
*/
static int
! generate_UNLET(cctx_T *cctx, isntype_T isn_type, char_u *name, int forceit)
{
isn_T *isn;
RETURN_OK_IF_SKIP(cctx);
! if ((isn = generate_instr(cctx, isn_type)) == NULL)
return FAIL;
isn->isn_arg.unlet.ul_name = vim_strsave(name);
isn->isn_arg.unlet.ul_forceit = forceit;
***************
*** 4594,4603 ****
// Normal name. Only supports g:, w:, t: and b: namespaces.
*name_end = NUL;
! if (check_vim9_unlet(p) == FAIL)
ret = FAIL;
else
! ret = generate_UNLET(cctx, p, eap->forceit);
*name_end = cc;
return ret;
--- 4594,4605 ----
// Normal name. Only supports g:, w:, t: and b: namespaces.
*name_end = NUL;
! if (*p == '$')
! ret = generate_UNLET(cctx, ISN_UNLETENV, p + 1, eap->forceit);
! else if (check_vim9_unlet(p) == FAIL)
ret = FAIL;
else
! ret = generate_UNLET(cctx, ISN_UNLET, p, eap->forceit);
*name_end = cc;
return ret;
***************
*** 6363,6368 ****
--- 6365,6371 ----
break;
case ISN_UNLET:
+ case ISN_UNLETENV:
vim_free(isn->isn_arg.unlet.ul_name);
break;
*** ../vim-8.2.0604/src/vim9execute.c 2020-04-19 16:28:55.292496003 +0200
--- src/vim9execute.c 2020-04-19 18:24:25.164395990 +0200
***************
*** 1073,1078 ****
--- 1073,1081 ----
iptr->isn_arg.unlet.ul_forceit) == FAIL)
goto failed;
break;
+ case ISN_UNLETENV:
+ vim_unsetenv(iptr->isn_arg.unlet.ul_name);
+ break;
// create a list from items on the stack; uses a single allocation
// for the list header and the items
***************
*** 2119,2124 ****
--- 2122,2132 ----
iptr->isn_arg.unlet.ul_forceit ? "!" : "",
iptr->isn_arg.unlet.ul_name);
break;
+ case ISN_UNLETENV:
+ smsg("%4d UNLETENV%s $%s", current,
+ iptr->isn_arg.unlet.ul_forceit ? "!" : "",
+ iptr->isn_arg.unlet.ul_name);
+ break;
case ISN_NEWLIST:
smsg("%4d NEWLIST size %lld", current,
(long long)(iptr->isn_arg.number));
*** ../vim-8.2.0604/src/testdir/test_vim9_script.vim 2020-04-19
16:28:55.296495996 +0200
--- src/testdir/test_vim9_script.vim 2020-04-19 18:18:37.973281698 +0200
***************
*** 289,294 ****
--- 289,299 ----
' unlet s:svar',
'enddef',
], 'E1081:')
+
+ $ENVVAR = 'foobar'
+ assert_equal('foobar', $ENVVAR)
+ unlet $ENVVAR
+ assert_equal('', $ENVVAR)
enddef
func Test_wrong_type()
*** ../vim-8.2.0604/src/testdir/test_vim9_disassemble.vim 2020-04-19
16:28:55.296495996 +0200
--- src/testdir/test_vim9_disassemble.vim 2020-04-19 18:26:37.096063132
+0200
***************
*** 130,135 ****
--- 130,136 ----
g:somevar = "value"
unlet g:somevar
unlet! g:somevar
+ unlet $SOMEVAR
enddef
def Test_disassemble_unlet()
***************
*** 141,147 ****
'unlet g:somevar.*' ..
'\d UNLET g:somevar.*' ..
'unlet! g:somevar.*' ..
! '\d UNLET! g:somevar.*',
res)
enddef
--- 142,150 ----
'unlet g:somevar.*' ..
'\d UNLET g:somevar.*' ..
'unlet! g:somevar.*' ..
! '\d UNLET! g:somevar.*' ..
! 'unlet $SOMEVAR.*' ..
! '\d UNLETENV $SOMEVAR.*',
res)
enddef
*** ../vim-8.2.0604/src/version.c 2020-04-19 18:13:14.542129938 +0200
--- src/version.c 2020-04-19 18:19:59.289072630 +0200
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 605,
/**/
--
Engineers will go without food and hygiene for days to solve a problem.
(Other times just because they forgot.)
(Scott Adams - The Dilbert principle)
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202004191627.03JGRqQ5010647%40masaka.moolenaar.net.