Patch 9.0.0114
Problem:    The command line takes up space even when not used.
Solution:   Allow for 'cmdheight' to be set to zero. (Shougo Matsushita,
            closes #10675, closes #940)
Files:      runtime/doc/options.txt, src/drawscreen.c, src/ex_cmds.c,
            src/ex_getln.c, src/getchar.c, src/message.c, src/normal.c,
            src/ops.c, src/option.c, src/register.c, src/screen.c,
            src/testdir/gen_opt_test.vim, src/window.c,
            src/testdir/test_messages.vim, src/testdir/test_window_cmd.vim


*** ../vim-9.0.0113/runtime/doc/options.txt     2022-07-04 17:34:06.382292138 
+0100
--- runtime/doc/options.txt     2022-07-30 16:28:40.961578705 +0100
***************
*** 1760,1771 ****
  
                                                *'cmdheight'* *'ch'*
  'cmdheight' 'ch'      number  (default 1)
!                       global
        Number of screen lines to use for the command-line.  Helps avoiding
        |hit-enter| prompts.
        The value of this option is stored with the tab page, so that each tab
        page can have a different value.
  
                                                *'cmdwinheight'* *'cwh'*
  'cmdwinheight' 'cwh'  number  (default 7)
                        global
--- 1760,1774 ----
  
                                                *'cmdheight'* *'ch'*
  'cmdheight' 'ch'      number  (default 1)
!                       global or local to tab page
        Number of screen lines to use for the command-line.  Helps avoiding
        |hit-enter| prompts.
        The value of this option is stored with the tab page, so that each tab
        page can have a different value.
  
+       When 'cmdheight' is zero, there is no command-line unless it is being
+       used.  Any messages will cause the |hit-enter| prompt.
+ 
                                                *'cmdwinheight'* *'cwh'*
  'cmdwinheight' 'cwh'  number  (default 7)
                        global
***************
*** 6446,6454 ****
                45%     relative position in the file
        If 'rulerformat' is set, it will determine the contents of the ruler.
        Each window has its own ruler.  If a window has a status line, the
!       ruler is shown there.  Otherwise it is shown in the last line of the
!       screen.  If the statusline is given by 'statusline' (i.e. not empty),
!       this option takes precedence over 'ruler' and 'rulerformat'
        If the number of characters displayed is different from the number of
        bytes in the text (e.g., for a TAB or a multibyte character), both
        the text column (byte number) and the screen column are shown,
--- 6449,6459 ----
                45%     relative position in the file
        If 'rulerformat' is set, it will determine the contents of the ruler.
        Each window has its own ruler.  If a window has a status line, the
!       ruler is shown there.  If a window doesn't have a status line and
!       'cmdheight' is zero, the ruler is not shown.  Otherwise it is shown in
!       the last line of the screen.  If the statusline is given by
!       'statusline' (i.e. not empty), this option takes precedence over
!       'ruler' and 'rulerformat'
        If the number of characters displayed is different from the number of
        bytes in the text (e.g., for a TAB or a multibyte character), both
        the text column (byte number) and the screen column are shown,
***************
*** 7098,7103 ****
--- 7103,7109 ----
                        |+cmdline_info| feature}
        Show (partial) command in the last line of the screen.  Set this
        option off if your terminal is slow.
+       The option has no effect when 'cmdheight' is zero.
        In Visual mode the size of the selected area is shown:
        - When selecting characters within a line, the number of characters.
          If the number of bytes is different it is also displayed: "2-6"
***************
*** 7147,7152 ****
--- 7153,7159 ----
        If in Insert, Replace or Visual mode put a message on the last line.
        Use the 'M' flag in 'highlight' to set the type of highlighting for
        this message.
+       The option has no effect when 'cmdheight' is zero.
        When |XIM| may be used the message will include "XIM".  But this
        doesn't mean XIM is really active, especially when 'imactivatekey' is
        not set.
*** ../vim-9.0.0113/src/drawscreen.c    2022-07-04 17:34:06.386292140 +0100
--- src/drawscreen.c    2022-07-30 16:52:23.039933894 +0100
***************
*** 649,656 ****
      int               off = 0;
      int               width;
  
!     // If 'ruler' off or redrawing disabled, don't do anything
!     if (!p_ru)
        return;
  
      /*
--- 649,656 ----
      int               off = 0;
      int               width;
  
!     // If 'ruler' off or messages area disabled, don't do anything
!     if (!p_ru || (wp->w_status_height == 0 && p_ch == 0))
        return;
  
      /*
***************
*** 671,677 ****
        return;
  
  #ifdef FEAT_STL_OPT
!     if (*p_ruf)
      {
        int     called_emsg_before = called_emsg;
  
--- 671,677 ----
        return;
  
  #ifdef FEAT_STL_OPT
!     if (*p_ruf && p_ch > 0)
      {
        int     called_emsg_before = called_emsg;
  
***************
*** 2506,2512 ****
            // Past end of the window or end of the screen. Note that after
            // resizing wp->w_height may be end up too big. That's a problem
            // elsewhere, but prevent a crash here.
!           if (row > wp->w_height || row + wp->w_winrow >= Rows)
            {
                // we may need the size of that too long line later on
                if (dollar_vcol == -1)
--- 2506,2513 ----
            // Past end of the window or end of the screen. Note that after
            // resizing wp->w_height may be end up too big. That's a problem
            // elsewhere, but prevent a crash here.
!           if (row > wp->w_height
!                   || row + wp->w_winrow >= (p_ch > 0 ? Rows : Rows + 1))
            {
                // we may need the size of that too long line later on
                if (dollar_vcol == -1)
***************
*** 2560,2566 ****
  
        // Safety check: if any of the wl_size values is wrong we might go over
        // the end of w_lines[].
!       if (idx >= Rows)
            break;
      }
  
--- 2561,2567 ----
  
        // Safety check: if any of the wl_size values is wrong we might go over
        // the end of w_lines[].
!       if (idx >= (p_ch > 0 ? Rows : Rows + 1))
            break;
      }
  
***************
*** 2946,2953 ****
      schar_T   *screenline2 = NULL;    // copy from ScreenLines2[]
  
      redraw_later(type);
!     if (msg_scrolled || (State != MODE_NORMAL && State != MODE_NORMAL_BUSY)
!                                                                   || exiting)
        return ret;
  
      // Allocate space to save the text displayed in the command line area.
--- 2947,2956 ----
      schar_T   *screenline2 = NULL;    // copy from ScreenLines2[]
  
      redraw_later(type);
!     if (msg_scrolled
!           || (State != MODE_NORMAL && State != MODE_NORMAL_BUSY)
!           || exiting
!           || p_ch == 0)
        return ret;
  
      // Allocate space to save the text displayed in the command line area.
*** ../vim-9.0.0113/src/ex_cmds.c       2022-07-26 19:44:52.916896633 +0100
--- src/ex_cmds.c       2022-07-30 16:52:01.971986996 +0100
***************
*** 3704,3709 ****
--- 3704,3710 ----
      int               endcolumn = FALSE;      // cursor in last column when 
done
      pos_T     old_cursor = curwin->w_cursor;
      int               start_nsubs;
+     int               cmdheight0 = p_ch == 0;
  #ifdef FEAT_EVAL
      int               save_ma = 0;
      int               save_sandbox = 0;
***************
*** 4010,4015 ****
--- 4011,4024 ----
        }
      }
  
+     if (cmdheight0)
+     {
+       // If cmdheight is 0, cmdheight must be set to 1 when we enter command
+       // line.
+       set_option_value((char_u *)"ch", 1L, NULL, 0);
+       redraw_statuslines();
+     }
+ 
      /*
       * Check for a match on each line.
       */
***************
*** 4833,4838 ****
--- 4842,4851 ----
        changed_window_setting();
  #endif
  
+     // Restore cmdheight
+     if (cmdheight0)
+       set_option_value((char_u *)"ch", 0L, NULL, 0);
+ 
      vim_regfree(regmatch.regprog);
      vim_free(sub_copy);
  
*** ../vim-9.0.0113/src/ex_getln.c      2022-07-28 12:34:06.527917764 +0100
--- src/ex_getln.c      2022-07-30 16:52:36.807899753 +0100
***************
*** 1611,1616 ****
--- 1611,1625 ----
      int               did_save_ccline = FALSE;
      int               cmdline_type;
      int               wild_type;
+     int               cmdheight0 = p_ch == 0;
+ 
+     if (cmdheight0)
+     {
+       // If cmdheight is 0, cmdheight must be set to 1 when we enter command
+       // line.
+       set_option_value((char_u *)"ch", 1L, NULL, 0);
+       update_screen(VALID);                 // redraw the screen NOW
+     }
  
      // one recursion level deeper
      ++depth;
***************
*** 2595,2600 ****
--- 2604,2616 ----
      {
        char_u *p = ccline.cmdbuff;
  
+       if (cmdheight0)
+       {
+           set_option_value((char_u *)"ch", 0L, NULL, 0);
+           // Redraw is needed for command line completion
+           redraw_all_later(CLEAR);
+       }
+ 
        --depth;
        if (did_save_ccline)
            restore_cmdline(&save_ccline);
*** ../vim-9.0.0113/src/getchar.c       2022-07-25 18:13:33.050580738 +0100
--- src/getchar.c       2022-07-30 16:52:45.635878092 +0100
***************
*** 2096,2101 ****
--- 2096,2105 ----
      --no_mapping;
      --allow_keys;
  
+     // redraw the screen after getchar()
+     if (p_ch == 0)
+       update_screen(CLEAR);
+ 
      set_vim_var_nr(VV_MOUSE_WIN, 0);
      set_vim_var_nr(VV_MOUSE_WINID, 0);
      set_vim_var_nr(VV_MOUSE_LNUM, 0);
*** ../vim-9.0.0113/src/message.c       2022-07-28 12:34:06.527917764 +0100
--- src/message.c       2022-07-30 16:53:03.807834100 +0100
***************
*** 953,959 ****
      // just in case.
      room = (int)(Rows - cmdline_row - 1) * Columns + sc_col - 1;
      if (room > 0 && (force || (shortmess(SHM_TRUNC) && !exmode_active))
!           && (n = (int)STRLEN(s) - room) > 0)
      {
        if (has_mbyte)
        {
--- 953,959 ----
      // just in case.
      room = (int)(Rows - cmdline_row - 1) * Columns + sc_col - 1;
      if (room > 0 && (force || (shortmess(SHM_TRUNC) && !exmode_active))
!           && (n = (int)STRLEN(s) - room) > 0 && p_ch > 0)
      {
        if (has_mbyte)
        {
***************
*** 1430,1436 ****
      }
  
  #ifdef FEAT_EVAL
!     if (need_clr_eos)
      {
        // Halfway an ":echo" command and getting an (error) message: clear
        // any text from the command.
--- 1430,1436 ----
      }
  
  #ifdef FEAT_EVAL
!     if (need_clr_eos || p_ch == 0)
      {
        // Halfway an ":echo" command and getting an (error) message: clear
        // any text from the command.
***************
*** 1448,1454 ****
  #endif
            0;
      }
!     else if (msg_didout)                  // start message on next line
      {
        msg_putchar('\n');
        did_return = TRUE;
--- 1448,1454 ----
  #endif
            0;
      }
!     else if (msg_didout || p_ch == 0)     // start message on next line
      {
        msg_putchar('\n');
        did_return = TRUE;
***************
*** 3460,3466 ****
                out_str(T_CE);  // clear to end of line
        }
      }
!     else
      {
  #ifdef FEAT_RIGHTLEFT
        if (cmdmsg_rl)
--- 3460,3466 ----
                out_str(T_CE);  // clear to end of line
        }
      }
!     else if (p_ch > 0)
      {
  #ifdef FEAT_RIGHTLEFT
        if (cmdmsg_rl)
*** ../vim-9.0.0113/src/normal.c        2022-07-24 20:07:57.656416981 +0100
--- src/normal.c        2022-07-30 16:53:17.203802115 +0100
***************
*** 1798,1803 ****
--- 1798,1806 ----
  {
      int           len;
  
+     if (p_ch == 0)
+       return;
+ 
      cursor_off();
  
      len = (int)STRLEN(showcmd_buf);
*** ../vim-9.0.0113/src/ops.c   2022-07-25 18:13:33.050580738 +0100
--- src/ops.c   2022-07-30 16:21:36.408925280 +0100
***************
*** 3260,3265 ****
--- 3260,3270 ----
            // Don't shorten this message, the user asked for it.
            p = p_shm;
            p_shm = (char_u *)"";
+           if (p_ch < 1)
+           {
+               msg_start();
+               msg_scroll = TRUE;
+           }
            msg((char *)IObuff);
            p_shm = p;
        }
*** ../vim-9.0.0113/src/option.c        2022-07-27 18:26:00.149928207 +0100
--- src/option.c        2022-07-30 16:21:36.408925280 +0100
***************
*** 3559,3565 ****
      // if p_ch changed value, change the command line height
      else if (pp == &p_ch)
      {
!       if (p_ch < 1)
        {
            errmsg = e_argument_must_be_positive;
            p_ch = 1;
--- 3559,3565 ----
      // if p_ch changed value, change the command line height
      else if (pp == &p_ch)
      {
!       if (p_ch < 0)
        {
            errmsg = e_argument_must_be_positive;
            p_ch = 1;
*** ../vim-9.0.0113/src/register.c      2022-07-26 14:44:33.625670422 +0100
--- src/register.c      2022-07-30 16:37:31.877621416 +0100
***************
*** 371,376 ****
--- 371,377 ----
  {
      char_u        *p;
      static int            regname;
+     static int            changed_cmdheight = FALSE;
      yankreg_T     *old_y_previous, *old_y_current;
      int                   retval;
  
***************
*** 385,390 ****
--- 386,400 ----
            showmode();
            regname = c;
            retval = OK;
+ 
+           if (p_ch < 1)
+           {
+               // Enable macro indicator temporary
+               set_option_value((char_u *)"ch", 1L, NULL, 0);
+               update_screen(VALID);
+ 
+               changed_cmdheight = TRUE;
+           }
        }
      }
      else                          // stop recording
***************
*** 412,417 ****
--- 422,434 ----
            y_previous = old_y_previous;
            y_current = old_y_current;
        }
+ 
+       if (changed_cmdheight)
+       {
+           // Restore cmdheight
+           set_option_value((char_u *)"ch", 0L, NULL, 0);
+           redraw_all_later(CLEAR);
+       }
      }
      return retval;
  }
*** ../vim-9.0.0113/src/screen.c        2022-07-25 19:41:58.713627693 +0100
--- src/screen.c        2022-07-30 16:21:36.408925280 +0100
***************
*** 4726,4732 ****
      int
  messaging(void)
  {
!     return (!(p_lz && char_avail() && !KeyTyped));
  }
  
  /*
--- 4726,4732 ----
      int
  messaging(void)
  {
!     return (!(p_lz && char_avail() && !KeyTyped)) && p_ch > 0;
  }
  
  /*
*** ../vim-9.0.0113/src/testdir/gen_opt_test.vim        2022-06-01 
12:21:02.000000000 +0100
--- src/testdir/gen_opt_test.vim        2022-07-30 16:21:36.408925280 +0100
***************
*** 27,33 ****
  " Two lists with values: values that work and values that fail.
  " When not listed, "othernum" or "otherstring" is used.
  let test_values = {
!       \ 'cmdheight': [[1, 2, 10], [-1, 0]],
        \ 'cmdwinheight': [[1, 2, 10], [-1, 0]],
        \ 'columns': [[12, 80], [-1, 0, 10]],
        \ 'conceallevel': [[0, 1, 2, 3], [-1, 4, 99]],
--- 27,33 ----
  " Two lists with values: values that work and values that fail.
  " When not listed, "othernum" or "otherstring" is used.
  let test_values = {
!       \ 'cmdheight': [[0, 1, 2, 10], [-1]],
        \ 'cmdwinheight': [[1, 2, 10], [-1, 0]],
        \ 'columns': [[12, 80], [-1, 0, 10]],
        \ 'conceallevel': [[0, 1, 2, 3], [-1, 4, 99]],
*** ../vim-9.0.0113/src/window.c        2022-07-27 15:23:32.272483068 +0100
--- src/window.c        2022-07-30 16:53:33.419763953 +0100
***************
*** 1005,1010 ****
--- 1005,1012 ----
        needed = wmh1 + STATUS_HEIGHT;
        if (flags & WSP_ROOM)
            needed += p_wh - wmh1;
+       if (p_ch == 0)
+           needed += 1;  // Adjust for cmdheight=0.
        if (flags & (WSP_BOT | WSP_TOP))
        {
            minheight = frame_minheight(topframe, NOWIN) + need_status;
***************
*** 5668,5673 ****
--- 5670,5677 ----
      if (full_screen && msg_scrolled == 0 && row < cmdline_row)
        screen_fill(row, cmdline_row, 0, (int)Columns, ' ', ' ', 0);
      cmdline_row = row;
+     p_ch = MAX(Rows - cmdline_row, 0);
+     curtab->tp_ch_used = p_ch;
      msg_row = row;
      msg_col = 0;
  
***************
*** 5704,5712 ****
  
      if (curfrp->fr_parent == NULL)
      {
-       // topframe: can only change the command line
        if (height > ROWS_AVAIL)
!           height = ROWS_AVAIL;
        if (height > 0)
            frame_new_height(curfrp, height, FALSE, FALSE);
      }
--- 5708,5719 ----
  
      if (curfrp->fr_parent == NULL)
      {
        if (height > ROWS_AVAIL)
!           // If height is greater than the available space, try to create
!           // space for the frame by reducing 'cmdheight' if possible, while
!           // making sure `cmdheight` doesn't go below 1.
!           height = MIN((p_ch > 0 ? ROWS_AVAIL + (p_ch - 1)
!                                                       : ROWS_AVAIL), height);
        if (height > 0)
            frame_new_height(curfrp, height, FALSE, FALSE);
      }
***************
*** 6037,6043 ****
      while (p_wmh > 0)
      {
        room = Rows - p_ch;
!       needed = min_rows() - 1;  // 1 was added for the cmdline
        if (room >= needed)
            break;
        --p_wmh;
--- 6044,6050 ----
      while (p_wmh > 0)
      {
        room = Rows - p_ch;
!       needed = min_rows();
        if (room >= needed)
            break;
        --p_wmh;
***************
*** 6143,6151 ****
         * Only dragging the last status line can reduce p_ch.
         */
        room = Rows - cmdline_row;
!       if (curfr->fr_next == NULL)
!           room -= 1;
!       else
            room -= p_ch;
        if (room < 0)
            room = 0;
--- 6150,6156 ----
         * Only dragging the last status line can reduce p_ch.
         */
        room = Rows - cmdline_row;
!       if (curfr->fr_next != NULL)
            room -= p_ch;
        if (room < 0)
            room = 0;
***************
*** 6196,6204 ****
      row = win_comp_pos();
      screen_fill(row, cmdline_row, 0, (int)Columns, ' ', ' ', 0);
      cmdline_row = row;
!     p_ch = Rows - cmdline_row;
!     if (p_ch < 1)
!       p_ch = 1;
      curtab->tp_ch_used = p_ch;
      redraw_all_later(SOME_VALID);
      showmode();
--- 6201,6207 ----
      row = win_comp_pos();
      screen_fill(row, cmdline_row, 0, (int)Columns, ' ', ' ', 0);
      cmdline_row = row;
!     p_ch = MAX(Rows - cmdline_row, 0);
      curtab->tp_ch_used = p_ch;
      redraw_all_later(SOME_VALID);
      showmode();
***************
*** 6733,6739 ****
            total = n;
      }
      total += tabline_height();
!     total += 1;               // count the room for the command line
      return total;
  }
  
--- 6736,6743 ----
            total = n;
      }
      total += tabline_height();
!     if (p_ch > 0)
!       total += 1;             // count the room for the command line
      return total;
  }
  
*** ../vim-9.0.0113/src/testdir/test_messages.vim       2022-07-28 
12:34:06.527917764 +0100
--- src/testdir/test_messages.vim       2022-07-30 16:21:36.408925280 +0100
***************
*** 387,390 ****
--- 387,437 ----
    call delete('b.txt')
  endfunc
  
+ func Test_cmdheight_zero()
+   set cmdheight=0
+   set showcmd
+   redraw!
+ 
+   echo 'test echo'
+   call assert_equal(116, screenchar(&lines, 1))
+   redraw!
+ 
+   echomsg 'test echomsg'
+   call assert_equal(116, screenchar(&lines, 1))
+   redraw!
+ 
+   call feedkeys(":ls\<CR>", "xt")
+   call assert_equal(':ls', Screenline(&lines - 1))
+   redraw!
+ 
+   let char = getchar(0)
+   call assert_match(char, 0)
+ 
+   " Check change/restore cmdheight when macro
+   call feedkeys("qa", "xt")
+   call assert_equal(&cmdheight, 1)
+   call feedkeys("q", "xt")
+   call assert_equal(&cmdheight, 0)
+ 
+   call setline(1, 'somestring')
+   call feedkeys("y", "n")
+   %s/somestring/otherstring/gc
+   call assert_equal(getline(1), 'otherstring')
+ 
+   call feedkeys("g\<C-g>", "xt")
+   call assert_match(
+         \ 'Col 1 of 11; Line 1 of 1; Word 1 of 1',
+         \ Screenline(&lines))
+ 
+   " Check split behavior
+   for i in range(1, 10)
+     split
+   endfor
+   only
+   call assert_equal(&cmdheight, 0)
+ 
+   set cmdheight&
+   set showcmd&
+ endfunc
+ 
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-9.0.0113/src/testdir/test_window_cmd.vim     2022-04-20 
18:59:34.000000000 +0100
--- src/testdir/test_window_cmd.vim     2022-07-30 16:21:36.408925280 +0100
***************
*** 1481,1489 ****
      call assert_equal(h0, winheight(0))
      call assert_equal(1, &cmdheight)
    endfor
    call assert_true(win_move_statusline(0, 1))
!   call assert_equal(h0, winheight(0))
!   call assert_equal(1, &cmdheight)
    " check win_move_statusline from bottom window on top window ID
    let id = win_getid(1)
    for offset in range(5)
--- 1481,1492 ----
      call assert_equal(h0, winheight(0))
      call assert_equal(1, &cmdheight)
    endfor
+   " supports cmdheight=0
+   set cmdheight=0
    call assert_true(win_move_statusline(0, 1))
!   call assert_equal(h0 + 1, winheight(0))
!   call assert_equal(0, &cmdheight)
!   set cmdheight&
    " check win_move_statusline from bottom window on top window ID
    let id = win_getid(1)
    for offset in range(5)
*** ../vim-9.0.0113/src/version.c       2022-07-30 15:43:56.222091886 +0100
--- src/version.c       2022-07-30 16:25:21.425375824 +0100
***************
*** 737,738 ****
--- 737,740 ----
  {   /* Add new patch number below this line */
+ /**/
+     114,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
198. You read all the quotes at Netaholics Anonymous and keep thinking
     "What's wrong with that?"

 /// 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/20220730155448.644621C0ECD%40moolenaar.net.

Raspunde prin e-mail lui