summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-09-16 21:08:28 +0200
committerBram Moolenaar <Bram@vim.org>2020-09-16 21:08:28 +0200
commita187c43cfe8863d48b2159d695fedcb71f8525c1 (patch)
tree40cd63746c55f16dadb674da3d1ffab7f23f291b /runtime
parent7707228aace9aff16434edf5377a354c6ad07316 (diff)
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9v8.2.1698
Problem: Cannot lock a variable in legacy Vim script like in Vim9. Solution: Make ":lockvar 0" work.
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/eval.txt15
1 files changed, 13 insertions, 2 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 68884ba1ed..7dbf7772aa 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.