src/nvim/screen.c
/// Resize the screen to Rows and Columns.
///
/// Allocate default_grid.chars[] and other grid arrays.
///
/// There may be some time between setting Rows and Columns and (re)allocating
/// default_grid arrays.  This happens when starting up and when
/// (manually) changing the shell size.  Always use default_grid.Rows and
/// default_grid.Columns to access items in default_grid.chars[].  Use Rows
/// and Columns for positioning text etc. where the final size of the shell is
/// needed.
Resize the screen to Rows and Columns.
Allocate default_grid.chars[] and other grid arrays.

There may be some time between setting Rows and Columns and (re)allocating
default_grid arrays.  This happens when starting up and when
(manually) changing the shell size.
Resize the screen to Rows and Columns . Allocate default_grid . chars [] and other grid arrays . There may be some time between setting Rows and Columns and ( re ) allocating default_grid arrays . This happens when starting up and when ( manually ) changing the shell size .
void screenalloc(void)
{
  if (resizing) {
    return;
  }
  resizing = true;
  int retry_count = 0;
retry:
  if ((default_grid.chars != NULL
       && Rows == default_grid.Rows
       && Columns == default_grid.Columns
       )
      || Rows == 0
      || Columns == 0
      || (!full_screen && default_grid.chars == NULL)) {
    resizing = false;
    return;
  }
  ++RedrawingDisabled;
  ui_comp_set_screen_valid(false);
  if (msg_grid.chars) {
    msg_grid_invalid = true;
  }
  win_new_shellsize();      
  comp_col();           
   If anything fails, make grid arrays NULL, so we don't do anything!
   Continuing with the old arrays may result in a crash, because the
   size is wrong.
  grid_alloc(&default_grid, Rows, Columns, true, true);
  StlClickDefinition *new_tab_page_click_defs = xcalloc(
      (size_t)Columns, sizeof(*new_tab_page_click_defs));
  clear_tab_page_click_defs(tab_page_click_defs, tab_page_click_defs_size);
  xfree(tab_page_click_defs);
  tab_page_click_defs = new_tab_page_click_defs;
  tab_page_click_defs_size = Columns;
  default_grid.row_offset = 0;
  default_grid.col_offset = 0;
  default_grid.handle = DEFAULT_GRID_HANDLE;
  must_redraw = CLEAR;   need to clear the screen later
  RedrawingDisabled--;
  if (starting == 0 && ++retry_count <= 3) {
    apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf);
    goto retry;
  }
  resizing = false;
}
void screenalloc ( void ) { if ( resizing ) { return ; } resizing = true ; int retry_count = 0 ; retry : if ( ( default_grid . chars != NULL && Rows == default_grid . Rows && Columns == default_grid . Columns ) || Rows == 0 || Columns == 0 || ( ! full_screen && default_grid . chars == NULL ) ) { resizing = false ; return ; } ++ RedrawingDisabled ; ui_comp_set_screen_valid ( false ) ; if ( msg_grid . chars ) { msg_grid_invalid = true ; } win_new_shellsize ( ) ; comp_col ( ) ; grid_alloc ( & default_grid , Rows , Columns , true , true ) ; StlClickDefinition * new_tab_page_click_defs = xcalloc ( ( size_t ) Columns , sizeof ( * new_tab_page_click_defs ) ) ; clear_tab_page_click_defs ( tab_page_click_defs , tab_page_click_defs_size ) ; xfree ( tab_page_click_defs ) ; tab_page_click_defs = new_tab_page_click_defs ; tab_page_click_defs_size = Columns ; default_grid . row_offset = 0 ; default_grid . col_offset = 0 ; default_grid . handle = DEFAULT_GRID_HANDLE ; must_redraw = CLEAR ; RedrawingDisabled -- ; if ( starting == 0 && ++ retry_count <= 3 ) { apply_autocmds ( EVENT_VIMRESIZED , NULL , NULL , FALSE , curbuf ) ; goto retry ; } resizing = false ; }
Resize the screen to Rows and Columns.
Resize the screen to Rows and Columns .
// It's possible that we produce an out-of-memory message below, which // will cause this function to be called again.  To break the loop, just // return here. // Allocation of the screen buffers is done only when the size changes and // when Rows and Columns have been set and we have started doing full // screen stuff. /*
   * Note that the window sizes are updated before reallocating the arrays,
   * thus we must not redraw here!
   */ // win_new_shellsize will recompute floats position, but tell the // compositor to not redraw them yet /* fit the windows in the new sized shell */ /* recompute columns for shown command and ruler */ // We're changing the size of the screen. // - Allocate new arrays for default_grid // - Move lines from the old arrays into the new arrays, clear extra //   lines (unless the screen is going to be cleared). // - Free the old arrays. // // If anything fails, make grid arrays NULL, so we don't do anything! // Continuing with the old arrays may result in a crash, because the // size is wrong. // need to clear the screen later /*
   * Do not apply autocommands more than 3 times to avoid an endless loop
   * in case applying autocommands always changes Rows or Columns.
   */ /* In rare cases, autocommands may have altered Rows or Columns,
    * jump back to check if we need to allocate the screen again. */