Patch 8.2.5067
Problem:    Can specify multispace listchars only for whole line.
Solution:   Add "leadmultispace". (Christian Brabandt, closes #10496)
Files:      runtime/doc/options.txt, src/drawline.c, src/message.c,
            src/screen.c, src/structs.h, src/window.c,
            src/testdir/test_listchars.vim


*** ../vim-8.2.5065/runtime/doc/options.txt     2022-05-22 14:48:26.335247292 
+0100
--- runtime/doc/options.txt     2022-06-07 10:13:01.841322890 +0100
***************
*** 5075,5088 ****
                        "space" setting is used.  For example,
                        `:set listchars=multispace:---+` shows ten consecutive
                        spaces as:
!                               ---+---+--
                                                        *lcs-lead*
          lead:c        Character to show for leading spaces.  When omitted,
                        leading spaces are blank.  Overrides the "space" and
                        "multispace" settings for leading spaces.  You can
                        combine it with "tab:", for example: >
                                :set listchars+=tab:>-,lead:.
! <                                                     *lcs-trail*
          trail:c       Character to show for trailing spaces.  When omitted,
                        trailing spaces are blank.  Overrides the "space" and
                        "multispace" settings for trailing spaces.
--- 5076,5098 ----
                        "space" setting is used.  For example,
                        `:set listchars=multispace:---+` shows ten consecutive
                        spaces as:
!                               ---+---+-- ~
                                                        *lcs-lead*
          lead:c        Character to show for leading spaces.  When omitted,
                        leading spaces are blank.  Overrides the "space" and
                        "multispace" settings for leading spaces.  You can
                        combine it with "tab:", for example: >
                                :set listchars+=tab:>-,lead:.
! <                                                     *lcs-leadmultispace*
!         leadmultispace:c...
!                       Like multispace value, but only for leading whitespace
!                       Overrides |lcs-lead| for leading multiple spaces.
!                       `:set listchars=leadmultispace:---+` shows ten 
consecutive
!                       leading spaces as:
!                               ---+---+--XXX ~
!                       Where "XXX" denotes the first non-blank characters in
!                       the line.
!                                                       *lcs-trail*
          trail:c       Character to show for trailing spaces.  When omitted,
                        trailing spaces are blank.  Overrides the "space" and
                        "multispace" settings for trailing spaces.
*** ../vim-8.2.5065/src/drawline.c      2022-05-08 21:25:17.125880347 +0100
--- src/drawline.c      2022-06-07 10:08:26.133401549 +0100
***************
*** 767,772 ****
--- 767,773 ----
      {
        if (wp->w_lcs_chars.space
                || wp->w_lcs_chars.multispace != NULL
+               || wp->w_lcs_chars.leadmultispace != NULL
                || wp->w_lcs_chars.trail
                || wp->w_lcs_chars.lead
                || wp->w_lcs_chars.nbsp)
***************
*** 781,787 ****
            trailcol += (colnr_T) (ptr - line);
        }
        // find end of leading whitespace
!       if (wp->w_lcs_chars.lead)
        {
            leadcol = 0;
            while (VIM_ISWHITE(ptr[leadcol]))
--- 782,788 ----
            trailcol += (colnr_T) (ptr - line);
        }
        // find end of leading whitespace
!       if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
        {
            leadcol = 0;
            while (VIM_ISWHITE(ptr[leadcol]))
***************
*** 2118,2125 ****
                if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
                        || (leadcol != 0 && ptr < line + leadcol && c == ' '))
                {
!                   c = (ptr > line + trailcol) ? wp->w_lcs_chars.trail
!                                                       : wp->w_lcs_chars.lead;
                    if (!attr_pri)
                    {
                        n_attr = 1;
--- 2119,2142 ----
                if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
                        || (leadcol != 0 && ptr < line + leadcol && c == ' '))
                {
!                   if (leadcol != 0 && in_multispace && ptr < line + leadcol
!                           && wp->w_lcs_chars.leadmultispace != NULL)
!                   {
!                       c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
!                       if (wp->w_lcs_chars.leadmultispace[multispace_pos] == 
NUL)
!                           multispace_pos = 0;
!                   }
! 
!                   else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
!                       c = wp->w_lcs_chars.trail;
! 
!                   else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
!                       c = wp->w_lcs_chars.lead;
! 
!                   else if (leadcol != 0 && c == ' ' && wp->w_lcs_chars.space)
!                       c = wp->w_lcs_chars.space;
! 
! 
                    if (!attr_pri)
                    {
                        n_attr = 1;
*** ../vim-8.2.5065/src/message.c       2022-05-09 12:16:14.757073343 +0100
--- src/message.c       2022-06-07 10:08:26.133401549 +0100
***************
*** 1881,1887 ****
                --trail;
        }
        // find end of leading whitespace
!       if (curwin->w_lcs_chars.lead)
        {
            lead = s;
            while (VIM_ISWHITE(lead[0]))
--- 1881,1887 ----
                --trail;
        }
        // find end of leading whitespace
!       if (curwin->w_lcs_chars.lead || curwin->w_lcs_chars.leadmultispace != 
NULL)
        {
            lead = s;
            while (VIM_ISWHITE(lead[0]))
***************
*** 1993,1999 ****
            }
            else if (c == ' ')
            {
!               if (lead != NULL && s <= lead)
                {
                    c = curwin->w_lcs_chars.lead;
                    attr = HL_ATTR(HLF_8);
--- 1993,2007 ----
            }
            else if (c == ' ')
            {
!               if (list && lead != NULL && s <= lead && in_multispace
!                       && curwin->w_lcs_chars.leadmultispace != NULL)
!               {
!                   c = curwin->w_lcs_chars.leadmultispace[multispace_pos++];
!                   if (curwin->w_lcs_chars.leadmultispace[multispace_pos] == 
NUL)
!                       multispace_pos = 0;
!                   attr = HL_ATTR(HLF_8);
!               }
!               else if (lead != NULL && s <= lead && curwin->w_lcs_chars.lead)
                {
                    c = curwin->w_lcs_chars.lead;
                    attr = HL_ATTR(HLF_8);
***************
*** 2003,2008 ****
--- 2011,2024 ----
                    c = curwin->w_lcs_chars.trail;
                    attr = HL_ATTR(HLF_8);
                }
+               else if (list && lead != NULL && s <= lead && in_multispace
+                       && curwin->w_lcs_chars.leadmultispace != NULL)
+               {
+                   c = curwin->w_lcs_chars.leadmultispace[multispace_pos++];
+                   if (curwin->w_lcs_chars.leadmultispace[multispace_pos] == 
NUL)
+                       multispace_pos = 0;
+                   attr = HL_ATTR(HLF_8);
+               }
                else if (list && in_multispace
                        && curwin->w_lcs_chars.multispace != NULL)
                {
*** ../vim-8.2.5065/src/screen.c        2022-06-05 16:55:50.702774344 +0100
--- src/screen.c        2022-06-07 10:08:26.133401549 +0100
***************
*** 4831,4841 ****
      char *
  set_chars_option(win_T *wp, char_u **varp)
  {
!     int               round, i, len, entries;
      char_u    *p, *s;
      int               c1 = 0, c2 = 0, c3 = 0;
      char_u    *last_multispace = NULL; // Last occurrence of "multispace:"
      int               multispace_len = 0;      // Length of lcs-multispace 
string
      struct charstab
      {
        int     *cp;
--- 4831,4843 ----
      char *
  set_chars_option(win_T *wp, char_u **varp)
  {
!     int               round, i, len, len2, entries;
      char_u    *p, *s;
      int               c1 = 0, c2 = 0, c3 = 0;
      char_u    *last_multispace = NULL; // Last occurrence of "multispace:"
+     char_u    *last_lmultispace = NULL; // Last occurrence of 
"leadmultispace:"
      int               multispace_len = 0;      // Length of lcs-multispace 
string
+     int               lead_multispace_len = 0; // Length of 
lcs-leadmultispace string
      struct charstab
      {
        int     *cp;
***************
*** 4909,4914 ****
--- 4911,4924 ----
                }
                else
                    lcs_chars.multispace = NULL;
+ 
+               if (lead_multispace_len > 0)
+               {
+                   lcs_chars.leadmultispace = ALLOC_MULT(int, 
lead_multispace_len + 1);
+                   lcs_chars.leadmultispace[lead_multispace_len] = NUL;
+               }
+               else
+                   lcs_chars.leadmultispace = NULL;
            }
            else
            {
***************
*** 4972,4977 ****
--- 4982,4988 ----
            if (i == entries)
            {
                len = (int)STRLEN("multispace");
+               len2 = (int)STRLEN("leadmultispace");
                if ((varp == &p_lcs || varp == &wp->w_p_lcs)
                        && STRNCMP(p, "multispace", len) == 0
                        && p[len] == ':'
***************
*** 5008,5013 ****
--- 5019,5061 ----
                        p = s;
                    }
                }
+ 
+               else if ((varp == &p_lcs || varp == &wp->w_p_lcs)
+                       && STRNCMP(p, "leadmultispace", len2) == 0
+                       && p[len2] == ':'
+                       && p[len2 + 1] != NUL)
+               {
+                   s = p + len2 + 1;
+                   if (round == 0)
+                   {
+                       // Get length of lcsmultispace string in first round
+                       last_lmultispace = p;
+                       lead_multispace_len = 0;
+                       while (*s != NUL && *s != ',')
+                       {
+                           c1 = get_encoded_char_adv(&s);
+                           if (char2cells(c1) > 1)
+                               return e_invalid_argument;
+                           ++lead_multispace_len;
+                       }
+                       if (lead_multispace_len == 0)
+                           // lcsmultispace cannot be an empty string
+                           return e_invalid_argument;
+                       p = s;
+                   }
+                   else
+                   {
+                       int multispace_pos = 0;
+ 
+                       while (*s != NUL && *s != ',')
+                       {
+                           c1 = get_encoded_char_adv(&s);
+                           if (p == last_lmultispace)
+                               lcs_chars.leadmultispace[multispace_pos++] = c1;
+                       }
+                       p = s;
+                   }
+               }
                else
                    return e_invalid_argument;
            }
***************
*** 5020,5025 ****
--- 5068,5075 ----
      {
        if (wp->w_lcs_chars.multispace != NULL)
            vim_free(wp->w_lcs_chars.multispace);
+       if (wp->w_lcs_chars.leadmultispace != NULL)
+           vim_free(wp->w_lcs_chars.leadmultispace);
        wp->w_lcs_chars = lcs_chars;
      }
  
*** ../vim-8.2.5065/src/structs.h       2022-06-05 16:55:50.702774344 +0100
--- src/structs.h       2022-06-07 10:08:26.133401549 +0100
***************
*** 3411,3416 ****
--- 3411,3417 ----
      int               trail;
      int               lead;
      int               *multispace;
+     int               *leadmultispace;
  #ifdef FEAT_CONCEAL
      int               conceal;
  #endif
*** ../vim-8.2.5065/src/window.c        2022-05-30 15:23:05.380780131 +0100
--- src/window.c        2022-06-07 10:08:26.137401549 +0100
***************
*** 5188,5193 ****
--- 5188,5194 ----
      clear_winopt(&wp->w_allbuf_opt);
  
      vim_free(wp->w_lcs_chars.multispace);
+     vim_free(wp->w_lcs_chars.leadmultispace);
  
  #ifdef FEAT_EVAL
      vars_clear(&wp->w_vars->dv_hashtab);      // free all w: variables
*** ../vim-8.2.5065/src/testdir/test_listchars.vim      2021-12-18 
15:32:38.064496744 +0000
--- src/testdir/test_listchars.vim      2022-06-07 10:08:26.133401549 +0100
***************
*** 132,138 ****
              \ 'h<<<<<<<<<<<$',
              \ '<<<<<<<<<<<<$',
              \ '>>>>0xx0<<<<$',
!               \ '$'
              \ ]
    redraw!
    for i in range(1, 5)
--- 132,138 ----
              \ 'h<<<<<<<<<<<$',
              \ '<<<<<<<<<<<<$',
              \ '>>>>0xx0<<<<$',
!         \ '$'
              \ ]
    redraw!
    for i in range(1, 5)
***************
*** 162,168 ****
              \ ' hyYzZyYzZyY$',
              \ 'yYzZyYzZyYj $',
              \ 'yYzZ0yY0yYzZ$',
!               \ '$'
              \ ]
    redraw!
    for i in range(1, 5)
--- 162,168 ----
              \ ' hyYzZyYzZyY$',
              \ 'yYzZyYzZyYj $',
              \ 'yYzZ0yY0yYzZ$',
!         \ '$'
              \ ]
    redraw!
    for i in range(1, 5)
***************
*** 172,178 ****
--- 172,304 ----
  
    call assert_equal(expected, split(execute("%list"), "\n"))
  
+   " Test leadmultispace + multispace
+   normal ggdG
+   set listchars=eol:$,multispace:yYzZ,nbsp:S
+   set listchars+=leadmultispace:.-+*
+   set list
+ 
+   call append(0, [
+             \ '    ffff    ',
+             \ '  i i     gg',
+             \ ' h          ',
+             \ '          j ',
+             \ '    0  0    ',
+             \ ])
+ 
+   let expected = [
+             \ '.-+*ffffyYzZ$',
+             \ '.-i iSyYzZgg$',
+             \ ' hyYzZyYzZyY$',
+             \ '.-+*.-+*.-j $',
+             \ '.-+*0yY0yYzZ$',
+         \ '$'
+             \ ]
+   redraw!
+   call assert_equal('eol:$,multispace:yYzZ,nbsp:S,leadmultispace:.-+*', 
&listchars)
+   for i in range(1, 5)
+     call cursor(i, 1)
+     call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
+   endfor
+ 
+   call assert_equal(expected, split(execute("%list"), "\n"))
+ 
+   " Test leadmultispace without multispace
+   normal ggdG
+   set listchars-=multispace:yYzZ
+   set listchars+=space:+,trail:>,eol:$
+   set list
+ 
+   call append(0, [
+             \ '    ffff    ',
+             \ '  i i     gg',
+             \ ' h          ',
+             \ '          j ',
+             \ '    0  0    ',
+             \ ])
+ 
+   let expected = [
+             \ '.-+*ffff>>>>$',
+             \ '.-i+i+++++gg$',
+             \ '+h>>>>>>>>>>$',
+             \ '.-+*.-+*.-j>$',
+             \ '.-+*0++0>>>>$',
+         \ '$',
+             \ ]
+ 
+   redraw!
+   call assert_equal('eol:$,nbsp:S,leadmultispace:.-+*,space:+,trail:>,eol:$', 
&listchars)
+   for i in range(1, 5)
+     call cursor(i, 1)
+     call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
+   endfor
+ 
+   call assert_equal(expected, split(execute("%list"), "\n"))
+ 
+   " Test leadmultispace only
+   normal ggdG
+   set listchars&
+   set listchars=leadmultispace:.-+*
+   set list
+ 
+   call append(0, [
+             \ '    ffff    ',
+             \ '  i i     gg',
+             \ ' h          ',
+             \ '          j ',
+             \ '    0  0    ',
+             \ ])
+ 
+   let expected = [
+             \ '.-+*ffff    ',
+             \ '.-i i     gg',
+             \ ' h          ',
+             \ '.-+*.-+*.-j ',
+             \ '.-+*0  0    ',
+         \ ' ',
+             \ ]
+   redraw!
+   call assert_equal('leadmultispace:.-+*', &listchars)
+   for i in range(1, 5)
+     call cursor(i, 1)
+     call assert_equal([expected[i - 1]], ScreenLines(i, 12))
+   endfor
+   call assert_equal(expected, split(execute("%list"), "\n"))
+ 
+   " Test leadmultispace and lead and space
+   normal ggdG
+   set listchars&
+   set listchars+=lead:<,space:-
+   set listchars+=leadmultispace:.-+*
+   set list
+ 
+   call append(0, [
+             \ '    ffff    ',
+             \ '  i i     gg',
+             \ ' h          ',
+             \ '          j ',
+             \ '    0  0    ',
+             \ ])
+ 
+   let expected = [
+             \ '.-+*ffff----$',
+             \ '.-i-i-----gg$',
+             \ '<h----------$',
+             \ '.-+*.-+*.-j-$',
+             \ '.-+*0--0----$',
+         \ '$',
+             \ ]
+   redraw!
+   call assert_equal('eol:$,lead:<,space:-,leadmultispace:.-+*', &listchars)
+   for i in range(1, 5)
+     call cursor(i, 1)
+     call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
+   endfor
+   call assert_equal(expected, split(execute("%list"), "\n"))
+ 
    " the last occurrence of 'multispace:' is used
+   set listchars&
+   set listchars+=multispace:yYzZ
    set listchars+=space:x,multispace:XyY
  
    let expected = [
***************
*** 181,189 ****
              \ 'xhXyYXyYXyYX$',
              \ 'XyYXyYXyYXjx$',
              \ 'XyYX0Xy0XyYX$',
!               \ '$'
              \ ]
    redraw!
    for i in range(1, 5)
      call cursor(i, 1)
      call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
--- 307,316 ----
              \ 'xhXyYXyYXyYX$',
              \ 'XyYXyYXyYXjx$',
              \ 'XyYX0Xy0XyYX$',
!         \ '$'
              \ ]
    redraw!
+   call assert_equal('eol:$,multispace:yYzZ,space:x,multispace:XyY', 
&listchars)
    for i in range(1, 5)
      call cursor(i, 1)
      call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
***************
*** 199,205 ****
              \ '>h<<<<<<<<<<$',
              \ '>>>>>>>>>>j<$',
              \ '>>>>0Xy0<<<<$',
!               \ '$'
              \ ]
    redraw!
    for i in range(1, 5)
--- 326,332 ----
              \ '>h<<<<<<<<<<$',
              \ '>>>>>>>>>>j<$',
              \ '>>>>0Xy0<<<<$',
!         \ '$'
              \ ]
    redraw!
    for i in range(1, 5)
***************
*** 219,225 ****
              \ '>h<<<<<<<<<<$',
              \ '>>>>>>>>>>j<$',
              \ '>>>>0xx0<<<<$',
!               \ '$'
              \ ]
    redraw!
    for i in range(1, 5)
--- 346,352 ----
              \ '>h<<<<<<<<<<$',
              \ '>>>>>>>>>>j<$',
              \ '>>>>0xx0<<<<$',
!         \ '$'
              \ ]
    redraw!
    for i in range(1, 5)
***************
*** 315,325 ****
--- 442,454 ----
    call assert_fails('set listchars=x', 'E474:')
    call assert_fails('set listchars=x', 'E474:')
    call assert_fails('set listchars=multispace', 'E474:')
+   call assert_fails('set listchars=leadmultispace', 'E474:')
  
    " Too short
    call assert_fails('set listchars=space:', 'E474:')
    call assert_fails('set listchars=tab:x', 'E474:')
    call assert_fails('set listchars=multispace:', 'E474:')
+   call assert_fails('set listchars=leadmultispace:', 'E474:')
  
    " One occurrence too short
    call assert_fails('set listchars=space:,space:x', 'E474:')
***************
*** 328,333 ****
--- 457,464 ----
    call assert_fails('set listchars=tab:xx,tab:x', 'E474:')
    call assert_fails('set listchars=multispace:,multispace:x', 'E474:')
    call assert_fails('set listchars=multispace:x,multispace:', 'E474:')
+   call assert_fails('set listchars=leadmultispace:,leadmultispace:x', 'E474:')
+   call assert_fails('set listchars=leadmultispace:x,leadmultispace:', 'E474:')
  
    " Too long
    call assert_fails('set listchars=space:xx', 'E474:')
***************
*** 340,345 ****
--- 471,478 ----
    call assert_fails('set listchars=tab:xx·', 'E474:')
    call assert_fails('set listchars=multispace:·', 'E474:')
    call assert_fails('set listchars=multispace:xxx·', 'E474:')
+   call assert_fails('set listchars=leadmultispace:·', 'E474:')
+   call assert_fails('set listchars=leadmultispace:xxx·', 'E474:')
  
    " Has control character
    call assert_fails("set listchars=space:\x01", 'E474:')
***************
*** 354,359 ****
--- 487,496 ----
    call assert_fails('set listchars=tab:xx\\x01', 'E474:')
    call assert_fails('set listchars=multispace:\\x01', 'E474:')
    call assert_fails('set listchars=multispace:xxx\\x01', 'E474:')
+   call assert_fails("set listchars=leadmultispace:\x01", 'E474:')
+   call assert_fails('set listchars=leadmultispace:\\x01', 'E474:')
+   call assert_fails("set listchars=leadmultispace:xxx\x01", 'E474:')
+   call assert_fails('set listchars=leadmultispace:xxx\\x01', 'E474:')
  
    enew!
    set ambiwidth& listchars& ff&
*** ../vim-8.2.5065/src/version.c       2022-06-06 22:16:06.158653538 +0100
--- src/version.c       2022-06-07 10:15:17.849358487 +0100
***************
*** 736,737 ****
--- 736,739 ----
  {   /* Add new patch number below this line */
+ /**/
+     5066,
  /**/

-- 
TALL KNIGHT: When you have found the shrubbery, then you must cut down the
             mightiest tree in the forest ... with a herring.
                 "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/20220607091712.B5D611C291C%40moolenaar.net.

Raspunde prin e-mail lui