From a187c43cfe8863d48b2159d695fedcb71f8525c1 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Wed, 16 Sep 2020 21:08:28 +0200 Subject: patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9 Problem: Cannot lock a variable in legacy Vim script like in Vim9. Solution: Make ":lockvar 0" work. --- runtime/doc/eval.txt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 68884ba1e..7dbf7772a 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -12364,7 +12364,9 @@ text... < is equivalent to: > :let x = 1 :lockvar! x -< This is useful if you want to make sure the variable +< NOTE: in Vim9 script `:const` works differently, see + |vim9-const| + This is useful if you want to make sure the variable is not modified. If the value is a List or Dictionary literal then the items also cannot be changed: > const ll = [1, 2, 3] @@ -12404,6 +12406,8 @@ text... [depth] is relevant when locking a |List| or |Dictionary|. It specifies how deep the locking goes: + 0 Lock the variable {name} but not its + value. 1 Lock the |List| or |Dictionary| itself, cannot add or remove items, but can still change their values. @@ -12417,7 +12421,14 @@ text... |Dictionary|, one level deeper. The default [depth] is 2, thus when {name} is a |List| or |Dictionary| the values cannot be changed. - *E743* + + Example with [depth] 0: > + let mylist = [1, 2, 3] + lockvar 0 mylist + let mylist[0] = 77 " OK + call add(mylist, 4] " OK + let mylist = [7, 8, 9] " Error! +< *E743* For unlimited depth use [!] and omit [depth]. However, there is a maximum depth of 100 to catch loops. -- cgit v1.2.1