diff options
author | VVKot <volodymyr.kot.ua@gmail.com> | 2021-02-13 19:06:37 +0000 |
---|---|---|
committer | VVKot <volodymyr.kot.ua@gmail.com> | 2021-03-28 08:37:01 +0100 |
commit | 6752ac49682d63dfc7960e518ecbd6517c88392d (patch) | |
tree | b0e4a27d32f23ea52f11ae1a6a4f24617f79a5e6 /src/nvim/change.c | |
parent | b79596eb5e942a299aa021a0f9a3f2db909294da (diff) | |
download | rneovim-6752ac49682d63dfc7960e518ecbd6517c88392d.tar.gz rneovim-6752ac49682d63dfc7960e518ecbd6517c88392d.tar.bz2 rneovim-6752ac49682d63dfc7960e518ecbd6517c88392d.zip |
vim-patch:8.1.0105: all tab stops are the same
Problem: All tab stops are the same.
Solution: Add the variable tabstop feature. (Christian Brabandt,
closes vim/vim#2711)
https://github.com/vim/vim/commit/04958cbaf25eea27eceedaa987adfb354ad5f7fd
Diffstat (limited to 'src/nvim/change.c')
-rw-r--r-- | src/nvim/change.c | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/src/nvim/change.c b/src/nvim/change.c index 0f5081c94c..38bd591eca 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -828,6 +828,7 @@ int copy_indent(int size, char_u *src) int tab_pad; int ind_done; int round; + int ind_col; // Round 1: compute the number of characters needed for the indent // Round 2: copy the characters. @@ -835,13 +836,15 @@ int copy_indent(int size, char_u *src) todo = size; ind_len = 0; ind_done = 0; + ind_col = 0; s = src; // Count/copy the usable portion of the source line. while (todo > 0 && ascii_iswhite(*s)) { if (*s == TAB) { - tab_pad = (int)curbuf->b_p_ts - - (ind_done % (int)curbuf->b_p_ts); + tab_pad = tabstop_padding(ind_done, + curbuf->b_p_ts, + curbuf->b_p_vts_array); // Stop if this tab will overshoot the target. if (todo < tab_pad) { @@ -849,9 +852,11 @@ int copy_indent(int size, char_u *src) } todo -= tab_pad; ind_done += tab_pad; + ind_col += tab_pad; } else { todo--; ind_done++; + ind_col++; } ind_len++; @@ -862,11 +867,12 @@ int copy_indent(int size, char_u *src) } // Fill to next tabstop with a tab, if possible. - tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); + tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts, curbuf->b_p_vts_array); if ((todo >= tab_pad) && !curbuf->b_p_et) { todo -= tab_pad; ind_len++; + ind_col += tab_pad; if (p != NULL) { *p++ = TAB; @@ -874,12 +880,20 @@ int copy_indent(int size, char_u *src) } // Add tabs required for indent. - while (todo >= (int)curbuf->b_p_ts && !curbuf->b_p_et) { - todo -= (int)curbuf->b_p_ts; - ind_len++; - - if (p != NULL) { - *p++ = TAB; + if (!curbuf->b_p_et) { + for (;;) { + tab_pad = tabstop_padding(ind_col, + curbuf->b_p_ts, + curbuf->b_p_vts_array); + if (todo < tab_pad) { + break; + } + todo -= tab_pad; + ind_len++; + ind_col += tab_pad; + if (p != NULL) { + *p++ = TAB; + } } } @@ -1029,7 +1043,9 @@ int open_line( || do_si ) { // count white space on current line - newindent = get_indent_str(saved_line, (int)curbuf->b_p_ts, false); + newindent = get_indent_str_vtab(saved_line, + curbuf->b_p_ts, + curbuf->b_p_vts_array, false); if (newindent == 0 && !(flags & OPENLINE_COM_LIST)) { newindent = second_line_indent; // for ^^D command in insert mode } @@ -1453,7 +1469,9 @@ int open_line( if (curbuf->b_p_ai || do_si ) { - newindent = get_indent_str(leader, (int)curbuf->b_p_ts, false); + newindent = get_indent_str_vtab(leader, + curbuf->b_p_ts, + curbuf->b_p_vts_array, false); } // Add the indent offset |