aboutsummaryrefslogtreecommitdiff
path: root/runtime/doc/eval.txt
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/doc/eval.txt')
-rw-r--r--runtime/doc/eval.txt106
1 files changed, 89 insertions, 17 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index cf1394d799..da65708ac0 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1418,6 +1418,13 @@ v:exception The value of the exception most recently caught and not
:endtry
< Output: "caught oops".
+ *v:false* *false-variable*
+v:false Special value used to put "false" in JSON and msgpack. See
+ |json_encode()|. This value is converted to "false" when used
+ as a String (e.g. in |expr5| with string concatenation
+ operator) and to zero when used as a Number (e.g. in |expr5|
+ or |expr7| when used with numeric operators).
+
*v:fcs_reason* *fcs_reason-variable*
v:fcs_reason The reason why the |FileChangedShell| event was triggered.
Can be used in an autocommand to decide what to do and/or what
@@ -1557,6 +1564,13 @@ v:msgpack_types Dictionary containing msgpack types used by |msgpackparse()|
(not editable) empty lists. To check whether some list is one
of msgpack types, use |is| operator.
+ *v:null* *null-variable*
+v:null Special value used to put "null" in JSON and NIL in msgpack.
+ See |json_encode()|. This value is converted to "null" when
+ used as a String (e.g. in |expr5| with string concatenation
+ operator) and to zero when used as a Number (e.g. in |expr5|
+ or |expr7| when used with numeric operators).
+
*v:oldfiles* *oldfiles-variable*
v:oldfiles List of file names that is loaded from the |shada| file on
startup. These are the files that Vim remembers marks for.
@@ -1722,6 +1736,13 @@ v:throwpoint The point where the exception most recently caught and not
:endtry
< Output: "Exception from test.vim, line 2"
+ *v:true* *true-variable*
+v:true Special value used to put "true" in JSON and msgpack. See
+ |json_encode()|. This value is converted to "true" when used
+ as a String (e.g. in |expr5| with string concatenation
+ operator) and to one when used as a Number (e.g. in |expr5| or
+ |expr7| when used with numeric operators).
+
*v:val* *val-variable*
v:val Value of the current item of a |List| or |Dictionary|. Only
valid while evaluating the expression used with |map()| and
@@ -1932,6 +1953,8 @@ jobstart( {cmd}[, {opts}]) Number Spawns {cmd} as a job
jobstop( {job}) Number Stops a job
jobwait( {ids}[, {timeout}]) Number Wait for a set of jobs
join( {list} [, {sep}]) String join {list} items into one String
+json_decode( {expr}) any Convert {expr} from JSON
+json_encode( {expr}) String Convert {expr} to JSON
keys( {dict}) List keys in {dict}
len( {expr}) Number the length of {expr}
libcall( {lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
@@ -2222,17 +2245,17 @@ assert_equal({expected}, {actual}, [, {msg}])
assert_false({actual}, [, {msg}]) *assert_false()*
When {actual} is not false an error message is added to
- |v:errors|, like with |assert_equal()|..
- A value is false when it is zero. When "{actual}" is not a
- number the assert fails.
+ |v:errors|, like with |assert_equal()|.
+ A value is false when it is zero or |v:false|. When "{actual}"
+ is not a number or |v:false| the assert fails.
When {msg} is omitted an error in the form "Expected False but
got {actual}" is produced.
assert_true({actual}, [, {msg}]) *assert_true()*
When {actual} is not true an error message is added to
- |v:errors|, like with |assert_equal()|..
- A value is true when it is a non-zeron number. When {actual}
- is not a number the assert fails.
+ |v:errors|, like with |assert_equal()|.
+ A value is true when it is a non-zero number or |v:true|.
+ When {actual} is not a number or |v:true| the assert fails.
When {msg} is omitted an error in the form "Expected True but
got {actual}" is produced.
@@ -2826,9 +2849,8 @@ diff_hlID({lnum}, {col}) *diff_hlID()*
empty({expr}) *empty()*
Return the Number 1 if {expr} is empty, zero otherwise.
A |List| or |Dictionary| is empty when it does not have any
- items. A Number is empty when its value is zero.
- For a long |List| this is much faster than comparing the
- length with zero.
+ items. A Number is empty when its value is zero. Special
+ variable is empty when it is |v:false| or |v:null|.
escape({string}, {chars}) *escape()*
Escape the characters in {chars} that occur in {string} with a
@@ -4291,6 +4313,46 @@ join({list} [, {sep}]) *join()*
converted into a string like with |string()|.
The opposite function is |split()|.
+json_decode({expr}) *json_decode()*
+ Convert {expr} from JSON object. Accepts |readfile()|-style
+ list as the input, as well as regular string. May output any
+ Vim value. When 'encoding' is not UTF-8 string is converted
+ from UTF-8 to 'encoding', failing conversion fails
+ json_decode(). In the following cases it will output
+ |msgpack-special-dict|:
+ 1. Dictionary contains duplicate key.
+ 2. Dictionary contains empty key.
+ 3. String contains NUL byte. Two special dictionaries: for
+ dictionary and for string will be emitted in case string
+ with NUL byte was a dictionary key.
+
+ Note: function treats its input as UTF-8 always regardless of
+ 'encoding' value. This is needed because JSON source is
+ supposed to be external (e.g. |readfile()|) and JSON standard
+ allows only a few encodings, of which UTF-8 is recommended and
+ the only one required to be supported. Non-UTF-8 characters
+ are an error.
+
+json_encode({expr}) *json_encode()*
+ Convert {expr} into a JSON string. Accepts
+ |msgpack-special-dict| as the input. Converts from 'encoding'
+ to UTF-8 when encoding strings. Will not convert |Funcref|s,
+ mappings with non-string keys (can be created as
+ |msgpack-special-dict|), values with self-referencing
+ containers, strings which contain non-UTF-8 characters,
+ pseudo-UTF-8 strings which contain codepoints reserved for
+ surrogate pairs (such strings are not valid UTF-8 strings).
+ When converting 'encoding' is taken into account, if it is not
+ "utf-8", then conversion is performed before encoding strings.
+ Non-printable characters are converted into "\u1234" escapes
+ or special escapes like "\t", other are dumped as-is.
+
+ Note: all characters above U+0079 are considered non-printable
+ when 'encoding' is not UTF-8. This function always outputs
+ UTF-8 strings as required by the standard thus when 'encoding'
+ is not unicode resulting string will look incorrect if
+ "\u1234" notation is not used.
+
keys({dict}) *keys()*
Return a |List| with all the keys of {dict}. The |List| is in
arbitrary order.
@@ -4818,7 +4880,7 @@ msgpackdump({list}) {Nvim} *msgpackdump()*
(dictionary with zero items is represented by 0x80 byte in
messagepack).
- Limitations: *E951* *E952*
+ Limitations: *E951* *E952* *E953*
1. |Funcref|s cannot be dumped.
2. Containers that reference themselves cannot be dumped.
3. Dictionary keys are always dumped as STR strings.
@@ -4853,9 +4915,13 @@ msgpackparse({list}) {Nvim} *msgpackparse()*
contains name of the key from |v:msgpack_types|):
Key Value ~
- nil Zero, ignored when dumping.
- boolean One or zero. When dumping it is only checked that
- value is a |Number|.
+ nil Zero, ignored when dumping. This value cannot
+ possibly appear in |msgpackparse()| output in Neovim
+ versions which have |v:null|.
+ boolean One or zero. When dumping it is only checked that
+ value is a |Number|. This value cannot possibly
+ appear in |msgpackparse()| output in Neovim versions
+ which have |v:true| and |v:false|.
integer |List| with four numbers: sign (-1 or 1), highest two
bits, number with bits from 62nd to 31st, lowest 31
bits. I.e. to get actual number one will need to use
@@ -6729,12 +6795,14 @@ trunc({expr}) *trunc()*
type({expr}) *type()*
The result is a Number, depending on the type of {expr}:
- Number: 0
- String: 1
+ Number: 0
+ String: 1
Funcref: 2
- List: 3
+ List: 3
Dictionary: 4
- Float: 5
+ Float: 5
+ Boolean: 6 (|v:true| and |v:false|)
+ Null: 7 (|v:null|)
To avoid the magic numbers it should be used this way: >
:if type(myvar) == type(0)
:if type(myvar) == type("")
@@ -6742,6 +6810,10 @@ type({expr}) *type()*
:if type(myvar) == type([])
:if type(myvar) == type({})
:if type(myvar) == type(0.0)
+ :if type(myvar) == type(v:true)
+< In place of checking for |v:null| type it is better to check
+ for |v:null| directly as it is the only value of this type: >
+ :if myvar is v:null
undofile({name}) *undofile()*
Return the name of the undo file that would be used for a file