]> granicus.if.org Git - vim/commitdiff
patch 8.2.4882: cannot make 'breakindent' use a specific column v8.2.4882
authorChristian Brabandt <cb@256bit.org>
Fri, 6 May 2022 11:21:04 +0000 (12:21 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 6 May 2022 11:21:04 +0000 (12:21 +0100)
Problem:    Cannot make 'breakindent' use a specific column.
Solution:   Add the "column" entry in 'breakindentopt'. (Christian Brabandt,
            closes #10362, closes #10325)

runtime/doc/options.txt
src/indent.c
src/structs.h
src/testdir/test_breakindent.vim
src/version.c

index cd048456d3b704668ac20b95617d7b4eae7d2d06..689c9a28c1d0b179e4d4243b3165294d228e219d 100644 (file)
@@ -1392,14 +1392,20 @@ A jump table for the options with a short description can be found at |Q_op|.
                            characters.  It permits dynamic French paragraph
                            indentation (negative) or emphasizing the line
                            continuation (positive).
+                           (default: 0)
                sbr         Display the 'showbreak' value before applying the
                            additional indent.
+                           (default: off)
                list:{n}    Adds an additional indent for lines that match a
                            numbered or bulleted list (using the
                            'formatlistpat' setting).
                list:-1     Uses the length of a match with 'formatlistpat'
                            for indentation.
-       The default value for min is 20, shift and list is 0.
+                           (default: 0)
+               column:{n}  Indent at column {n}. Will overrule the other
+                           sub-options. Note: an additional indent may be
+                           added for the 'showbreak' setting.
+                           (default: off)
 
                                                *'browsedir'* *'bsdir'*
 'browsedir' 'bsdir'    string  (default: "last")
index 9efa52753ecda60469aa3bf20ba24f07ce1a1166..e8892b517fe609394ac5c4401ef055a6065095c8 100644 (file)
@@ -866,6 +866,7 @@ briopt_check(win_T *wp)
     long       bri_min = 20;
     int                bri_sbr = FALSE;
     int                bri_list = 0;
+    int                bri_vcol = 0;
 
     p = wp->w_p_briopt;
     while (*p != NUL)
@@ -891,6 +892,11 @@ briopt_check(win_T *wp)
            p += 5;
            bri_list = getdigits(&p);
        }
+       else if (STRNCMP(p, "column:", 7) == 0)
+       {
+           p += 7;
+           bri_vcol = getdigits(&p);
+       }
        if (*p != ',' && *p != NUL)
            return FAIL;
        if (*p == ',')
@@ -901,6 +907,7 @@ briopt_check(win_T *wp)
     wp->w_briopt_min   = bri_min;
     wp->w_briopt_sbr   = bri_sbr;
     wp->w_briopt_list  = bri_list;
+    wp->w_briopt_vcol  = bri_vcol;
 
     return OK;
 }
@@ -953,11 +960,13 @@ get_breakindent_win(
        prev_tick = CHANGEDTICK(wp->w_buffer);
 # ifdef FEAT_VARTABS
        prev_vts = wp->w_buffer->b_p_vts_array;
-       prev_indent = get_indent_str_vtab(line,
+       if (wp->w_briopt_vcol == 0)
+           prev_indent = get_indent_str_vtab(line,
                                     (int)wp->w_buffer->b_p_ts,
                                    wp->w_buffer->b_p_vts_array, wp->w_p_list);
 # else
-       prev_indent = get_indent_str(line,
+       if (wp->w_briopt_vcol == 0)
+           prev_indent = get_indent_str(line,
                                     (int)wp->w_buffer->b_p_ts, wp->w_p_list);
 # endif
        prev_listopt = wp->w_briopt_list;
@@ -965,7 +974,7 @@ get_breakindent_win(
        vim_free(prev_flp);
        prev_flp = vim_strsave(get_flp_value(wp->w_buffer));
        // add additional indent for numbered lists
-       if (wp->w_briopt_list != 0)
+       if (wp->w_briopt_list != 0 && wp->w_briopt_vcol == 0)
        {
            regmatch_T      regmatch;
 
@@ -986,7 +995,14 @@ get_breakindent_win(
            }
        }
     }
-    bri = prev_indent + wp->w_briopt_shift;
+    if (wp->w_briopt_vcol != 0)
+    {
+       // column value has priority
+       bri = wp->w_briopt_vcol;
+       prev_list = 0;
+    }
+    else
+       bri = prev_indent + wp->w_briopt_shift;
 
     // Add offset for number column, if 'n' is in 'cpoptions'
     bri += win_col_off2(wp);
index 3135616dd4b21d8a7cca8be83b8db538c9331369..1a607c65e15f3a906576064ae61acaddb23bc131 100644 (file)
@@ -3215,7 +3215,7 @@ struct diffblock_S
 #endif
 
 #define SNAP_HELP_IDX  0
-#define SNAP_AUCMD_IDX 1
+#define SNAP_AUCMD_IDX 1
 #define SNAP_COUNT     2
 
 /*
@@ -3312,7 +3312,8 @@ struct frame_S
                                // for first
     // fr_child and fr_win are mutually exclusive
     frame_T    *fr_child;      // first contained frame
-    win_T      *fr_win;        // window that fills this frame
+    win_T      *fr_win;        // window that fills this frame; for a snapshot
+                               // set to the current window
 };
 
 #define FR_LEAF        0       // frame is a leaf
@@ -3742,6 +3743,7 @@ struct window_S
     int                w_briopt_shift;     // additional shift for breakindent
     int                w_briopt_sbr;       // sbr in 'briopt'
     int                w_briopt_list;      // additional indent for lists
+    int                w_briopt_vcol;      // indent for specific column
 #endif
 
     long       w_scbind_pos;
index 9b6106d7be7c9c1e1a6d9fd2cb026f92a07bdc69..8f8f2c4f1b2f6516991f85e5d2792dca72971ce4 100644 (file)
@@ -837,16 +837,17 @@ endfunc
 func Test_window_resize_with_linebreak()
   new
   53vnew
-  set linebreak
-  set showbreak=>>
-  set breakindent
-  set breakindentopt=shift:4
+  setl linebreak
+  setl showbreak=>>
+  setl breakindent
+  setl breakindentopt=shift:4
   call setline(1, "\naaaaaaaaa\n\na\naaaaa\n¯aaaaaaaaaa\naaaaaaaaaaaa\naaa\n\"a:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaa\"\naaaaaaaa\n\"a")
   redraw!
   call assert_equal(["    >>aa^@\"a: "], ScreenLines(2, 14))
   vertical resize 52
   redraw!
   call assert_equal(["    >>aaa^@\"a:"], ScreenLines(2, 14))
+  set linebreak& showbreak& breakindent& breakindentopt&
   %bw!
 endfunc
 
@@ -943,4 +944,57 @@ func Test_no_extra_indent()
   bwipeout!
 endfunc
 
+func Test_breakindent_column()
+  " restore original
+  let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP"
+  call s:test_windows('setl breakindent breakindentopt=column:10')
+  redraw!
+  " 1) default: does not indent, too wide :(
+  let expect = [
+  \ "                    ",
+  \ "    abcdefghijklmnop",
+  \ "qrstuvwxyzABCDEFGHIJ",
+  \ "KLMNOP              "
+  \ ]
+  let lines = s:screen_lines2(1, 4, 20)
+  call s:compare_lines(expect, lines)
+  " 2) lower min value, so that breakindent works
+  setl breakindentopt+=min:5
+  redraw!
+  let expect = [
+  \ "                    ",
+  \ "    abcdefghijklmnop",
+  \ "          qrstuvwxyz",
+  \ "          ABCDEFGHIJ",
+  \ "          KLMNOP    "
+  \ ]
+  let lines = s:screen_lines2(1, 5, 20)
+  " 3) set shift option -> no influence
+  setl breakindentopt+=shift:5
+  redraw!
+  let expect = [
+  \ "                    ",
+  \ "    abcdefghijklmnop",
+  \ "          qrstuvwxyz",
+  \ "          ABCDEFGHIJ",
+  \ "          KLMNOP    "
+  \ ]
+  let lines = s:screen_lines2(1, 5, 20)
+  call s:compare_lines(expect, lines)
+  " 4) add showbreak value
+  setl showbreak=++
+  redraw!
+  let expect = [
+  \ "                    ",
+  \ "    abcdefghijklmnop",
+  \ "          ++qrstuvwx",
+  \ "          ++yzABCDEF",
+  \ "          ++GHIJKLMN",
+  \ "          ++OP      "
+  \ ]
+  let lines = s:screen_lines2(1, 6, 20)
+  call s:compare_lines(expect, lines)
+  bwipeout!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 301c5831abb46df20c444563a48d9075e6f96387..4cb930fd6156ed3341d021e2c3fca706d29a0c23 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4882,
 /**/
     4881,
 /**/