To: vim_dev@googlegroups.com Subject: Patch 8.2.2612 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2612 Problem: col('.') may get outdated column value. Solution: Add a note to the help how to make this work and add a test for it. (closes #7971) Files: runtime/doc/map.txt, src/testdir/test_mapping.vim *** ../vim-8.2.2611/runtime/doc/map.txt 2021-01-31 17:02:06.254490174 +0100 --- runtime/doc/map.txt 2021-03-17 13:27:13.714877548 +0100 *************** *** 263,268 **** --- 263,282 ---- endfunc nnoremap OpenPopup() + 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 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 before the character that is + expression-mapped: > + nmap ! f!x + Be very careful about side effects! The expression is evaluated while obtaining characters, you may very well make the command dysfunctional. For this reason the following is blocked: *** ../vim-8.2.2611/src/testdir/test_mapping.vim 2020-11-28 14:43:23.950237798 +0100 --- src/testdir/test_mapping.vim 2021-03-17 13:27:12.346881010 +0100 *************** *** 485,490 **** --- 485,514 ---- nmapclear 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 x StoreColumn() + 2 + nmap ! f!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 ExprMapped + nunmap x + nunmap ! + endfunc + func Test_expr_map_restore_cursor() CheckScreendump *** ../vim-8.2.2611/src/version.c 2021-03-17 12:27:20.095476909 +0100 --- src/version.c 2021-03-17 13:22:44.607568369 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2612, /**/ -- Git catch 22: "merge is not possible because you have unmerged files." /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///