Patch 8.2.4734
Problem:    getcharpos() may change a mark position.
Solution:   Copy the mark position. (closes #10148)
Files:      src/eval.c, src/testdir/test_cursor_func.vim


*** ../vim-8.2.4733/src/eval.c  2022-04-04 14:58:02.166539812 +0100
--- src/eval.c  2022-04-11 13:04:43.895699670 +0100
***************
*** 5636,5669 ****
      name = tv_get_string_chk(varp);
      if (name == NULL)
        return NULL;
      if (name[0] == '.' && (!in_vim9script() || name[1] == NUL))
      {
        // cursor
        pos = curwin->w_cursor;
-       if (charcol)
-           pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col);
-       return &pos;
      }
!     if (name[0] == 'v' && name[1] == NUL)     // Visual start
      {
        if (VIsual_active)
            pos = VIsual;
        else
            pos = curwin->w_cursor;
-       if (charcol)
-           pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col);
-       return &pos;
      }
!     if (name[0] == '\'' && (!in_vim9script()
                                        || (name[1] != NUL && name[2] == NUL)))
      {
        // mark
        pp = getmark_buf_fnum(curbuf, name[1], FALSE, fnum);
        if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0)
            return NULL;
        if (charcol)
!           pp->col = buf_byteidx_to_charidx(curbuf, pp->lnum, pp->col);
!       return pp;
      }
  
      pos.coladd = 0;
--- 5636,5670 ----
      name = tv_get_string_chk(varp);
      if (name == NULL)
        return NULL;
+ 
+     pos.lnum = 0;
      if (name[0] == '.' && (!in_vim9script() || name[1] == NUL))
      {
        // cursor
        pos = curwin->w_cursor;
      }
!     else if (name[0] == 'v' && name[1] == NUL)
      {
+       // Visual start
        if (VIsual_active)
            pos = VIsual;
        else
            pos = curwin->w_cursor;
      }
!     else if (name[0] == '\'' && (!in_vim9script()
                                        || (name[1] != NUL && name[2] == NUL)))
      {
        // mark
        pp = getmark_buf_fnum(curbuf, name[1], FALSE, fnum);
        if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0)
            return NULL;
+       pos = *pp;
+     }
+     if (pos.lnum != 0)
+     {
        if (charcol)
!           pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col);
!       return &pos;
      }
  
      pos.coladd = 0;
*** ../vim-8.2.4733/src/testdir/test_cursor_func.vim    2022-02-15 
13:40:13.508939677 +0000
--- src/testdir/test_cursor_func.vim    2022-04-11 12:40:43.509892656 +0100
***************
*** 188,199 ****
    call assert_fails('call getcharpos({})', 'E731:')
    call assert_equal([0, 0, 0, 0], getcharpos(0))
    new
!   call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678'])
  
    " Test for '.' and '$'
    normal 1G
    call assert_equal([0, 1, 1, 0], getcharpos('.'))
!   call assert_equal([0, 4, 1, 0], getcharpos('$'))
    normal 2G6l
    call assert_equal([0, 2, 7, 0], getcharpos('.'))
    normal 3G$
--- 188,199 ----
    call assert_fails('call getcharpos({})', 'E731:')
    call assert_equal([0, 0, 0, 0], getcharpos(0))
    new
!   call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678', ' │  x'])
  
    " Test for '.' and '$'
    normal 1G
    call assert_equal([0, 1, 1, 0], getcharpos('.'))
!   call assert_equal([0, 5, 1, 0], getcharpos('$'))
    normal 2G6l
    call assert_equal([0, 2, 7, 0], getcharpos('.'))
    normal 3G$
***************
*** 207,212 ****
--- 207,218 ----
    delmarks m
    call assert_equal([0, 0, 0, 0], getcharpos("'m"))
  
+   " Check mark does not move
+   normal 5Gfxma
+   call assert_equal([0, 5, 5, 0], getcharpos("'a"))
+   call assert_equal([0, 5, 5, 0], getcharpos("'a"))
+   call assert_equal([0, 5, 5, 0], getcharpos("'a"))
+ 
    " Test for the visual start column
    vnoremap <expr> <F3> SaveVisualStartCharPos()
    let g:VisualStartPos = []
*** ../vim-8.2.4733/src/version.c       2022-04-11 11:37:07.994510794 +0100
--- src/version.c       2022-04-11 12:43:32.869853968 +0100
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     4734,
  /**/

-- 
ARTHUR:       Now stand aside worthy adversary.
BLACK KNIGHT: (Glancing at his shoulder) 'Tis but a scratch.
ARTHUR:       A scratch?  Your arm's off.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            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/20220411120720.D110F1C0917%40moolenaar.net.

Raspunde prin e-mail lui