Patch 9.0.1061
Problem:    Cannot display 'showcmd' somewhere else.
Solution:   Add the 'showcmdloc' option. (Luuk van Baal, closes #11684)
Files:      runtime/doc/options.txt, src/buffer.c, src/drawscreen.c,
            src/proto/drawscreen.pro, src/globals.h, src/normal.c,
            src/option.h, src/optiondefs.h, src/optionstr.c, src/screen.c,
            src/testdir/gen_opt_test.vim, src/testdir/test_statusline.vim,
            src/testdir/test_tabline.vim,
            src/testdir/dumps/Test_statusline_showcmd_1.dump,
            src/testdir/dumps/Test_statusline_showcmd_2.dump,
            src/testdir/dumps/Test_statusline_showcmd_3.dump,
            src/testdir/dumps/Test_tabline_showcmd_1.dump,
            src/testdir/dumps/Test_tabline_showcmd_2.dump


*** ../vim-9.0.1060/runtime/doc/options.txt     2022-11-30 10:23:11.691069019 
+0000
--- runtime/doc/options.txt     2022-12-15 13:00:12.484643257 +0000
***************
*** 7183,7191 ****
--- 7220,7244 ----
        - When selecting more than one line, the number of lines.
        - When selecting a block, the size in screen characters:
          {lines}x{columns}.
+       This information can be displayed in an alternative location using the
+       'showcmdloc' option.
        NOTE: This option is set to the Vi default value when 'compatible' is
        set and to the Vim default value when 'compatible' is reset.
  
+                       *'showcmdloc'* *'sloc'*
+ 'showcmdloc' 'sloc'   string  (default "last")
+       This option can be used to display the (partially) entered command in
+       another location.  Possible values are:
+         last          Last line of the screen (default).
+         statusline    Status line of the current window.
+         tabline       First line of the screen if 'showtabine' is enabled.
+       Setting this option to "statusline" or "tabline" means that these will
+       be redrawn whenever the command changes, which can be on every key
+       pressed.
+       The %S 'statusline' item can be used in 'statusline' or 'tabline' to
+       place the text.  Without a custom 'statusline' or 'tabline' it will be
+       displayed in a convenient location.
+ 
                        *'showfulltag'* *'sft'* *'noshowfulltag'* *'nosft'*
  'showfulltag' 'sft'   boolean (default off)
                        global
***************
*** 7680,7685 ****
--- 7736,7742 ----
        P S   Percentage through file of displayed window.  This is like the
              percentage described for 'ruler'.  Always 3 in length, unless
              translated.
+       S S   'showcmd' content, see 'showcmdloc'.
        a S   Argument list status as in default title.  ({current} of {max})
              Empty if the argument file count is zero or one.
        { NF  Evaluate expression between '%{' and '}' and substitute result.
*** ../vim-9.0.1060/src/buffer.c        2022-11-28 18:51:38.959571588 +0000
--- src/buffer.c        2022-12-15 12:51:06.062025524 +0000
***************
*** 4775,4780 ****
--- 4775,4785 ----
            get_rel_pos(wp, str, TMPLEN);
            break;
  
+       case STL_SHOWCMD:
+           if (p_sc && STRCMP(opt_name, p_sloc) == 0)
+               str = showcmd_buf;
+           break;
+ 
        case STL_ARGLISTSTAT:
            fillable = FALSE;
            buf_tmp[0] = 0;
*** ../vim-9.0.1060/src/drawscreen.c    2022-11-29 16:09:14.408617365 +0000
--- src/drawscreen.c    2022-12-15 12:51:06.062025524 +0000
***************
*** 73,80 ****
  static int  did_update_one_window;
  #endif
  
- static void win_redr_status(win_T *wp, int ignore_pum);
- 
  /*
   * Based on the current value of curwin->w_topline, transfer a screenfull
   * of stuff from Filemem to ScreenLines[], and update curwin->w_botline.
--- 73,78 ----
***************
*** 423,429 ****
   * If "ignore_pum" is TRUE, also redraw statusline when the popup menu is
   * displayed.
   */
!     static void
  win_redr_status(win_T *wp, int ignore_pum UNUSED)
  {
      int               row;
--- 421,427 ----
   * If "ignore_pum" is TRUE, also redraw statusline when the popup menu is
   * displayed.
   */
!     void
  win_redr_status(win_T *wp, int ignore_pum UNUSED)
  {
      int               row;
***************
*** 548,553 ****
--- 546,561 ----
                                                   - 1 + wp->w_wincol), attr);
  
        win_redr_ruler(wp, TRUE, ignore_pum);
+ 
+       // Draw the 'showcmd' information if 'showcmdloc' == "statusline".
+       if (p_sc && *p_sloc == 's')
+       {
+           int width = MIN(10, this_ru_col - len - 2);
+ 
+           if (width > 0)
+               screen_puts_len(showcmd_buf, width, row,
+                               wp->w_wincol + this_ru_col - width - 1, attr);
+       }
      }
  
      /*
*** ../vim-9.0.1060/src/proto/drawscreen.pro    2022-08-22 15:19:12.728328961 
+0100
--- src/proto/drawscreen.pro    2022-12-15 13:03:42.992300508 +0000
***************
*** 1,6 ****
--- 1,7 ----
  /* drawscreen.c */
  int update_screen(int type_arg);
  int statusline_row(win_T *wp);
+ void win_redr_status(win_T *wp, int ignore_pum);
  void showruler(int always);
  void win_redr_ruler(win_T *wp, int always, int ignore_pum);
  void after_updating_screen(int may_resize_shell);
*** ../vim-9.0.1060/src/globals.h       2022-12-09 12:21:46.473444271 +0000
--- src/globals.h       2022-12-15 12:51:06.062025524 +0000
***************
*** 2038,2040 ****
--- 2038,2044 ----
  EXTERN int skip_win_fix_scroll INIT(= FALSE);
  // Skip update_topline() call while executing win_fix_scroll().
  EXTERN int skip_update_topline INIT(= FALSE);
+ 
+ // 'showcmd' buffer shared between normal.c and statusline.c
+ #define SHOWCMD_BUFLEN (SHOWCMD_COLS + 1 + 30)
+ EXTERN char_u showcmd_buf[SHOWCMD_BUFLEN];
*** ../vim-9.0.1060/src/normal.c        2022-12-01 12:03:42.263227523 +0000
--- src/normal.c        2022-12-15 13:08:26.267921244 +0000
***************
*** 1574,1581 ****
   * Routines for displaying a partly typed command
   */
  
- #define SHOWCMD_BUFLEN (SHOWCMD_COLS + 1 + 30)
- static char_u showcmd_buf[SHOWCMD_BUFLEN];
  static char_u old_showcmd_buf[SHOWCMD_BUFLEN];  // For push_showcmd()
  static int    showcmd_is_clear = TRUE;
  static int    showcmd_visual = FALSE;
--- 1574,1579 ----
***************
*** 1798,1819 ****
      static void
  display_showcmd(void)
  {
!     int           len;
  
      cursor_off();
  
!     len = (int)STRLEN(showcmd_buf);
!     if (len == 0)
!       showcmd_is_clear = TRUE;
!     else
      {
!       screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0);
!       showcmd_is_clear = FALSE;
!     }
  
!     // clear the rest of an old message by outputting up to SHOWCMD_COLS
!     // spaces
!     screen_puts((char_u *)"          " + len, (int)Rows - 1, sc_col + len, 0);
  
      setcursor();          // put cursor back where it belongs
  }
--- 1796,1820 ----
      static void
  display_showcmd(void)
  {
!     int           len = (int)STRLEN(showcmd_buf);
  
+     showcmd_is_clear = (len == 0);
      cursor_off();
  
!     if (*p_sloc == 's')
!       win_redr_status(curwin, FALSE);
!     else if (*p_sloc == 't')
!       draw_tabline();
!     else // 'showcmdloc' is "last" or empty
      {
!       if (!showcmd_is_clear)
!           screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0);
  
!       // clear the rest of an old message by outputting up to SHOWCMD_COLS
!       // spaces
!       screen_puts((char_u *)"          " + len,
!                                               (int)Rows - 1, sc_col + len, 0);
!     }
  
      setcursor();          // put cursor back where it belongs
  }
*** ../vim-9.0.1060/src/option.h        2022-11-23 20:19:17.133682464 +0000
--- src/option.h        2022-12-15 12:51:06.066025510 +0000
***************
*** 343,348 ****
--- 343,349 ----
  #define STL_ALTPERCENT        'P'             // percentage as TOP BOT ALL or 
NN%
  #define STL_ARGLISTSTAT       'a'             // argument list status as (x 
of y)
  #define STL_PAGENUM   'N'             // page number (when printing)
+ #define STL_SHOWCMD   'S'             // 'showcmd' buffer
  #define STL_VIM_EXPR  '{'             // start of expression to substitute
  #define STL_MIDDLEMARK        '='             // separation between left and 
right
  #define STL_TRUNCMARK '<'             // truncation mark if line is too long
***************
*** 350,356 ****
  #define STL_HIGHLIGHT '#'             // highlight name
  #define STL_TABPAGENR 'T'             // tab page label nr
  #define STL_TABCLOSENR        'X'             // tab page close nr
! #define STL_ALL               ((char_u *) "fFtcvVlLknoObBrRhHmYyWwMqpPaN{#")
  
  // flags used for parsed 'wildmode'
  #define WIM_FULL      0x01
--- 351,357 ----
  #define STL_HIGHLIGHT '#'             // highlight name
  #define STL_TABPAGENR 'T'             // tab page label nr
  #define STL_TABCLOSENR        'X'             // tab page close nr
! #define STL_ALL               ((char_u *) "fFtcvVlLknoObBrRhHmYyWwMqpPaNS{#")
  
  // flags used for parsed 'wildmode'
  #define WIM_FULL      0x01
***************
*** 892,897 ****
--- 893,899 ----
  EXTERN char_u *p_sbr;         // 'showbreak'
  #endif
  EXTERN int    p_sc;           // 'showcmd'
+ EXTERN char_u *p_sloc;        // 'showcmdloc'
  EXTERN int    p_sft;          // 'showfulltag'
  EXTERN int    p_sm;           // 'showmatch'
  EXTERN int    p_smd;          // 'showmode'
*** ../vim-9.0.1060/src/optiondefs.h    2022-12-01 19:25:00.444755203 +0000
--- src/optiondefs.h    2022-12-15 13:11:09.611730388 +0000
***************
*** 2240,2245 ****
--- 2240,2248 ----
                                (char_u *)TRUE
  #endif
                                } SCTX_INIT},
+     {"showcmdloc",  "sloc", P_STRING|P_RSTAT,
+                           (char_u *)&p_sloc, PV_NONE,
+                           {(char_u *)"last", (char_u *)"last"} SCTX_INIT},
      {"showfulltag", "sft",  P_BOOL|P_VI_DEF,
                            (char_u *)&p_sft, PV_NONE,
                            {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
*** ../vim-9.0.1060/src/optionstr.c     2022-11-28 11:36:46.295659899 +0000
--- src/optionstr.c     2022-12-15 12:51:06.066025510 +0000
***************
*** 93,98 ****
--- 93,99 ----
  #if defined(MSWIN) && defined(FEAT_TERMINAL)
  static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
  #endif
+ static char *(p_sloc_values[]) = {"last", "statusline", "tabline", NULL};
  
  static int check_opt_strings(char_u *val, char **values, int list);
  static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int 
list);
***************
*** 1894,1899 ****
--- 1895,1906 ----
      }
  #endif
  
+     // 'showcmdloc'
+     else if (varp == &p_sloc)
+     {
+       if (check_opt_strings(p_sloc, p_sloc_values, FALSE) != OK)
+           errmsg = e_invalid_argument;
+     }
  
  #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
      // 'toolbar'
*** ../vim-9.0.1060/src/screen.c        2022-11-28 20:34:47.708140332 +0000
--- src/screen.c        2022-12-15 12:51:06.066025510 +0000
***************
*** 4389,4396 ****
            c = ' ';
        screen_fill(0, 1, col, (int)Columns, c, c, attr_fill);
  
        // Put an "X" for closing the current tab if there are several.
!       if (first_tabpage->tp_next != NULL)
        {
            screen_putchar('X', 0, (int)Columns - 1, attr_nosel);
            TabPageIdxs[Columns - 1] = -999;
--- 4389,4406 ----
            c = ' ';
        screen_fill(0, 1, col, (int)Columns, c, c, attr_fill);
  
+       // Draw the 'showcmd' information if 'showcmdloc' == "tabline".
+       if (p_sc && *p_sloc == 't')
+       {
+           int width = MIN(10, (int)Columns - col - (tabcount > 1) * 3);
+ 
+           if (width > 0)
+               screen_puts_len(showcmd_buf, width, 0, (int)Columns
+                           - width - (tabcount > 1) * 2, attr_nosel);
+       }
+ 
        // Put an "X" for closing the current tab if there are several.
!       if (tabcount > 1)
        {
            screen_putchar('X', 0, (int)Columns - 1, attr_nosel);
            TabPageIdxs[Columns - 1] = -999;
*** ../vim-9.0.1060/src/testdir/gen_opt_test.vim        2022-11-23 
20:19:17.133682464 +0000
--- src/testdir/gen_opt_test.vim        2022-12-15 12:51:06.066025510 +0000
***************
*** 132,137 ****
--- 132,138 ----
        \ 'selection': [['old', 'inclusive'], ['', 'xxx']],
        \ 'selectmode': [['', 'mouse', 'key,cmd'], ['xxx']],
        \ 'sessionoptions': [['', 'blank', 'help,options,slash'], ['xxx']],
+       \ 'showcmdloc': [['last', 'statusline', 'tabline'], ['xxx']],
        \ 'signcolumn': [['', 'auto', 'no'], ['xxx', 'no,yes']],
        \ 'spellfile': [['', 'file.en.add', '/tmp/dir\ with\ 
space/en.utf-8.add'], ['xxx', '/tmp/file']],
        \ 'spelllang': [['', 'xxx', 'sr@latin'], ['not&lang', "that\\\rthere"]],
*** ../vim-9.0.1060/src/testdir/test_statusline.vim     2022-10-10 
22:39:38.207545888 +0100
--- src/testdir/test_statusline.vim     2022-12-15 12:51:06.066025510 +0000
***************
*** 558,561 ****
--- 558,583 ----
    call StopVimInTerminal(buf)
  endfunc
  
+ func Test_statusline_showcmd()
+   CheckScreendump
+ 
+   let lines =<< trim END
+     set laststatus=2
+     set statusline=%S
+     set showcmdloc=statusline
+     call setline(1, ['a', 'b', 'c'])
+   END
+   call writefile(lines, 'XTest_statusline', 'D')
+ 
+   let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 6})
+   call feedkeys("\<C-V>Gl", "xt")
+   call VerifyScreenDump(buf, 'Test_statusline_showcmd_1', {})
+ 
+   call feedkeys("\<Esc>1234", "xt")
+   call VerifyScreenDump(buf, 'Test_statusline_showcmd_2', {})
+ 
+   call feedkeys("\<Esc>:set statusline=\<CR>:\<CR>1234", "xt")
+   call VerifyScreenDump(buf, 'Test_statusline_showcmd_3', {})
+ endfunc
+ 
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-9.0.1060/src/testdir/test_tabline.vim        2022-10-15 
20:52:22.559752564 +0100
--- src/testdir/test_tabline.vim        2022-12-15 12:51:06.066025510 +0000
***************
*** 1,6 ****
--- 1,9 ----
  " Test for tabline
  
  source shared.vim
+ source view_util.vim
+ source check.vim
+ source screendump.vim
  
  func TablineWithCaughtError()
    let s:func_in_tabline_called = 1
***************
*** 158,162 ****
--- 161,183 ----
    call RunVim([], [], "-e -s -S Xclickscript -c qa")
  endfunc
  
+ func Test_tabline_showcmd()
+   CheckScreendump
+ 
+   let lines =<< trim END
+     set showtabline=2
+     set showcmdloc=tabline
+     call setline(1, ['a', 'b', 'c'])
+   END
+   call writefile(lines, 'XTest_tabline', 'D')
+ 
+   let buf = RunVimInTerminal('-S XTest_tabline', {'rows': 6})
+ 
+   call feedkeys("\<C-V>Gl", "xt")
+   call VerifyScreenDump(buf, 'Test_tabline_showcmd_1', {})
+ 
+   call feedkeys("\<Esc>1234", "xt")
+   call VerifyScreenDump(buf, 'Test_tabline_showcmd_2', {})
+ endfunc
  
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-9.0.1060/src/testdir/dumps/Test_statusline_showcmd_1.dump    
2022-12-15 13:12:43.895626634 +0000
--- src/testdir/dumps/Test_statusline_showcmd_1.dump    2022-12-15 
12:51:06.066025510 +0000
***************
*** 0 ****
--- 1,6 ----
+ |a+0&#e0e0e08| +0&#ffffff0@73
+ |b+0&#e0e0e08| +0&#ffffff0@73
+ |c+0&#e0e0e08> +0&#ffffff0@73
+ |~+0#4040ff13&| @73
+ |3+3#0000000&|x|2| @71
+ |-+2&&@1| |V|I|S|U|A|L| |B|L|O|C|K| |-@1| +0&&@56
*** ../vim-9.0.1060/src/testdir/dumps/Test_statusline_showcmd_2.dump    
2022-12-15 13:12:43.899626628 +0000
--- src/testdir/dumps/Test_statusline_showcmd_2.dump    2022-12-15 
12:51:06.066025510 +0000
***************
*** 0 ****
--- 1,6 ----
+ |a+0&#ffffff0| @73
+ |b| @73
+ >c| @73
+ |~+0#4040ff13&| @73
+ |1+3#0000000&|2|3|4| @70
+ | +0&&@74
*** ../vim-9.0.1060/src/testdir/dumps/Test_statusline_showcmd_3.dump    
2022-12-15 13:12:43.903626624 +0000
--- src/testdir/dumps/Test_statusline_showcmd_3.dump    2022-12-15 
12:51:06.066025510 +0000
***************
*** 0 ****
--- 1,6 ----
+ |a+0&#ffffff0| @73
+ |b| @73
+ >c| @73
+ |~+0#4040ff13&| @73
+ |[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @32|1|2|3|4| @6|3|,|1| @11|A|l@1
+ |:+0&&| @73
*** ../vim-9.0.1060/src/testdir/dumps/Test_tabline_showcmd_1.dump       
2022-12-15 13:12:43.907626622 +0000
--- src/testdir/dumps/Test_tabline_showcmd_1.dump       2022-12-15 
12:51:06.066025510 +0000
***************
*** 0 ****
--- 1,6 ----
+ | +2&#ffffff0|+| |[|N|o| |N|a|m|e|]| | +1&&@51|3+8#0000001#e0e0e08|x|2| 
+1#0000000#ffffff0@6
+ |a+0&#e0e0e08| +0&#ffffff0@73
+ |b+0&#e0e0e08| +0&#ffffff0@73
+ |c+0&#e0e0e08> +0&#ffffff0@73
+ |~+0#4040ff13&| @73
+ |-+2#0000000&@1| |V|I|S|U|A|L| |B|L|O|C|K| |-@1| +0&&@38|3|,|2| @10|A|l@1| 
*** ../vim-9.0.1060/src/testdir/dumps/Test_tabline_showcmd_2.dump       
2022-12-15 13:12:43.911626615 +0000
--- src/testdir/dumps/Test_tabline_showcmd_2.dump       2022-12-15 
12:51:06.066025510 +0000
***************
*** 0 ****
--- 1,6 ----
+ | +2&#ffffff0|+| |[|N|o| |N|a|m|e|]| | +1&&@51|1+8#0000001#e0e0e08|2|3|4| 
+1#0000000#ffffff0@5
+ |a+0&&| @73
+ |b| @73
+ >c| @73
+ |~+0#4040ff13&| @73
+ | +0#0000000&@56|3|,|1| @10|A|l@1| 
*** ../vim-9.0.1060/src/version.c       2022-12-14 20:54:52.411699476 +0000
--- src/version.c       2022-12-15 12:54:01.653470992 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     1061,
  /**/

-- 
You were lucky to have a LAKE! There were a hundred and sixty of
us living in a small shoebox in the middle of the road.

 /// 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/20221215131614.5CD321C0395%40moolenaar.net.

Raspunde prin e-mail lui