comparison src/edit.c @ 14175:2ad722003b36 v8.1.0105

patch 8.1.0105: all tab stops are the same commit https://github.com/vim/vim/commit/04958cbaf25eea27eceedaa987adfb354ad5f7fd Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jun 23 19:23:02 2018 +0200 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)
author Christian Brabandt <cb@256bit.org>
date Sat, 23 Jun 2018 19:30:07 +0200
parents d053ec57d886
children fbf0681606fa
comparison
equal deleted inserted replaced
14174:d36eedd19166 14175:2ad722003b36
740 ) 740 )
741 { 741 {
742 mincol = curwin->w_wcol; 742 mincol = curwin->w_wcol;
743 validate_cursor_col(); 743 validate_cursor_col();
744 744
745 if ((int)curwin->w_wcol < mincol - curbuf->b_p_ts 745 if (
746 #ifdef FEAT_VARTABS
747 (int)curwin->w_wcol < mincol - tabstop_at(
748 get_nolist_virtcol(), curbuf->b_p_ts,
749 curbuf->b_p_vts_array)
750 #else
751 (int)curwin->w_wcol < mincol - curbuf->b_p_ts
752 #endif
746 && curwin->w_wrow == W_WINROW(curwin) 753 && curwin->w_wrow == W_WINROW(curwin)
747 + curwin->w_height - 1 - p_so 754 + curwin->w_height - 1 - p_so
748 && (curwin->w_cursor.lnum != curwin->w_topline 755 && (curwin->w_cursor.lnum != curwin->w_topline
749 #ifdef FEAT_DIFF 756 #ifdef FEAT_DIFF
750 || curwin->w_topfill > 0 757 || curwin->w_topfill > 0
9327 /* 9334 /*
9328 * Handle deleting one 'shiftwidth' or 'softtabstop'. 9335 * Handle deleting one 'shiftwidth' or 'softtabstop'.
9329 */ 9336 */
9330 if ( mode == BACKSPACE_CHAR 9337 if ( mode == BACKSPACE_CHAR
9331 && ((p_sta && in_indent) 9338 && ((p_sta && in_indent)
9332 || (get_sts_value() != 0 9339 || ((get_sts_value() != 0
9340 #ifdef FEAT_VARTABS
9341 || tabstop_count(curbuf->b_p_vsts_array)
9342 #endif
9343 )
9333 && curwin->w_cursor.col > 0 9344 && curwin->w_cursor.col > 0
9334 && (*(ml_get_cursor() - 1) == TAB 9345 && (*(ml_get_cursor() - 1) == TAB
9335 || (*(ml_get_cursor() - 1) == ' ' 9346 || (*(ml_get_cursor() - 1) == ' '
9336 && (!*inserted_space_p 9347 && (!*inserted_space_p
9337 || arrow_used)))))) 9348 || arrow_used))))))
9338 { 9349 {
9350 #ifndef FEAT_VARTABS
9339 int ts; 9351 int ts;
9352 #endif
9340 colnr_T vcol; 9353 colnr_T vcol;
9341 colnr_T want_vcol; 9354 colnr_T want_vcol;
9342 colnr_T start_vcol; 9355 colnr_T start_vcol;
9343 9356
9344 *inserted_space_p = FALSE; 9357 *inserted_space_p = FALSE;
9358 #ifndef FEAT_VARTABS
9345 if (p_sta && in_indent) 9359 if (p_sta && in_indent)
9346 ts = (int)get_sw_value(curbuf); 9360 ts = (int)get_sw_value(curbuf);
9347 else 9361 else
9348 ts = (int)get_sts_value(); 9362 ts = (int)get_sts_value();
9363 #endif
9349 /* Compute the virtual column where we want to be. Since 9364 /* Compute the virtual column where we want to be. Since
9350 * 'showbreak' may get in the way, need to get the last column of 9365 * 'showbreak' may get in the way, need to get the last column of
9351 * the previous character. */ 9366 * the previous character. */
9352 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL); 9367 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
9353 start_vcol = vcol; 9368 start_vcol = vcol;
9354 dec_cursor(); 9369 dec_cursor();
9355 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &want_vcol); 9370 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &want_vcol);
9356 inc_cursor(); 9371 inc_cursor();
9372 #ifdef FEAT_VARTABS
9373 if (p_sta && in_indent)
9374 want_vcol = (want_vcol / curbuf->b_p_sw) * curbuf->b_p_sw;
9375 else
9376 want_vcol = tabstop_start(want_vcol, curbuf->b_p_sts,
9377 curbuf->b_p_vsts_array);
9378 #else
9357 want_vcol = (want_vcol / ts) * ts; 9379 want_vcol = (want_vcol / ts) * ts;
9380 #endif
9358 9381
9359 /* delete characters until we are at or before want_vcol */ 9382 /* delete characters until we are at or before want_vcol */
9360 while (vcol > want_vcol 9383 while (vcol > want_vcol
9361 && (cc = *(ml_get_cursor() - 1), VIM_ISWHITE(cc))) 9384 && (cc = *(ml_get_cursor() - 1), VIM_ISWHITE(cc)))
9362 ins_bs_one(&vcol); 9385 ins_bs_one(&vcol);
10142 if (ind) 10165 if (ind)
10143 can_cindent = FALSE; 10166 can_cindent = FALSE;
10144 #endif 10167 #endif
10145 10168
10146 /* 10169 /*
10147 * When nothing special, insert TAB like a normal character 10170 * When nothing special, insert TAB like a normal character.
10148 */ 10171 */
10149 if (!curbuf->b_p_et 10172 if (!curbuf->b_p_et
10173 #ifdef FEAT_VARTABS
10174 && !(p_sta && ind
10175 /* These five lines mean 'tabstop' != 'shiftwidth' */
10176 && ((tabstop_count(curbuf->b_p_vts_array) > 1)
10177 || (tabstop_count(curbuf->b_p_vts_array) == 1
10178 && tabstop_first(curbuf->b_p_vts_array)
10179 != get_sw_value(curbuf))
10180 || (tabstop_count(curbuf->b_p_vts_array) == 0
10181 && curbuf->b_p_ts != get_sw_value(curbuf))))
10182 && tabstop_count(curbuf->b_p_vsts_array) == 0
10183 #else
10150 && !(p_sta && ind && curbuf->b_p_ts != get_sw_value(curbuf)) 10184 && !(p_sta && ind && curbuf->b_p_ts != get_sw_value(curbuf))
10185 #endif
10151 && get_sts_value() == 0) 10186 && get_sts_value() == 0)
10152 return TRUE; 10187 return TRUE;
10153 10188
10154 if (stop_arrow() == FAIL) 10189 if (stop_arrow() == FAIL)
10155 return TRUE; 10190 return TRUE;
10160 can_si = FALSE; 10195 can_si = FALSE;
10161 can_si_back = FALSE; 10196 can_si_back = FALSE;
10162 #endif 10197 #endif
10163 AppendToRedobuff((char_u *)"\t"); 10198 AppendToRedobuff((char_u *)"\t");
10164 10199
10200 #ifdef FEAT_VARTABS
10201 if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */
10202 {
10203 temp = (int)curbuf->b_p_sw;
10204 temp -= get_nolist_virtcol() % temp;
10205 }
10206 else if (tabstop_count(curbuf->b_p_vsts_array) > 0 || curbuf->b_p_sts > 0)
10207 /* use 'softtabstop' when set */
10208 temp = tabstop_padding(get_nolist_virtcol(), curbuf->b_p_sts,
10209 curbuf->b_p_vsts_array);
10210 else /* otherwise use 'tabstop' */
10211 temp = tabstop_padding(get_nolist_virtcol(), curbuf->b_p_ts,
10212 curbuf->b_p_vts_array);
10213 #else
10165 if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */ 10214 if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */
10166 temp = (int)get_sw_value(curbuf); 10215 temp = (int)get_sw_value(curbuf);
10167 else if (curbuf->b_p_sts != 0) /* use 'softtabstop' when set */ 10216 else if (curbuf->b_p_sts != 0) /* use 'softtabstop' when set */
10168 temp = (int)get_sts_value(); 10217 temp = (int)get_sts_value();
10169 else /* otherwise use 'tabstop' */ 10218 else /* otherwise use 'tabstop' */
10170 temp = (int)curbuf->b_p_ts; 10219 temp = (int)curbuf->b_p_ts;
10171 temp -= get_nolist_virtcol() % temp; 10220 temp -= get_nolist_virtcol() % temp;
10221 #endif
10172 10222
10173 /* 10223 /*
10174 * Insert the first space with ins_char(). It will delete one char in 10224 * Insert the first space with ins_char(). It will delete one char in
10175 * replace mode. Insert the rest with ins_str(); it will not delete any 10225 * replace mode. Insert the rest with ins_str(); it will not delete any
10176 * chars. For VREPLACE mode, we use ins_char() for all characters. 10226 * chars. For VREPLACE mode, we use ins_char() for all characters.
10191 } 10241 }
10192 10242
10193 /* 10243 /*
10194 * When 'expandtab' not set: Replace spaces by TABs where possible. 10244 * When 'expandtab' not set: Replace spaces by TABs where possible.
10195 */ 10245 */
10246 #ifdef FEAT_VARTABS
10247 if (!curbuf->b_p_et && (tabstop_count(curbuf->b_p_vsts_array) > 0
10248 || get_sts_value() > 0
10249 || (p_sta && ind)))
10250 #else
10196 if (!curbuf->b_p_et && (get_sts_value() || (p_sta && ind))) 10251 if (!curbuf->b_p_et && (get_sts_value() || (p_sta && ind)))
10252 #endif
10197 { 10253 {
10198 char_u *ptr; 10254 char_u *ptr;
10199 #ifdef FEAT_VREPLACE 10255 #ifdef FEAT_VREPLACE
10200 char_u *saved_line = NULL; /* init for GCC */ 10256 char_u *saved_line = NULL; /* init for GCC */
10201 pos_T pos; 10257 pos_T pos;