0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

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 #2711)
This commit is contained in:
Bram Moolenaar
2018-06-23 19:23:02 +02:00
parent 5ec7414a1c
commit 04958cbaf2
31 changed files with 1750 additions and 173 deletions

View File

@@ -742,7 +742,14 @@ edit(
mincol = curwin->w_wcol;
validate_cursor_col();
if ((int)curwin->w_wcol < mincol - curbuf->b_p_ts
if (
#ifdef FEAT_VARTABS
(int)curwin->w_wcol < mincol - tabstop_at(
get_nolist_virtcol(), curbuf->b_p_ts,
curbuf->b_p_vts_array)
#else
(int)curwin->w_wcol < mincol - curbuf->b_p_ts
#endif
&& curwin->w_wrow == W_WINROW(curwin)
+ curwin->w_height - 1 - p_so
&& (curwin->w_cursor.lnum != curwin->w_topline
@@ -9329,23 +9336,31 @@ ins_bs(
*/
if ( mode == BACKSPACE_CHAR
&& ((p_sta && in_indent)
|| (get_sts_value() != 0
|| ((get_sts_value() != 0
#ifdef FEAT_VARTABS
|| tabstop_count(curbuf->b_p_vsts_array)
#endif
)
&& curwin->w_cursor.col > 0
&& (*(ml_get_cursor() - 1) == TAB
|| (*(ml_get_cursor() - 1) == ' '
&& (!*inserted_space_p
|| arrow_used))))))
{
#ifndef FEAT_VARTABS
int ts;
#endif
colnr_T vcol;
colnr_T want_vcol;
colnr_T start_vcol;
*inserted_space_p = FALSE;
#ifndef FEAT_VARTABS
if (p_sta && in_indent)
ts = (int)get_sw_value(curbuf);
else
ts = (int)get_sts_value();
#endif
/* Compute the virtual column where we want to be. Since
* 'showbreak' may get in the way, need to get the last column of
* the previous character. */
@@ -9354,7 +9369,15 @@ ins_bs(
dec_cursor();
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &want_vcol);
inc_cursor();
#ifdef FEAT_VARTABS
if (p_sta && in_indent)
want_vcol = (want_vcol / curbuf->b_p_sw) * curbuf->b_p_sw;
else
want_vcol = tabstop_start(want_vcol, curbuf->b_p_sts,
curbuf->b_p_vsts_array);
#else
want_vcol = (want_vcol / ts) * ts;
#endif
/* delete characters until we are at or before want_vcol */
while (vcol > want_vcol
@@ -10144,10 +10167,22 @@ ins_tab(void)
#endif
/*
* When nothing special, insert TAB like a normal character
* When nothing special, insert TAB like a normal character.
*/
if (!curbuf->b_p_et
#ifdef FEAT_VARTABS
&& !(p_sta && ind
/* These five lines mean 'tabstop' != 'shiftwidth' */
&& ((tabstop_count(curbuf->b_p_vts_array) > 1)
|| (tabstop_count(curbuf->b_p_vts_array) == 1
&& tabstop_first(curbuf->b_p_vts_array)
!= get_sw_value(curbuf))
|| (tabstop_count(curbuf->b_p_vts_array) == 0
&& curbuf->b_p_ts != get_sw_value(curbuf))))
&& tabstop_count(curbuf->b_p_vsts_array) == 0
#else
&& !(p_sta && ind && curbuf->b_p_ts != get_sw_value(curbuf))
#endif
&& get_sts_value() == 0)
return TRUE;
@@ -10162,6 +10197,20 @@ ins_tab(void)
#endif
AppendToRedobuff((char_u *)"\t");
#ifdef FEAT_VARTABS
if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */
{
temp = (int)curbuf->b_p_sw;
temp -= get_nolist_virtcol() % temp;
}
else if (tabstop_count(curbuf->b_p_vsts_array) > 0 || curbuf->b_p_sts > 0)
/* use 'softtabstop' when set */
temp = tabstop_padding(get_nolist_virtcol(), curbuf->b_p_sts,
curbuf->b_p_vsts_array);
else /* otherwise use 'tabstop' */
temp = tabstop_padding(get_nolist_virtcol(), curbuf->b_p_ts,
curbuf->b_p_vts_array);
#else
if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */
temp = (int)get_sw_value(curbuf);
else if (curbuf->b_p_sts != 0) /* use 'softtabstop' when set */
@@ -10169,6 +10218,7 @@ ins_tab(void)
else /* otherwise use 'tabstop' */
temp = (int)curbuf->b_p_ts;
temp -= get_nolist_virtcol() % temp;
#endif
/*
* Insert the first space with ins_char(). It will delete one char in
@@ -10193,7 +10243,13 @@ ins_tab(void)
/*
* When 'expandtab' not set: Replace spaces by TABs where possible.
*/
#ifdef FEAT_VARTABS
if (!curbuf->b_p_et && (tabstop_count(curbuf->b_p_vsts_array) > 0
|| get_sts_value() > 0
|| (p_sta && ind)))
#else
if (!curbuf->b_p_et && (get_sts_value() || (p_sta && ind)))
#endif
{
char_u *ptr;
#ifdef FEAT_VREPLACE