mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 23:38:17 +00:00
eval: Forbid (un)locking b:changedtick
Port of vim-patch:8.0.0343
This commit is contained in:
@@ -8606,9 +8606,12 @@ This does NOT work: >
|
|||||||
:lockvar v
|
:lockvar v
|
||||||
:let v = 'asdf' " fails!
|
:let v = 'asdf' " fails!
|
||||||
:unlet v
|
:unlet v
|
||||||
< *E741*
|
< *E741* *E940*
|
||||||
If you try to change a locked variable you get an
|
If you try to change a locked variable you get an
|
||||||
error message: "E741: Value is locked: {name}"
|
error message: "E741: Value is locked: {name}".
|
||||||
|
If you try to lock or unlock a built-in variable you
|
||||||
|
will get an error message "E940: Cannot lock or unlock
|
||||||
|
variable {name}".
|
||||||
|
|
||||||
[depth] is relevant when locking a |List| or
|
[depth] is relevant when locking a |List| or
|
||||||
|Dictionary|. It specifies how deep the locking goes:
|
|Dictionary|. It specifies how deep the locking goes:
|
||||||
|
@@ -3091,6 +3091,12 @@ static int do_lock_var(lval_T *lp, char_u *name_end, int deep, int lock)
|
|||||||
true);
|
true);
|
||||||
if (di == NULL) {
|
if (di == NULL) {
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
|
} else if ((di->di_flags & DI_FLAGS_FIX)
|
||||||
|
&& di->di_tv.v_type != VAR_DICT
|
||||||
|
&& di->di_tv.v_type != VAR_LIST) {
|
||||||
|
// For historical reasons this error is not given for Lists and
|
||||||
|
// Dictionaries. E.g. b: dictionary may be locked/unlocked.
|
||||||
|
emsgf(_("E940: Cannot lock or unlock variable %s"), lp->ll_name);
|
||||||
} else {
|
} else {
|
||||||
if ((di->di_flags & (DI_FLAGS_LOCK|DI_FLAGS_FIX))
|
if ((di->di_flags & (DI_FLAGS_LOCK|DI_FLAGS_FIX))
|
||||||
== (DI_FLAGS_LOCK|DI_FLAGS_FIX)) {
|
== (DI_FLAGS_LOCK|DI_FLAGS_FIX)) {
|
||||||
|
@@ -101,19 +101,21 @@ describe('b:changedtick', function()
|
|||||||
redir_exec(':let b:'))
|
redir_exec(':let b:'))
|
||||||
end)
|
end)
|
||||||
it('fails to unlock b:changedtick', function()
|
it('fails to unlock b:changedtick', function()
|
||||||
-- Note:
|
|
||||||
-- - unlocking VAR_FIXED variables is not an error.
|
|
||||||
-- - neither VAR_FIXED variables are reported as locked by islocked().
|
|
||||||
-- So test mostly checks that b:changedtick status does not change.
|
|
||||||
eq(0, exc_exec('let d = b:'))
|
eq(0, exc_exec('let d = b:'))
|
||||||
eq(0, funcs.islocked('b:changedtick'))
|
eq(0, funcs.islocked('b:changedtick'))
|
||||||
eq(0, funcs.islocked('d.changedtick'))
|
eq(0, funcs.islocked('d.changedtick'))
|
||||||
eq('',
|
eq('\nE940: Cannot lock or unlock variable b:changedtick',
|
||||||
redir_exec('unlockvar b:changedtick'))
|
redir_exec('unlockvar b:changedtick'))
|
||||||
eq('\nE46: Cannot change read-only variable "d.changedtick"',
|
eq('\nE46: Cannot change read-only variable "d.changedtick"',
|
||||||
redir_exec('unlockvar d.changedtick'))
|
redir_exec('unlockvar d.changedtick'))
|
||||||
eq(0, funcs.islocked('b:changedtick'))
|
eq(0, funcs.islocked('b:changedtick'))
|
||||||
eq(0, funcs.islocked('d.changedtick'))
|
eq(0, funcs.islocked('d.changedtick'))
|
||||||
|
eq('\nE940: Cannot lock or unlock variable b:changedtick',
|
||||||
|
redir_exec('lockvar b:changedtick'))
|
||||||
|
eq('\nE46: Cannot change read-only variable "d.changedtick"',
|
||||||
|
redir_exec('lockvar d.changedtick'))
|
||||||
|
eq(0, funcs.islocked('b:changedtick'))
|
||||||
|
eq(0, funcs.islocked('d.changedtick'))
|
||||||
end)
|
end)
|
||||||
it('is being completed', function()
|
it('is being completed', function()
|
||||||
feed(':echo b:<Tab><Home>let cmdline="<End>"<CR>')
|
feed(':echo b:<Tab><Home>let cmdline="<End>"<CR>')
|
||||||
|
Reference in New Issue
Block a user