Merge pull request #14248 from andymass/vim-8.2.2612

[RFC] vim-patch 8.2.{2612,2613}
This commit is contained in:
Jan Edmund Lazo 2021-03-29 20:46:44 -04:00 committed by GitHub
commit 3f447d928d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View File

@ -224,6 +224,20 @@ text before the cursor and start omni completion when some condition is met.
For abbreviations |v:char| is set to the character that was typed to trigger
the abbreviation. You can use this to decide how to expand the {lhs}. You
should not either insert or change the v:char.
Also, keep in mind that the expression may be evaluated when looking for
typeahead, before the previous command has been executed. For example: >
func StoreColumn()
let g:column = col('.')
return 'x'
endfunc
nnoremap <expr> x StoreColumn()
nmap ! f!x
You will notice that g:column has the value from before executing "fx",
because "z" is evaluated before "fx" is executed.
This can be solved by inserting <Ignore> before the character that is
expression-mapped: >
nmap ! f!<Ignore>x
Be very careful about side effects! The expression is evaluated while
obtaining characters, you may very well make the command dysfunctional.

View File

@ -427,6 +427,30 @@ func Test_error_in_map_expr()
exe buf .. 'bwipe!'
endfunc
func Test_expr_map_gets_cursor()
new
call setline(1, ['one', 'some w!rd'])
func StoreColumn()
let g:exprLine = line('.')
let g:exprCol = col('.')
return 'x'
endfunc
nnoremap <expr> x StoreColumn()
2
nmap ! f!<Ignore>x
call feedkeys("!", 'xt')
call assert_equal('some wrd', getline(2))
call assert_equal(2, g:exprLine)
call assert_equal(7, g:exprCol)
bwipe!
unlet g:exprLine
unlet g:exprCol
delfunc StoreColumn
nunmap x
nunmap !
endfunc
" Test for mapping errors
func Test_map_error()
call assert_fails('unmap', 'E474:')