Skip to content

Commit 65f0847

Browse files
committed
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>.
1 parent c168bd4 commit 65f0847

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

runtime/doc/cmdline.txt

+5
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,11 @@ Also see |`=|.
830830
Note: these are typed literally, they are not special keys!
831831
<cword> is replaced with the word under the cursor (like |star|)
832832
<cWORD> is replaced with the WORD under the cursor (see |WORD|)
833+
<cexpr> is replaced with the word under the cursor, including more
834+
to form a C expression. E.g., when the cursor is on "arg"
835+
of "ptr->arg" then the result is "ptr->arg"; when the
836+
cursor is on "]" of "list[idx]" then the result is
837+
"list[idx]". This is used for |v:beval_text|.
833838
<cfile> is replaced with the path name under the cursor (like what
834839
|gf| uses)
835840
<afile> When executing autocommands, is replaced with the file name

src/ex_docmd.c

+19-14
Original file line numberDiff line numberDiff line change
@@ -10650,31 +10650,33 @@ find_cmdline_var(char_u *src, int *usedlen)
1065010650
"%",
1065110651
#define SPEC_PERC 0
1065210652
"#",
10653-
#define SPEC_HASH 1
10653+
#define SPEC_HASH (SPEC_PERC + 1)
1065410654
"<cword>", /* cursor word */
10655-
#define SPEC_CWORD 2
10655+
#define SPEC_CWORD (SPEC_HASH + 1)
1065610656
"<cWORD>", /* cursor WORD */
10657-
#define SPEC_CCWORD 3
10657+
#define SPEC_CCWORD (SPEC_CWORD + 1)
10658+
"<cexpr>", /* expr under cursor */
10659+
#define SPEC_CEXPR (SPEC_CCWORD + 1)
1065810660
"<cfile>", /* cursor path name */
10659-
#define SPEC_CFILE 4
10661+
#define SPEC_CFILE (SPEC_CEXPR + 1)
1066010662
"<sfile>", /* ":so" file name */
10661-
#define SPEC_SFILE 5
10663+
#define SPEC_SFILE (SPEC_CFILE + 1)
1066210664
"<slnum>", /* ":so" file line number */
10663-
#define SPEC_SLNUM 6
10665+
#define SPEC_SLNUM (SPEC_SFILE + 1)
1066410666
#ifdef FEAT_AUTOCMD
1066510667
"<afile>", /* autocommand file name */
10666-
# define SPEC_AFILE 7
10668+
# define SPEC_AFILE (SPEC_SLNUM + 1)
1066710669
"<abuf>", /* autocommand buffer number */
10668-
# define SPEC_ABUF 8
10670+
# define SPEC_ABUF (SPEC_AFILE + 1)
1066910671
"<amatch>", /* autocommand match name */
10670-
# define SPEC_AMATCH 9
10672+
# define SPEC_AMATCH (SPEC_ABUF + 1)
1067110673
#endif
1067210674
#ifdef FEAT_CLIENTSERVER
1067310675
"<client>"
1067410676
# ifdef FEAT_AUTOCMD
10675-
# define SPEC_CLIENT 10
10677+
# define SPEC_CLIENT (SPEC_AMATCH + 1)
1067610678
# else
10677-
# define SPEC_CLIENT 7
10679+
# define SPEC_CLIENT (SPEC_SLNUM + 1)
1067810680
# endif
1067910681
#endif
1068010682
};
@@ -10762,10 +10764,13 @@ eval_vars(
1076210764
/*
1076310765
* word or WORD under cursor
1076410766
*/
10765-
if (spec_idx == SPEC_CWORD || spec_idx == SPEC_CCWORD)
10767+
if (spec_idx == SPEC_CWORD || spec_idx == SPEC_CCWORD
10768+
|| spec_idx == SPEC_CEXPR)
1076610769
{
10767-
resultlen = find_ident_under_cursor(&result, spec_idx == SPEC_CWORD ?
10768-
(FIND_IDENT|FIND_STRING) : FIND_STRING);
10770+
resultlen = find_ident_under_cursor(&result,
10771+
spec_idx == SPEC_CWORD ? (FIND_IDENT | FIND_STRING)
10772+
: spec_idx == SPEC_CEXPR ? (FIND_IDENT | FIND_STRING | FIND_EVAL)
10773+
: FIND_STRING);
1076910774
if (resultlen == 0)
1077010775
{
1077110776
*errormsg = (char_u *)"";

src/testdir/test_normal.vim

+16-4
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,22 @@ func! Test_normal10_expand()
389389
call setline(1, ['1', 'ifooar,,cbar'])
390390
2
391391
norm! $
392-
let a=expand('<cword>')
393-
let b=expand('<cWORD>')
394-
call assert_equal('cbar', a)
395-
call assert_equal('ifooar,,cbar', b)
392+
call assert_equal('cbar', expand('<cword>'))
393+
call assert_equal('ifooar,,cbar', expand('<cWORD>'))
394+
395+
call setline(1, ['prx = list[idx];'])
396+
1
397+
let expected = ['', 'prx', 'prx', 'prx',
398+
\ 'list', 'list', 'list', 'list', 'list', 'list', 'list',
399+
\ 'idx', 'idx', 'idx', 'idx',
400+
\ 'list[idx]',
401+
\ '];',
402+
\ ]
403+
for i in range(1, 16)
404+
exe 'norm ' . i . '|'
405+
call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i)
406+
endfor
407+
396408
" clean up
397409
bw!
398410
endfunc

src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
1090,
772774
/**/
773775
1089,
774776
/**/

0 commit comments

Comments
 (0)