Patch 8.2.4160
Problem:    Cannot change the register used for Select mode delete.
Solution:   Make CTRL-R set the register to be used when deleting text for
            Select mode. (Shougo Matsushita, closes #9531)
Files:      runtime/doc/visual.txt, src/globals.h, src/normal.c, src/ops.c,
            src/testdir/test_selectmode.vim


*** ../vim-8.2.4159/runtime/doc/visual.txt      2021-01-31 16:02:06.278490083 
+0000
--- runtime/doc/visual.txt      2022-01-20 15:19:42.313459328 +0000
***************
*** 487,492 ****
--- 488,498 ----
  - ESC stops Select mode.
  - CTRL-O switches to Visual mode for the duration of one command. *v_CTRL-O*
  - CTRL-G switches to Visual mode.
+ - CTRL-R {register} selects the register to be used for the text that is
+   deleted when typing text.                                     *v_CTRL-R*
+   Unless you specify the "_" (black hole) register, the unnamed register is
+   also overwritten.
+ 
  
  Otherwise, typed characters are handled as in Visual mode.
  
*** ../vim-8.2.4159/src/globals.h       2022-01-20 14:57:18.280528244 +0000
--- src/globals.h       2022-01-20 15:13:10.717522503 +0000
***************
*** 875,880 ****
--- 875,882 ----
                                // whether Visual mode is active
  EXTERN int    VIsual_select INIT(= FALSE);
                                // whether Select mode is active
+ EXTERN int    VIsual_select_reg INIT(= 0);
+                               // register name for Select mode
  EXTERN int    restart_VIsual_select INIT(= 0);
                                // restart Select mode when next cmd finished
  EXTERN int    VIsual_reselect;
*** ../vim-8.2.4159/src/normal.c        2022-01-15 18:25:04.657419390 +0000
--- src/normal.c        2022-01-20 15:20:57.035941858 +0000
***************
*** 89,95 ****
  static void   nv_suspend(cmdarg_T *cap);
  static void   nv_g_cmd(cmdarg_T *cap);
  static void   nv_dot(cmdarg_T *cap);
! static void   nv_redo(cmdarg_T *cap);
  static void   nv_Undo(cmdarg_T *cap);
  static void   nv_tilde(cmdarg_T *cap);
  static void   nv_operator(cmdarg_T *cap);
--- 89,95 ----
  static void   nv_suspend(cmdarg_T *cap);
  static void   nv_g_cmd(cmdarg_T *cap);
  static void   nv_dot(cmdarg_T *cap);
! static void   nv_redo_or_register(cmdarg_T *cap);
  static void   nv_Undo(cmdarg_T *cap);
  static void   nv_tilde(cmdarg_T *cap);
  static void   nv_operator(cmdarg_T *cap);
***************
*** 188,194 ****
      {Ctrl_O,  nv_ctrlo,       0,                      0},
      {Ctrl_P,  nv_up,          NV_STS,                 FALSE},
      {Ctrl_Q,  nv_visual,      0,                      FALSE},
!     {Ctrl_R,  nv_redo,        0,                      0},
      {Ctrl_S,  nv_ignore,      0,                      0},
      {Ctrl_T,  nv_tagpop,      NV_NCW,                 0},
      {Ctrl_U,  nv_halfpage,    0,                      0},
--- 188,194 ----
      {Ctrl_O,  nv_ctrlo,       0,                      0},
      {Ctrl_P,  nv_up,          NV_STS,                 FALSE},
      {Ctrl_Q,  nv_visual,      0,                      FALSE},
!     {Ctrl_R,  nv_redo_or_register, 0,                 0},
      {Ctrl_S,  nv_ignore,      0,                      0},
      {Ctrl_T,  nv_tagpop,      NV_NCW,                 0},
      {Ctrl_U,  nv_halfpage,    0,                      0},
***************
*** 1303,1308 ****
--- 1303,1309 ----
            trigger_modechanged();
            showmode();
            restart_VIsual_select = 0;
+           VIsual_select_reg = 0;
        }
        if (restart_edit != 0 && !VIsual_active && old_mapped_len == 0)
            (void)edit(restart_edit, FALSE, 1L);
***************
*** 5997,6003 ****
--- 5998,6007 ----
             * start Select mode.
             */
            if (cap->arg)
+           {
                VIsual_select = TRUE;
+               VIsual_select_reg = 0;
+           }
            else
                may_start_select('c');
            setmouse();
***************
*** 6550,6560 ****
  }
  
  /*
!  * CTRL-R: undo undo
   */
      static void
! nv_redo(cmdarg_T *cap)
  {
      if (!checkclearopq(cap->oap))
      {
        u_redo((int)cap->count1);
--- 6554,6583 ----
  }
  
  /*
!  * CTRL-R: undo undo or specify register in select mode
   */
      static void
! nv_redo_or_register(cmdarg_T *cap)
  {
+     if (VIsual_select && VIsual_active)
+     {
+       int reg;
+       // Get register name
+       ++no_mapping;
+       ++allow_keys;
+       reg = plain_vgetc();
+       LANGMAP_ADJUST(reg, TRUE);
+       --no_mapping;
+       --allow_keys;
+ 
+       if (reg == '"')
+           // the unnamed register is 0
+           reg = 0;
+ 
+         VIsual_select_reg = valid_yank_reg(reg, TRUE) ? reg : 0;
+       return;
+     }
+ 
      if (!checkclearopq(cap->oap))
      {
        u_redo((int)cap->count1);
***************
*** 6926,6932 ****
--- 6949,6958 ----
  nv_select(cmdarg_T *cap)
  {
      if (VIsual_active)
+     {
        VIsual_select = TRUE;
+       VIsual_select_reg = 0;
+     }
      else if (VIsual_reselect)
      {
        cap->nchar = 'v';           // fake "gv" command
*** ../vim-8.2.4159/src/ops.c   2022-01-20 12:10:45.052814746 +0000
--- src/ops.c   2022-01-20 15:22:24.874163917 +0000
***************
*** 624,629 ****
--- 624,633 ----
        return FAIL;
      }
  
+     if (VIsual_select && oap->is_VIsual)
+       // use register given with CTRL_R, defaults to zero
+         oap->regname = VIsual_select_reg;
+ 
  #ifdef FEAT_CLIPBOARD
      adjust_clip_reg(&oap->regname);
  #endif
*** ../vim-8.2.4159/src/testdir/test_selectmode.vim     2021-03-16 
20:17:12.249245839 +0000
--- src/testdir/test_selectmode.vim     2022-01-20 15:25:14.670741739 +0000
***************
*** 258,261 ****
--- 258,313 ----
    bwipe!
  endfunc
  
+ " Test for selecting a register with CTRL-R
+ func Test_selectmode_register()
+   new
+ 
+   " Default behavior: use unnamed register
+   call setline(1, 'foo')
+   call setreg('"', 'bar')
+   call setreg('a', 'baz')
+   exe ":norm! v\<c-g>a"
+   call assert_equal(getline('.'), 'aoo')
+   call assert_equal('f', getreg('"'))
+   call assert_equal('baz', getreg('a'))
+ 
+   " Use the black hole register
+   call setline(1, 'foo')
+   call setreg('"', 'bar')
+   call setreg('a', 'baz')
+   exe ":norm! v\<c-g>\<c-r>_a"
+   call assert_equal(getline('.'), 'aoo')
+   call assert_equal('bar', getreg('"'))
+   call assert_equal('baz', getreg('a'))
+ 
+   " Invalid register: use unnamed register
+   call setline(1, 'foo')
+   call setreg('"', 'bar')
+   call setreg('a', 'baz')
+   exe ":norm! v\<c-g>\<c-r>?a"
+   call assert_equal(getline('.'), 'aoo')
+   call assert_equal('f', getreg('"'))
+   call assert_equal('baz', getreg('a'))
+ 
+   " Use unnamed register
+   call setline(1, 'foo')
+   call setreg('"', 'bar')
+   call setreg('a', 'baz')
+   exe ":norm! v\<c-g>\<c-r>\"a"
+   call assert_equal(getline('.'), 'aoo')
+   call assert_equal('f', getreg('"'))
+   call assert_equal('baz', getreg('a'))
+ 
+   " use specicifed register, unnamed register is also written
+   call setline(1, 'foo')
+   call setreg('"', 'bar')
+   call setreg('a', 'baz')
+   exe ":norm! v\<c-g>\<c-r>aa"
+   call assert_equal(getline('.'), 'aoo')
+   call assert_equal('f', getreg('"'))
+   call assert_equal('f', getreg('a'))
+ 
+   bw!
+ endfunc
+ 
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.4159/src/version.c       2022-01-20 15:10:53.684409333 +0000
--- src/version.c       2022-01-20 15:15:14.482949206 +0000
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4160,
  /**/

-- 
ARTHUR: Did you say shrubberies?
ROGER:  Yes.  Shrubberies are my trade.  I am a shrubber.  My name is Roger
        the Shrubber.  I arrange, design, and sell shrubberies.
                 "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/20220120152632.46DA01C188D%40moolenaar.net.

Raspunde prin e-mail lui