aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/eval.txt15
-rw-r--r--src/nvim/eval.c30
-rw-r--r--src/nvim/eval.h7
-rw-r--r--src/nvim/testdir/test_viml.vim8
-rw-r--r--src/nvim/version.c2
-rw-r--r--src/nvim/vim.h8
6 files changed, 61 insertions, 9 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 9c6cbd5a1a..254cf8b418 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1718,6 +1718,21 @@ v:swapcommand Normal mode command to be executed after a file has been
example, when jumping to a tag the value is ":tag tagname\r".
For ":edit +cmd file" the value is ":cmd\r".
+ *v:t_TYPE* *v:t_bool* *t_bool-varialble*
+v:t_bool Value of Boolean type. Read-only. See: |type()|
+ *v:t_dict* *t_dict-varialble*
+v:t_dict Value of Dictionary type. Read-only. See: |type()|
+ *v:t_float* *t_float-varialble*
+v:t_float Value of Float type. Read-only. See: |type()|
+ *v:t_func* *t_func-varialble*
+v:t_func Value of Funcref type. Read-only. See: |type()|
+ *v:t_list* *t_list-varialble*
+v:t_list Value of List type. Read-only. See: |type()|
+ *v:t_number* *t_number-varialble*
+v:t_number Value of Number type. Read-only. See: |type()|
+ *v:t_string* *t_string-varialble*
+v:t_string Value of String type. Read-only. See: |type()|
+
*v:termresponse* *termresponse-variable*
v:termresponse The escape sequence returned by the terminal for the |t_RV|
termcap entry. It is set when Vim receives an escape sequence
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 88464b8cb0..422fedff1d 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -387,6 +387,13 @@ static struct vimvar {
VV(VV__NULL_LIST, "_null_list", VAR_LIST, VV_RO),
VV(VV__NULL_DICT, "_null_dict", VAR_DICT, VV_RO),
VV(VV_VIM_DID_ENTER, "vim_did_enter", VAR_NUMBER, VV_RO),
+ VV(VV_TYPE_NUMBER, "t_number", VAR_NUMBER, VV_RO),
+ VV(VV_TYPE_STRING, "t_string", VAR_NUMBER, VV_RO),
+ VV(VV_TYPE_FUNC, "t_func", VAR_NUMBER, VV_RO),
+ VV(VV_TYPE_LIST, "t_list", VAR_NUMBER, VV_RO),
+ VV(VV_TYPE_DICT, "t_dict", VAR_NUMBER, VV_RO),
+ VV(VV_TYPE_FLOAT, "t_float", VAR_NUMBER, VV_RO),
+ VV(VV_TYPE_BOOL, "t_bool", VAR_NUMBER, VV_RO),
};
#undef VV
@@ -400,7 +407,7 @@ static struct vimvar {
#define vv_dict vv_di.di_tv.vval.v_dict
#define vv_tv vv_di.di_tv
-static dictitem_T vimvars_var; /* variable used for v: */
+static dictitem_T vimvars_var; // variable used for v:
#define vimvarht vimvardict.dv_hashtab
typedef struct {
@@ -563,6 +570,13 @@ void eval_init(void)
set_vim_var_nr(VV_SEARCHFORWARD, 1L);
set_vim_var_nr(VV_HLSEARCH, 1L);
set_vim_var_nr(VV_COUNT1, 1);
+ set_vim_var_nr(VV_TYPE_NUMBER, VAR_TYPE_NUMBER);
+ set_vim_var_nr(VV_TYPE_STRING, VAR_TYPE_STRING);
+ set_vim_var_nr(VV_TYPE_FUNC, VAR_TYPE_FUNC);
+ set_vim_var_nr(VV_TYPE_LIST, VAR_TYPE_LIST);
+ set_vim_var_nr(VV_TYPE_DICT, VAR_TYPE_DICT);
+ set_vim_var_nr(VV_TYPE_FLOAT, VAR_TYPE_FLOAT);
+ set_vim_var_nr(VV_TYPE_BOOL, VAR_TYPE_BOOL);
set_vim_var_special(VV_FALSE, kSpecialVarFalse);
set_vim_var_special(VV_TRUE, kSpecialVarTrue);
@@ -16801,17 +16815,17 @@ static void f_type(typval_T *argvars, typval_T *rettv, FunPtr fptr)
int n = -1;
switch (argvars[0].v_type) {
- case VAR_NUMBER: n = 0; break;
- case VAR_STRING: n = 1; break;
- case VAR_FUNC: n = 2; break;
- case VAR_LIST: n = 3; break;
- case VAR_DICT: n = 4; break;
- case VAR_FLOAT: n = 5; break;
+ case VAR_NUMBER: n = VAR_TYPE_NUMBER; break;
+ case VAR_STRING: n = VAR_TYPE_STRING; break;
+ case VAR_FUNC: n = VAR_TYPE_FUNC; break;
+ case VAR_LIST: n = VAR_TYPE_LIST; break;
+ case VAR_DICT: n = VAR_TYPE_DICT; break;
+ case VAR_FLOAT: n = VAR_TYPE_FLOAT; break;
case VAR_SPECIAL: {
switch (argvars[0].vval.v_special) {
case kSpecialVarTrue:
case kSpecialVarFalse: {
- n = 6;
+ n = VAR_TYPE_BOOL;
break;
}
case kSpecialVarNull: {
diff --git a/src/nvim/eval.h b/src/nvim/eval.h
index 1061840816..cc7827b801 100644
--- a/src/nvim/eval.h
+++ b/src/nvim/eval.h
@@ -127,6 +127,13 @@ typedef enum {
VV__NULL_LIST, // List with NULL value. For test purposes only.
VV__NULL_DICT, // Dictionary with NULL value. For test purposes only.
VV_VIM_DID_ENTER,
+ VV_TYPE_NUMBER,
+ VV_TYPE_STRING,
+ VV_TYPE_FUNC,
+ VV_TYPE_LIST,
+ VV_TYPE_DICT,
+ VV_TYPE_FLOAT,
+ VV_TYPE_BOOL,
} VimVarIndex;
/// All recognized msgpack types
diff --git a/src/nvim/testdir/test_viml.vim b/src/nvim/testdir/test_viml.vim
index c39c5e6b28..a11d62f5cf 100644
--- a/src/nvim/testdir/test_viml.vim
+++ b/src/nvim/testdir/test_viml.vim
@@ -949,6 +949,14 @@ func Test_type()
call assert_equal(6, type(v:false))
call assert_equal(6, type(v:true))
call assert_equal(7, type(v:null))
+ call assert_equal(v:t_number, type(0))
+ call assert_equal(v:t_string, type(""))
+ call assert_equal(v:t_func, type(function("tr")))
+ call assert_equal(v:t_list, type([]))
+ call assert_equal(v:t_dict, type({}))
+ call assert_equal(v:t_float, type(0.0))
+ call assert_equal(v:t_bool, type(v:false))
+ call assert_equal(v:t_bool, type(v:true))
endfunc
"-------------------------------------------------------------------------------
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 82a6f5f9a9..07858e8953 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -371,7 +371,7 @@ static int included_patches[] = {
// 2074,
// 2073,
// 2072,
- // 2071,
+ 2071,
// 2070 NA
// 2069,
// 2068,
diff --git a/src/nvim/vim.h b/src/nvim/vim.h
index 32eba55c18..8271abda8d 100644
--- a/src/nvim/vim.h
+++ b/src/nvim/vim.h
@@ -123,6 +123,14 @@ Error: configure did not run properly.Check auto/config.log.
#define FAIL 0
#define NOTDONE 2 /* not OK or FAIL but skipped */
+// Type values for type().
+#define VAR_TYPE_NUMBER 0
+#define VAR_TYPE_STRING 1
+#define VAR_TYPE_FUNC 2
+#define VAR_TYPE_LIST 3
+#define VAR_TYPE_DICT 4
+#define VAR_TYPE_FLOAT 5
+#define VAR_TYPE_BOOL 6
/*
* values for xp_context when doing command line completion