forked from aniani/vim
patch 7.4.2071
Problem: The return value of type() is difficult to use. Solution: Define v:t_ constants. (Ken Takata)
This commit is contained in:
@@ -1827,6 +1827,27 @@ 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".
|
example, when jumping to a tag the value is ":tag tagname\r".
|
||||||
For ":edit +cmd file" the value is ":cmd\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_channel* *t_channel-varialble*
|
||||||
|
v:t_channel Value of Channel 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_job* *t_job-varialble*
|
||||||
|
v:t_job Value of Job type. Read-only. See: |type()|
|
||||||
|
*v:t_list* *t_list-varialble*
|
||||||
|
v:t_list Value of List type. Read-only. See: |type()|
|
||||||
|
*v:t_none* *t_none-varialble*
|
||||||
|
v:t_none Value of None 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* *termresponse-variable*
|
||||||
v:termresponse The escape sequence returned by the terminal for the |t_RV|
|
v:termresponse The escape sequence returned by the terminal for the |t_RV|
|
||||||
termcap entry. It is set when Vim receives an escape sequence
|
termcap entry. It is set when Vim receives an escape sequence
|
||||||
|
21
src/eval.c
21
src/eval.c
@@ -177,6 +177,16 @@ static struct vimvar
|
|||||||
{VV_NAME("none", VAR_SPECIAL), VV_RO},
|
{VV_NAME("none", VAR_SPECIAL), VV_RO},
|
||||||
{VV_NAME("vim_did_enter", VAR_NUMBER), VV_RO},
|
{VV_NAME("vim_did_enter", VAR_NUMBER), VV_RO},
|
||||||
{VV_NAME("testing", VAR_NUMBER), 0},
|
{VV_NAME("testing", VAR_NUMBER), 0},
|
||||||
|
{VV_NAME("t_number", VAR_NUMBER), VV_RO},
|
||||||
|
{VV_NAME("t_string", VAR_NUMBER), VV_RO},
|
||||||
|
{VV_NAME("t_func", VAR_NUMBER), VV_RO},
|
||||||
|
{VV_NAME("t_list", VAR_NUMBER), VV_RO},
|
||||||
|
{VV_NAME("t_dict", VAR_NUMBER), VV_RO},
|
||||||
|
{VV_NAME("t_float", VAR_NUMBER), VV_RO},
|
||||||
|
{VV_NAME("t_bool", VAR_NUMBER), VV_RO},
|
||||||
|
{VV_NAME("t_none", VAR_NUMBER), VV_RO},
|
||||||
|
{VV_NAME("t_job", VAR_NUMBER), VV_RO},
|
||||||
|
{VV_NAME("t_channel", VAR_NUMBER), VV_RO},
|
||||||
};
|
};
|
||||||
|
|
||||||
/* shorthand */
|
/* shorthand */
|
||||||
@@ -292,6 +302,17 @@ eval_init(void)
|
|||||||
set_vim_var_nr(VV_NONE, VVAL_NONE);
|
set_vim_var_nr(VV_NONE, VVAL_NONE);
|
||||||
set_vim_var_nr(VV_NULL, VVAL_NULL);
|
set_vim_var_nr(VV_NULL, VVAL_NULL);
|
||||||
|
|
||||||
|
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_nr(VV_TYPE_NONE, VAR_TYPE_NONE);
|
||||||
|
set_vim_var_nr(VV_TYPE_JOB, VAR_TYPE_JOB);
|
||||||
|
set_vim_var_nr(VV_TYPE_CHANNEL, VAR_TYPE_CHANNEL);
|
||||||
|
|
||||||
set_reg_var(0); /* default for v:register is not 0 but '"' */
|
set_reg_var(0); /* default for v:register is not 0 but '"' */
|
||||||
|
|
||||||
#ifdef EBCDIC
|
#ifdef EBCDIC
|
||||||
|
@@ -12136,22 +12136,22 @@ f_type(typval_T *argvars, typval_T *rettv)
|
|||||||
|
|
||||||
switch (argvars[0].v_type)
|
switch (argvars[0].v_type)
|
||||||
{
|
{
|
||||||
case VAR_NUMBER: n = 0; break;
|
case VAR_NUMBER: n = VAR_TYPE_NUMBER; break;
|
||||||
case VAR_STRING: n = 1; break;
|
case VAR_STRING: n = VAR_TYPE_STRING; break;
|
||||||
case VAR_PARTIAL:
|
case VAR_PARTIAL:
|
||||||
case VAR_FUNC: n = 2; break;
|
case VAR_FUNC: n = VAR_TYPE_FUNC; break;
|
||||||
case VAR_LIST: n = 3; break;
|
case VAR_LIST: n = VAR_TYPE_LIST; break;
|
||||||
case VAR_DICT: n = 4; break;
|
case VAR_DICT: n = VAR_TYPE_DICT; break;
|
||||||
case VAR_FLOAT: n = 5; break;
|
case VAR_FLOAT: n = VAR_TYPE_FLOAT; break;
|
||||||
case VAR_SPECIAL:
|
case VAR_SPECIAL:
|
||||||
if (argvars[0].vval.v_number == VVAL_FALSE
|
if (argvars[0].vval.v_number == VVAL_FALSE
|
||||||
|| argvars[0].vval.v_number == VVAL_TRUE)
|
|| argvars[0].vval.v_number == VVAL_TRUE)
|
||||||
n = 6;
|
n = VAR_TYPE_BOOL;
|
||||||
else
|
else
|
||||||
n = 7;
|
n = VAR_TYPE_NONE;
|
||||||
break;
|
break;
|
||||||
case VAR_JOB: n = 8; break;
|
case VAR_JOB: n = VAR_TYPE_JOB; break;
|
||||||
case VAR_CHANNEL: n = 9; break;
|
case VAR_CHANNEL: n = VAR_TYPE_CHANNEL; break;
|
||||||
case VAR_UNKNOWN:
|
case VAR_UNKNOWN:
|
||||||
EMSG2(_(e_intern2), "f_type(UNKNOWN)");
|
EMSG2(_(e_intern2), "f_type(UNKNOWN)");
|
||||||
n = -1;
|
n = -1;
|
||||||
|
@@ -188,6 +188,7 @@ endfunc
|
|||||||
" Test that we can open two channels.
|
" Test that we can open two channels.
|
||||||
func Ch_two_channels(port)
|
func Ch_two_channels(port)
|
||||||
let handle = ch_open('localhost:' . a:port, s:chopt)
|
let handle = ch_open('localhost:' . a:port, s:chopt)
|
||||||
|
call assert_equal(v:t_channel, type(handle))
|
||||||
if ch_status(handle) == "fail"
|
if ch_status(handle) == "fail"
|
||||||
call assert_false(1, "Can't open channel")
|
call assert_false(1, "Can't open channel")
|
||||||
return
|
return
|
||||||
@@ -420,6 +421,7 @@ func Test_raw_pipe()
|
|||||||
endif
|
endif
|
||||||
call ch_log('Test_raw_pipe()')
|
call ch_log('Test_raw_pipe()')
|
||||||
let job = job_start(s:python . " test_channel_pipe.py", {'mode': 'raw'})
|
let job = job_start(s:python . " test_channel_pipe.py", {'mode': 'raw'})
|
||||||
|
call assert_equal(v:t_job, type(job))
|
||||||
call assert_equal("run", job_status(job))
|
call assert_equal("run", job_status(job))
|
||||||
try
|
try
|
||||||
" For a change use the job where a channel is expected.
|
" For a change use the job where a channel is expected.
|
||||||
|
@@ -950,6 +950,20 @@ func Test_type()
|
|||||||
call assert_equal(6, type(v:true))
|
call assert_equal(6, type(v:true))
|
||||||
call assert_equal(7, type(v:none))
|
call assert_equal(7, type(v:none))
|
||||||
call assert_equal(7, type(v:null))
|
call assert_equal(7, type(v:null))
|
||||||
|
call assert_equal(8, v:t_job)
|
||||||
|
call assert_equal(9, v:t_channel)
|
||||||
|
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_func, type(function("tr", [8])))
|
||||||
|
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))
|
||||||
|
call assert_equal(v:t_none, type(v:none))
|
||||||
|
call assert_equal(v:t_none, type(v:null))
|
||||||
|
|
||||||
|
|
||||||
call assert_equal(0, 0 + v:false)
|
call assert_equal(0, 0 + v:false)
|
||||||
call assert_equal(1, 0 + v:true)
|
call assert_equal(1, 0 + v:true)
|
||||||
|
@@ -758,6 +758,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2071,
|
||||||
/**/
|
/**/
|
||||||
2070,
|
2070,
|
||||||
/**/
|
/**/
|
||||||
|
24
src/vim.h
24
src/vim.h
@@ -1968,7 +1968,17 @@ typedef int sock_T;
|
|||||||
#define VV_NONE 68
|
#define VV_NONE 68
|
||||||
#define VV_VIM_DID_ENTER 69
|
#define VV_VIM_DID_ENTER 69
|
||||||
#define VV_TESTING 70
|
#define VV_TESTING 70
|
||||||
#define VV_LEN 71 /* number of v: vars */
|
#define VV_TYPE_NUMBER 71
|
||||||
|
#define VV_TYPE_STRING 72
|
||||||
|
#define VV_TYPE_FUNC 73
|
||||||
|
#define VV_TYPE_LIST 74
|
||||||
|
#define VV_TYPE_DICT 75
|
||||||
|
#define VV_TYPE_FLOAT 76
|
||||||
|
#define VV_TYPE_BOOL 77
|
||||||
|
#define VV_TYPE_NONE 78
|
||||||
|
#define VV_TYPE_JOB 79
|
||||||
|
#define VV_TYPE_CHANNEL 80
|
||||||
|
#define VV_LEN 81 /* number of v: vars */
|
||||||
|
|
||||||
/* used for v_number in VAR_SPECIAL */
|
/* used for v_number in VAR_SPECIAL */
|
||||||
#define VVAL_FALSE 0L
|
#define VVAL_FALSE 0L
|
||||||
@@ -1976,6 +1986,18 @@ typedef int sock_T;
|
|||||||
#define VVAL_NONE 2L
|
#define VVAL_NONE 2L
|
||||||
#define VVAL_NULL 3L
|
#define VVAL_NULL 3L
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
#define VAR_TYPE_NONE 7
|
||||||
|
#define VAR_TYPE_JOB 8
|
||||||
|
#define VAR_TYPE_CHANNEL 9
|
||||||
|
|
||||||
#ifdef FEAT_CLIPBOARD
|
#ifdef FEAT_CLIPBOARD
|
||||||
|
|
||||||
/* VIM_ATOM_NAME is the older Vim-specific selection type for X11. Still
|
/* VIM_ATOM_NAME is the older Vim-specific selection type for X11. Still
|
||||||
|
Reference in New Issue
Block a user