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 <expr> <F3> <Sid>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 <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.
  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 <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 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 -- [email protected] -- 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    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202103171229.12HCTGCI990078%40masaka.moolenaar.net.

Raspunde prin e-mail lui