Patch 9.0.0533
Problem:    The win_line() function is much too long.
Solution:   Move code to separate functions.
Files:      src/drawline.c


*** ../vim-9.0.0532/src/drawline.c      2022-09-21 14:34:24.926995254 +0100
--- src/drawline.c      2022-09-21 15:33:49.539113466 +0100
***************
*** 103,108 ****
--- 103,111 ----
      int               win_attr;       // background for the whole window, 
except
                                // margins and "~" lines.
      int               wcr_attr;       // attributes from 'wincolor'
+ #ifdef FEAT_SYN_HL
+     int               cul_attr;       // set when 'cursorline' active
+ #endif
  
      int               screen_line_flags;  // flags for screen_line()
  
***************
*** 110,115 ****
--- 113,119 ----
      int               tocol;          // end of inverting
  
  #ifdef FEAT_LINEBREAK
+     long      vcol_sbr;           // virtual column after showbreak
      int               need_showbreak;     // overlong line, skipping first x 
chars
      int               dont_use_showbreak; // do not use 'showbreak'
  #endif
***************
*** 122,132 ****
      int               n_extra;        // number of extra bytes
      char_u    *p_extra;       // string of extra chars, plus NUL, only used
                                // when c_extra and c_final are NUL
      int               c_extra;        // extra chars, all the same
      int               c_final;        // final char, mandatory if set
  
-     char_u    *p_extra_free;  // p_extra buffer that needs to be freed
- 
      // saved "extra" items for when draw_state becomes WL_LINE (again)
      int               saved_n_extra;
      char_u    *saved_p_extra;
--- 126,135 ----
      int               n_extra;        // number of extra bytes
      char_u    *p_extra;       // string of extra chars, plus NUL, only used
                                // when c_extra and c_final are NUL
+     char_u    *p_extra_free;  // p_extra buffer that needs to be freed
      int               c_extra;        // extra chars, all the same
      int               c_final;        // final char, mandatory if set
  
      // saved "extra" items for when draw_state becomes WL_LINE (again)
      int               saved_n_extra;
      char_u    *saved_p_extra;
***************
*** 491,496 ****
--- 494,555 ----
  }
  #endif
  
+ #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
+     static void
+ handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
+ {
+ # ifdef FEAT_DIFF
+     if (wlv->filler_todo > 0)
+     {
+       // Draw "deleted" diff line(s).
+       if (char2cells(wp->w_fill_chars.diff) > 1)
+       {
+           wlv->c_extra = '-';
+           wlv->c_final = NUL;
+       }
+       else
+       {
+           wlv->c_extra = wp->w_fill_chars.diff;
+           wlv->c_final = NUL;
+       }
+ #  ifdef FEAT_RIGHTLEFT
+       if (wp->w_p_rl)
+           wlv->n_extra = wlv->col + 1;
+       else
+ #  endif
+           wlv->n_extra = wp->w_width - wlv->col;
+       wlv->char_attr = HL_ATTR(HLF_DED);
+     }
+ # endif
+ 
+ # ifdef FEAT_LINEBREAK
+     char_u *sbr = get_showbreak_value(wp);
+     if (*sbr != NUL && wlv->need_showbreak)
+     {
+       // Draw 'showbreak' at the start of each broken line.
+       wlv->p_extra = sbr;
+       wlv->c_extra = NUL;
+       wlv->c_final = NUL;
+       wlv->n_extra = (int)STRLEN(sbr);
+       if (wp->w_skipcol == 0 || !wp->w_p_wrap)
+           wlv->need_showbreak = FALSE;
+       wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
+       // Correct end of highlighted area for 'showbreak',
+       // required when 'linebreak' is also set.
+       if (wlv->tocol == wlv->vcol)
+           wlv->tocol += wlv->n_extra;
+       // combine 'showbreak' with 'wincolor'
+       wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
+ #  ifdef FEAT_SYN_HL
+       // combine 'showbreak' with 'cursorline'
+       if (wlv->cul_attr != 0)
+           wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
+ #  endif
+     }
+ # endif
+ }
+ #endif
+ 
  #if defined(FEAT_PROP_POPUP) || defined(PROTO)
  /*
   * Return the cell size of virtual text after truncation.
***************
*** 802,807 ****
--- 861,885 ----
  }
  
  /*
+  * Called when wlv->draw_state is set to WL_LINE.
+  */
+     static void
+ win_line_continue(winlinevars_T *wlv)
+ {
+     if (wlv->saved_n_extra > 0)
+     {
+       // Continue item from end of wrapped line.
+       wlv->n_extra = wlv->saved_n_extra;
+       wlv->c_extra = wlv->saved_c_extra;
+       wlv->c_final = wlv->saved_c_final;
+       wlv->p_extra = wlv->saved_p_extra;
+       wlv->char_attr = wlv->saved_char_attr;
+     }
+     else
+       wlv->char_attr = wlv->win_attr;
+ }
+ 
+ /*
   * Display line "lnum" of window 'wp' on the screen.
   * Start at row "startrow", stop when "endrow" is reached.
   * wp->w_virtcol needs to be valid.
***************
*** 820,828 ****
      winlinevars_T     wlv;            // variables passed between functions
  
      int               c = 0;                  // init for GCC
- #ifdef FEAT_LINEBREAK
-     long      vcol_sbr = -1;          // virtual column after showbreak
- #endif
      long      vcol_prev = -1;         // "wlv.vcol" of previous character
      char_u    *line;                  // current line
      char_u    *ptr;                   // current position in "line"
--- 898,903 ----
***************
*** 937,945 ****
  #ifdef FEAT_TERMINAL
      int               get_term_attr = FALSE;
  #endif
- #ifdef FEAT_SYN_HL
-     int               cul_attr = 0;           // set when 'cursorline' active
  
      // margin columns for the screen line, needed for when 'cursorlineopt'
      // contains "screenline"
      int               left_curline_col = 0;
--- 1012,1019 ----
  #ifdef FEAT_TERMINAL
      int               get_term_attr = FALSE;
  #endif
  
+ #ifdef FEAT_SYN_HL
      // margin columns for the screen line, needed for when 'cursorlineopt'
      // contains "screenline"
      int               left_curline_col = 0;
***************
*** 988,993 ****
--- 1062,1070 ----
      wlv.screen_row = wlv.row + W_WINROW(wp);
      wlv.fromcol = -10;
      wlv.tocol = MAXCOL;
+ #ifdef FEAT_LINEBREAK
+     wlv.vcol_sbr = -1;
+ #endif
  
      if (!number_only)
      {
***************
*** 1481,1496 ****
            // 'cursorlineopt'.  Otherwise it's done later.
            if (!wlv.cul_screenline)
            {
!               cul_attr = HL_ATTR(HLF_CUL);
  # ifdef FEAT_SIGNS
                // Combine the 'cursorline' and sign highlighting, depending on
                // the sign priority.
                if (sign_present && wlv.sattr.sat_linehl > 0)
                {
                    if (wlv.sattr.sat_priority >= 100)
!                       line_attr = hl_combine_attr(cul_attr, line_attr);
                    else
!                       line_attr = hl_combine_attr(line_attr, cul_attr);
                }
                else
  # endif
--- 1558,1573 ----
            // 'cursorlineopt'.  Otherwise it's done later.
            if (!wlv.cul_screenline)
            {
!               wlv.cul_attr = HL_ATTR(HLF_CUL);
  # ifdef FEAT_SIGNS
                // Combine the 'cursorline' and sign highlighting, depending on
                // the sign priority.
                if (sign_present && wlv.sattr.sat_linehl > 0)
                {
                    if (wlv.sattr.sat_priority >= 100)
!                       line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
                    else
!                       line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
                }
                else
  # endif
***************
*** 1498,1506 ****
                    // let the line attribute overrule 'cursorline', otherwise
                    // it disappears when both have background set;
                    // 'cursorline' can use underline or bold to make it show
!                   line_attr = hl_combine_attr(cul_attr, line_attr);
  # else
!                   line_attr = cul_attr;
  # endif
            }
            else
--- 1575,1583 ----
                    // let the line attribute overrule 'cursorline', otherwise
                    // it disappears when both have background set;
                    // 'cursorline' can use underline or bold to make it show
!                   line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
  # else
!                   line_attr = wlv.cul_attr;
  # endif
            }
            else
***************
*** 1558,1568 ****
  #ifdef FEAT_SYN_HL
            if (wlv.cul_screenline)
            {
!               cul_attr = 0;
                line_attr = line_attr_save;
            }
  #endif
- 
  #ifdef FEAT_CMDWIN
            if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
            {
--- 1635,1644 ----
  #ifdef FEAT_SYN_HL
            if (wlv.cul_screenline)
            {
!               wlv.cul_attr = 0;
                line_attr = line_attr_save;
            }
  #endif
  #ifdef FEAT_CMDWIN
            if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
            {
***************
*** 1578,1584 ****
                }
            }
  #endif
- 
  #ifdef FEAT_FOLDING
            if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
            {
--- 1654,1659 ----
***************
*** 1586,1592 ****
                handle_foldcolumn(wp, &wlv);
            }
  #endif
- 
  #ifdef FEAT_SIGNS
            if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
            {
--- 1661,1666 ----
***************
*** 1596,1698 ****
                    get_sign_display_info(FALSE, wp, &wlv);
            }
  #endif
- 
            if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
            {
                // Show the line number, if desired.
                wlv.draw_state = WL_NR;
                handle_lnum_col(wp, &wlv, sign_present, num_attr);
            }
- 
  #ifdef FEAT_LINEBREAK
            // Check if 'breakindent' applies and show it.
            // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
            if (wlv.n_extra == 0)
                handle_breakindent(wp, &wlv);
  #endif
- 
  #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
            if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
            {
-               char_u *sbr;
- 
                wlv.draw_state = WL_SBR;
! # ifdef FEAT_DIFF
!               if (wlv.filler_todo > 0)
!               {
!                   // Draw "deleted" diff line(s).
!                   if (char2cells(wp->w_fill_chars.diff) > 1)
!                   {
!                       wlv.c_extra = '-';
!                       wlv.c_final = NUL;
!                   }
!                   else
!                   {
!                       wlv.c_extra = wp->w_fill_chars.diff;
!                       wlv.c_final = NUL;
!                   }
! #  ifdef FEAT_RIGHTLEFT
!                   if (wp->w_p_rl)
!                       wlv.n_extra = wlv.col + 1;
!                   else
! #  endif
!                       wlv.n_extra = wp->w_width - wlv.col;
!                   wlv.char_attr = HL_ATTR(HLF_DED);
!               }
! # endif
! # ifdef FEAT_LINEBREAK
!               sbr = get_showbreak_value(wp);
!               if (*sbr != NUL && wlv.need_showbreak)
!               {
!                   // Draw 'showbreak' at the start of each broken line.
!                   wlv.p_extra = sbr;
!                   wlv.c_extra = NUL;
!                   wlv.c_final = NUL;
!                   wlv.n_extra = (int)STRLEN(sbr);
!                   if (wp->w_skipcol == 0 || !wp->w_p_wrap)
!                       wlv.need_showbreak = FALSE;
!                   vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
!                   // Correct end of highlighted area for 'showbreak',
!                   // required when 'linebreak' is also set.
!                   if (wlv.tocol == wlv.vcol)
!                       wlv.tocol += wlv.n_extra;
!                   // combine 'showbreak' with 'wincolor'
!                   wlv.char_attr = hl_combine_attr(wlv.win_attr,
!                                                             HL_ATTR(HLF_AT));
! #  ifdef FEAT_SYN_HL
!                   // combine 'showbreak' with 'cursorline'
!                   if (cul_attr != 0)
!                       wlv.char_attr = hl_combine_attr(wlv.char_attr,
!                                                                    cul_attr);
! #  endif
!               }
! # endif
            }
  #endif
- 
            if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
            {
                wlv.draw_state = WL_LINE;
!               if (wlv.saved_n_extra)
!               {
!                   // Continue item from end of wrapped line.
!                   wlv.n_extra = wlv.saved_n_extra;
!                   wlv.c_extra = wlv.saved_c_extra;
!                   wlv.c_final = wlv.saved_c_final;
!                   wlv.p_extra = wlv.saved_p_extra;
!                   wlv.char_attr = wlv.saved_char_attr;
!               }
!               else
!                   wlv.char_attr = wlv.win_attr;
            }
        }
  #ifdef FEAT_SYN_HL
        if (wlv.cul_screenline && wlv.draw_state == WL_LINE
                && wlv.vcol >= left_curline_col
                && wlv.vcol < right_curline_col)
        {
!           cul_attr = HL_ATTR(HLF_CUL);
!           line_attr = cul_attr;
        }
  #endif
  
--- 1670,1708 ----
                    get_sign_display_info(FALSE, wp, &wlv);
            }
  #endif
            if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
            {
                // Show the line number, if desired.
                wlv.draw_state = WL_NR;
                handle_lnum_col(wp, &wlv, sign_present, num_attr);
            }
  #ifdef FEAT_LINEBREAK
            // Check if 'breakindent' applies and show it.
            // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
            if (wlv.n_extra == 0)
                handle_breakindent(wp, &wlv);
  #endif
  #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
            if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
            {
                wlv.draw_state = WL_SBR;
!               handle_showbreak_and_filler(wp, &wlv);
            }
  #endif
            if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
            {
                wlv.draw_state = WL_LINE;
!               win_line_continue(&wlv);  // use wlv.saved_ values
            }
        }
+ 
  #ifdef FEAT_SYN_HL
        if (wlv.cul_screenline && wlv.draw_state == WL_LINE
                && wlv.vcol >= left_curline_col
                && wlv.vcol < right_curline_col)
        {
!           wlv.cul_attr = HL_ATTR(HLF_CUL);
!           line_attr = wlv.cul_attr;
        }
  #endif
  
***************
*** 2226,2233 ****
                        mb_utf8 = FALSE;
                        multi_attr = HL_ATTR(HLF_AT);
  #ifdef FEAT_SYN_HL
!                       if (cul_attr)
!                           multi_attr = hl_combine_attr(multi_attr, cul_attr);
  #endif
                        multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
  
--- 2236,2244 ----
                        mb_utf8 = FALSE;
                        multi_attr = HL_ATTR(HLF_AT);
  #ifdef FEAT_SYN_HL
!                       if (wlv.cul_attr)
!                           multi_attr = hl_combine_attr(
!                                                    multi_attr, wlv.cul_attr);
  #endif
                        multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
  
***************
*** 2565,2571 ****
  
                    // We have just drawn the showbreak value, no need to add
                    // space for it again.
!                   if (wlv.vcol == vcol_sbr)
                    {
                        wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
                        if (wlv.n_extra < 0)
--- 2576,2582 ----
  
                    // We have just drawn the showbreak value, no need to add
                    // space for it again.
!                   if (wlv.vcol == wlv.vcol_sbr)
                    {
                        wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
                        if (wlv.n_extra < 0)
***************
*** 2710,2716 ****
  
                    // only adjust the tab_len, when at the first column
                    // after the showbreak value was drawn
!                   if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
                        vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
  #endif
                    // tab amount depends on current column
--- 2721,2727 ----
  
                    // only adjust the tab_len, when at the first column
                    // after the showbreak value was drawn
!                   if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
                        vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
  #endif
                    // tab amount depends on current column
*** ../vim-9.0.0532/src/version.c       2022-09-21 15:13:49.314998845 +0100
--- src/version.c       2022-09-21 15:40:41.026505339 +0100
***************
*** 701,702 ****
--- 701,704 ----
  {   /* Add new patch number below this line */
+ /**/
+     533,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
123. You ask the car dealer to install an extra cigarette lighter
     on your new car to power your notebook.

 /// 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/20220921144155.EEC311C0EC3%40moolenaar.net.

Raspunde prin e-mail lui