To: vim_dev@googlegroups.com Subject: Patch 8.0.1832 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1832 Problem: Cannot use :unlet for an environment variable. Solution: Make it work. Use unsetenv() if available. (Ken Takata, closes #2855) Files: runtime/doc/eval.txt, src/config.h.in, src/configure.ac, src/auto/configure, src/eval.c, src/misc1.c, src/proto/misc1.pro, src/testdir/test_unlet.vim *** ../vim-8.0.1831/runtime/doc/eval.txt 2018-05-01 15:01:56.934414650 +0200 --- runtime/doc/eval.txt 2018-05-13 15:50:04.404705633 +0200 *************** *** 9894,9899 **** --- 9939,9952 ---- 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). *** ../vim-8.0.1831/src/config.h.in 2017-11-16 17:03:41.952727829 +0100 --- src/config.h.in 2018-05-13 15:37:01.313297576 +0200 *************** *** 211,216 **** --- 211,217 ---- #undef HAVE_TOWLOWER #undef HAVE_TOWUPPER #undef HAVE_ISWUPPER + #undef HAVE_UNSETENV #undef HAVE_USLEEP #undef HAVE_UTIME #undef HAVE_BIND_TEXTDOMAIN_CODESET *** ../vim-8.0.1831/src/configure.ac 2018-05-12 21:38:09.983347669 +0200 --- src/configure.ac 2018-05-13 15:37:01.313297576 +0200 *************** *** 3709,3715 **** 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) AC_FUNC_FSEEKO dnl define _LARGE_FILES, _FILE_OFFSET_BITS and _LARGEFILE_SOURCE when --- 3709,3715 ---- 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 unsetenv) AC_FUNC_FSEEKO dnl define _LARGE_FILES, _FILE_OFFSET_BITS and _LARGEFILE_SOURCE when *** ../vim-8.0.1831/src/auto/configure 2018-05-12 21:38:09.987347656 +0200 --- src/auto/configure 2018-05-13 15:38:02.532890230 +0200 *************** *** 12609,12615 **** 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 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" --- 12609,12615 ---- 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 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" *** ../vim-8.0.1831/src/eval.c 2018-05-12 15:38:22.474714244 +0200 --- src/eval.c 2018-05-13 15:42:40.823049133 +0200 *************** *** 2758,2763 **** --- 2758,2777 ---- 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); *** ../vim-8.0.1831/src/misc1.c 2018-05-01 15:47:30.292975459 +0200 --- src/misc1.c 2018-05-13 15:49:32.820799092 +0200 *************** *** 4479,4484 **** --- 4479,4495 ---- 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. */ *** ../vim-8.0.1831/src/proto/misc1.pro 2017-09-02 20:30:31.167315016 +0200 --- src/proto/misc1.pro 2018-05-13 15:37:01.317297550 +0200 *************** *** 60,65 **** --- 60,66 ---- 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); *** ../vim-8.0.1831/src/testdir/test_unlet.vim 2017-02-20 23:07:00.478656212 +0100 --- src/testdir/test_unlet.vim 2018-05-13 15:58:22.966685950 +0200 *************** *** 21,23 **** --- 21,47 ---- 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 *** ../vim-8.0.1831/src/version.c 2018-05-13 15:28:59.848552204 +0200 --- src/version.c 2018-05-13 15:37:57.152925987 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 1832, /**/ -- Sorry, no fortune today. /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///