mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.0.1090: cannot get the text under the cursor like v:beval_text
Problem: cannot get the text under the cursor like v:beval_text Solution: Add <cexpr>.
This commit is contained in:
@@ -830,6 +830,11 @@ Also see |`=|.
|
|||||||
Note: these are typed literally, they are not special keys!
|
Note: these are typed literally, they are not special keys!
|
||||||
<cword> is replaced with the word under the cursor (like |star|)
|
<cword> is replaced with the word under the cursor (like |star|)
|
||||||
<cWORD> is replaced with the WORD under the cursor (see |WORD|)
|
<cWORD> is replaced with the WORD under the cursor (see |WORD|)
|
||||||
|
<cexpr> is replaced with the word under the cursor, including more
|
||||||
|
to form a C expression. E.g., when the cursor is on "arg"
|
||||||
|
of "ptr->arg" then the result is "ptr->arg"; when the
|
||||||
|
cursor is on "]" of "list[idx]" then the result is
|
||||||
|
"list[idx]". This is used for |v:beval_text|.
|
||||||
<cfile> is replaced with the path name under the cursor (like what
|
<cfile> is replaced with the path name under the cursor (like what
|
||||||
|gf| uses)
|
|gf| uses)
|
||||||
<afile> When executing autocommands, is replaced with the file name
|
<afile> When executing autocommands, is replaced with the file name
|
||||||
|
@@ -10650,31 +10650,33 @@ find_cmdline_var(char_u *src, int *usedlen)
|
|||||||
"%",
|
"%",
|
||||||
#define SPEC_PERC 0
|
#define SPEC_PERC 0
|
||||||
"#",
|
"#",
|
||||||
#define SPEC_HASH 1
|
#define SPEC_HASH (SPEC_PERC + 1)
|
||||||
"<cword>", /* cursor word */
|
"<cword>", /* cursor word */
|
||||||
#define SPEC_CWORD 2
|
#define SPEC_CWORD (SPEC_HASH + 1)
|
||||||
"<cWORD>", /* cursor WORD */
|
"<cWORD>", /* cursor WORD */
|
||||||
#define SPEC_CCWORD 3
|
#define SPEC_CCWORD (SPEC_CWORD + 1)
|
||||||
|
"<cexpr>", /* expr under cursor */
|
||||||
|
#define SPEC_CEXPR (SPEC_CCWORD + 1)
|
||||||
"<cfile>", /* cursor path name */
|
"<cfile>", /* cursor path name */
|
||||||
#define SPEC_CFILE 4
|
#define SPEC_CFILE (SPEC_CEXPR + 1)
|
||||||
"<sfile>", /* ":so" file name */
|
"<sfile>", /* ":so" file name */
|
||||||
#define SPEC_SFILE 5
|
#define SPEC_SFILE (SPEC_CFILE + 1)
|
||||||
"<slnum>", /* ":so" file line number */
|
"<slnum>", /* ":so" file line number */
|
||||||
#define SPEC_SLNUM 6
|
#define SPEC_SLNUM (SPEC_SFILE + 1)
|
||||||
#ifdef FEAT_AUTOCMD
|
#ifdef FEAT_AUTOCMD
|
||||||
"<afile>", /* autocommand file name */
|
"<afile>", /* autocommand file name */
|
||||||
# define SPEC_AFILE 7
|
# define SPEC_AFILE (SPEC_SLNUM + 1)
|
||||||
"<abuf>", /* autocommand buffer number */
|
"<abuf>", /* autocommand buffer number */
|
||||||
# define SPEC_ABUF 8
|
# define SPEC_ABUF (SPEC_AFILE + 1)
|
||||||
"<amatch>", /* autocommand match name */
|
"<amatch>", /* autocommand match name */
|
||||||
# define SPEC_AMATCH 9
|
# define SPEC_AMATCH (SPEC_ABUF + 1)
|
||||||
#endif
|
#endif
|
||||||
#ifdef FEAT_CLIENTSERVER
|
#ifdef FEAT_CLIENTSERVER
|
||||||
"<client>"
|
"<client>"
|
||||||
# ifdef FEAT_AUTOCMD
|
# ifdef FEAT_AUTOCMD
|
||||||
# define SPEC_CLIENT 10
|
# define SPEC_CLIENT (SPEC_AMATCH + 1)
|
||||||
# else
|
# else
|
||||||
# define SPEC_CLIENT 7
|
# define SPEC_CLIENT (SPEC_SLNUM + 1)
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
@@ -10762,10 +10764,13 @@ eval_vars(
|
|||||||
/*
|
/*
|
||||||
* word or WORD under cursor
|
* word or WORD under cursor
|
||||||
*/
|
*/
|
||||||
if (spec_idx == SPEC_CWORD || spec_idx == SPEC_CCWORD)
|
if (spec_idx == SPEC_CWORD || spec_idx == SPEC_CCWORD
|
||||||
|
|| spec_idx == SPEC_CEXPR)
|
||||||
{
|
{
|
||||||
resultlen = find_ident_under_cursor(&result, spec_idx == SPEC_CWORD ?
|
resultlen = find_ident_under_cursor(&result,
|
||||||
(FIND_IDENT|FIND_STRING) : FIND_STRING);
|
spec_idx == SPEC_CWORD ? (FIND_IDENT | FIND_STRING)
|
||||||
|
: spec_idx == SPEC_CEXPR ? (FIND_IDENT | FIND_STRING | FIND_EVAL)
|
||||||
|
: FIND_STRING);
|
||||||
if (resultlen == 0)
|
if (resultlen == 0)
|
||||||
{
|
{
|
||||||
*errormsg = (char_u *)"";
|
*errormsg = (char_u *)"";
|
||||||
|
@@ -389,10 +389,22 @@ func! Test_normal10_expand()
|
|||||||
call setline(1, ['1', 'ifooar,,cbar'])
|
call setline(1, ['1', 'ifooar,,cbar'])
|
||||||
2
|
2
|
||||||
norm! $
|
norm! $
|
||||||
let a=expand('<cword>')
|
call assert_equal('cbar', expand('<cword>'))
|
||||||
let b=expand('<cWORD>')
|
call assert_equal('ifooar,,cbar', expand('<cWORD>'))
|
||||||
call assert_equal('cbar', a)
|
|
||||||
call assert_equal('ifooar,,cbar', b)
|
call setline(1, ['prx = list[idx];'])
|
||||||
|
1
|
||||||
|
let expected = ['', 'prx', 'prx', 'prx',
|
||||||
|
\ 'list', 'list', 'list', 'list', 'list', 'list', 'list',
|
||||||
|
\ 'idx', 'idx', 'idx', 'idx',
|
||||||
|
\ 'list[idx]',
|
||||||
|
\ '];',
|
||||||
|
\ ]
|
||||||
|
for i in range(1, 16)
|
||||||
|
exe 'norm ' . i . '|'
|
||||||
|
call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i)
|
||||||
|
endfor
|
||||||
|
|
||||||
" clean up
|
" clean up
|
||||||
bw!
|
bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
@@ -769,6 +769,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 */
|
||||||
|
/**/
|
||||||
|
1090,
|
||||||
/**/
|
/**/
|
||||||
1089,
|
1089,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user