Mercurial > vim
comparison src/evalvars.c @ 20093:646c53fa5781 v8.2.0602
patch 8.2.0602: :unlet $VAR does not work properly
Commit: https://github.com/vim/vim/commit/7e0868efcf094f2cc59fa4e18af3a8dc7aedd64f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 19 17:24:53 2020 +0200
patch 8.2.0602: :unlet $VAR does not work properly
Problem: :unlet $VAR does not work properly.
Solution: Make ":lockvar $VAR" fail. Check the "skip" flag.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 19 Apr 2020 17:30:03 +0200 |
parents | a64c16ff98b8 |
children | fda7bed83eb6 |
comparison
equal
deleted
inserted
replaced
20092:7e38221cd2c1 | 20093:646c53fa5781 |
---|---|
1415 | 1415 |
1416 do | 1416 do |
1417 { | 1417 { |
1418 if (*arg == '$') | 1418 if (*arg == '$') |
1419 { | 1419 { |
1420 char_u *name = ++arg; | 1420 lv.ll_name = arg; |
1421 | 1421 lv.ll_tv = NULL; |
1422 ++arg; | |
1422 if (get_env_len(&arg) == 0) | 1423 if (get_env_len(&arg) == 0) |
1423 { | 1424 { |
1424 semsg(_(e_invarg2), name - 1); | 1425 semsg(_(e_invarg2), arg - 1); |
1425 return; | 1426 return; |
1426 } | 1427 } |
1427 vim_unsetenv(name); | 1428 if (!error && !eap->skip |
1429 && callback(&lv, arg, eap, deep, cookie) == FAIL) | |
1430 error = TRUE; | |
1428 arg = skipwhite(arg); | 1431 arg = skipwhite(arg); |
1429 continue; | 1432 continue; |
1430 } | 1433 } |
1431 | 1434 |
1432 // Parse the name and find the end. | 1435 // Parse the name and find the end. |
1475 if (lp->ll_tv == NULL) | 1478 if (lp->ll_tv == NULL) |
1476 { | 1479 { |
1477 cc = *name_end; | 1480 cc = *name_end; |
1478 *name_end = NUL; | 1481 *name_end = NUL; |
1479 | 1482 |
1480 // Normal name or expanded name. | 1483 // Environment variable, normal name or expanded name. |
1481 if (do_unlet(lp->ll_name, forceit) == FAIL) | 1484 if (*lp->ll_name == '$') |
1485 vim_unsetenv(lp->ll_name + 1); | |
1486 else if (do_unlet(lp->ll_name, forceit) == FAIL) | |
1482 ret = FAIL; | 1487 ret = FAIL; |
1483 *name_end = cc; | 1488 *name_end = cc; |
1484 } | 1489 } |
1485 else if ((lp->ll_list != NULL | 1490 else if ((lp->ll_list != NULL |
1486 && var_check_lock(lp->ll_list->lv_lock, lp->ll_name, FALSE)) | 1491 && var_check_lock(lp->ll_list->lv_lock, lp->ll_name, FALSE)) |
1606 | 1611 |
1607 if (lp->ll_tv == NULL) | 1612 if (lp->ll_tv == NULL) |
1608 { | 1613 { |
1609 cc = *name_end; | 1614 cc = *name_end; |
1610 *name_end = NUL; | 1615 *name_end = NUL; |
1611 | 1616 if (*lp->ll_name == '$') |
1612 // Normal name or expanded name. | 1617 { |
1613 di = find_var(lp->ll_name, NULL, TRUE); | 1618 semsg(_(e_lock_unlock), lp->ll_name); |
1614 if (di == NULL) | |
1615 ret = FAIL; | 1619 ret = FAIL; |
1616 else if ((di->di_flags & DI_FLAGS_FIX) | 1620 } |
1617 && di->di_tv.v_type != VAR_DICT | |
1618 && di->di_tv.v_type != VAR_LIST) | |
1619 // For historic reasons this error is not given for a list or dict. | |
1620 // E.g., the b: dict could be locked/unlocked. | |
1621 semsg(_("E940: Cannot lock or unlock variable %s"), lp->ll_name); | |
1622 else | 1621 else |
1623 { | 1622 { |
1624 if (lock) | 1623 // Normal name or expanded name. |
1625 di->di_flags |= DI_FLAGS_LOCK; | 1624 di = find_var(lp->ll_name, NULL, TRUE); |
1625 if (di == NULL) | |
1626 ret = FAIL; | |
1627 else if ((di->di_flags & DI_FLAGS_FIX) | |
1628 && di->di_tv.v_type != VAR_DICT | |
1629 && di->di_tv.v_type != VAR_LIST) | |
1630 { | |
1631 // For historic reasons this error is not given for a list or | |
1632 // dict. E.g., the b: dict could be locked/unlocked. | |
1633 semsg(_(e_lock_unlock), lp->ll_name); | |
1634 ret = FAIL; | |
1635 } | |
1626 else | 1636 else |
1627 di->di_flags &= ~DI_FLAGS_LOCK; | 1637 { |
1628 item_lock(&di->di_tv, deep, lock); | 1638 if (lock) |
1639 di->di_flags |= DI_FLAGS_LOCK; | |
1640 else | |
1641 di->di_flags &= ~DI_FLAGS_LOCK; | |
1642 item_lock(&di->di_tv, deep, lock); | |
1643 } | |
1629 } | 1644 } |
1630 *name_end = cc; | 1645 *name_end = cc; |
1631 } | 1646 } |
1632 else if (lp->ll_range) | 1647 else if (lp->ll_range) |
1633 { | 1648 { |