File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -263,6 +263,20 @@ input. Example: >
263263 endfunc
264264 nnoremap <expr> <F3> <Sid>OpenPopup()
265265
266+ Also, keep in mind that the expression may be evaluated when looking for
267+ typeahead, before the previous command has been executed. For example: >
268+ func StoreColumn()
269+ let g:column = col('.')
270+ return 'x'
271+ endfunc
272+ nnoremap <expr> x StoreColumn()
273+ nmap ! f!x
274+ You will notice that g:column has the value from before executing "fx",
275+ because "z" is evaluated before "fx" is executed.
276+ This can be solved by inserting <Ignore> before the character that is
277+ expression-mapped: >
278+ nmap ! f!<Ignore>x
279+
266280 Be very careful about side effects! The expression is evaluated while
267281obtaining characters, you may very well make the command dysfunctional.
268282For this reason the following is blocked:
Original file line number Diff line number Diff line change @@ -485,6 +485,30 @@ func Test_list_mappings()
485485 nmapclear
486486endfunc
487487
488+ func Test_expr_map_gets_cursor ()
489+ new
490+ call setline (1 , [' one' , ' some w!rd' ])
491+ func StoreColumn ()
492+ let g: exprLine = line (' .' )
493+ let g: exprCol = col (' .' )
494+ return ' x'
495+ endfunc
496+ nnoremap <expr> x StoreColumn()
497+ 2
498+ nmap ! f!<Ignore> x
499+ call feedkeys (" !" , ' xt' )
500+ call assert_equal (' some wrd' , getline (2 ))
501+ call assert_equal (2 , g: exprLine )
502+ call assert_equal (7 , g: exprCol )
503+
504+ bwipe!
505+ unlet g: exprLine
506+ unlet g: exprCol
507+ delfunc ExprMapped
508+ nunmap x
509+ nunmap !
510+ endfunc
511+
488512func Test_expr_map_restore_cursor ()
489513 CheckScreendump
490514
Original file line number Diff line number Diff line change @@ -750,6 +750,8 @@ static char *(features[]) =
750750
751751static int included_patches [] =
752752{ /* Add new patch number below this line */
753+ /**/
754+ 2612 ,
753755/**/
754756 2611 ,
755757/**/
You can’t perform that action at this time.
0 commit comments