Skip to content

Commit 881adbf

Browse files
committed
updated for version 7.3.629
Problem: There is no way to make 'shiftwidth' follow 'tabstop'. Solution: When 'shiftwidth' is zero use the value of 'tabstop'. (Christian Brabandt)
1 parent 967175e commit 881adbf

File tree

8 files changed

+46
-26
lines changed

8 files changed

+46
-26
lines changed

src/edit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8899,9 +8899,9 @@ ins_bs(c, mode, inserted_space_p)
88998899

89008900
*inserted_space_p = FALSE;
89018901
if (p_sta && in_indent)
8902-
ts = curbuf->b_p_sw;
8902+
ts = (int)get_sw_value();
89038903
else
8904-
ts = curbuf->b_p_sts;
8904+
ts = (int)curbuf->b_p_sts;
89058905
/* Compute the virtual column where we want to be. Since
89068906
* 'showbreak' may get in the way, need to get the last column of
89078907
* the previous character. */
@@ -9589,7 +9589,7 @@ ins_tab()
95899589
* When nothing special, insert TAB like a normal character
95909590
*/
95919591
if (!curbuf->b_p_et
9592-
&& !(p_sta && ind && curbuf->b_p_ts != curbuf->b_p_sw)
9592+
&& !(p_sta && ind && curbuf->b_p_ts != get_sw_value())
95939593
&& curbuf->b_p_sts == 0)
95949594
return TRUE;
95959595

@@ -9605,7 +9605,7 @@ ins_tab()
96059605
AppendToRedobuff((char_u *)"\t");
96069606

96079607
if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */
9608-
temp = (int)curbuf->b_p_sw;
9608+
temp = (int)get_sw_value();
96099609
else if (curbuf->b_p_sts > 0) /* use 'softtabstop' when set */
96109610
temp = (int)curbuf->b_p_sts;
96119611
else /* otherwise use 'tabstop' */

src/ex_getln.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,10 +2268,12 @@ getexmodeline(promptc, cookie, indent)
22682268

22692269
if (c1 == Ctrl_T)
22702270
{
2271+
long sw = get_sw_value();
2272+
22712273
p = (char_u *)line_ga.ga_data;
22722274
p[line_ga.ga_len] = NUL;
22732275
indent = get_indent_str(p, 8);
2274-
indent += curbuf->b_p_sw - indent % curbuf->b_p_sw;
2276+
indent += sw - indent % sw;
22752277
add_indent:
22762278
while (get_indent_str(p, 8) < indent)
22772279
{
@@ -2323,7 +2325,7 @@ getexmodeline(promptc, cookie, indent)
23232325
p[line_ga.ga_len] = NUL;
23242326
indent = get_indent_str(p, 8);
23252327
--indent;
2326-
indent -= indent % curbuf->b_p_sw;
2328+
indent -= indent % get_sw_value();
23272329
}
23282330
while (get_indent_str(p, 8) > indent)
23292331
{

src/fold.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3025,7 +3025,7 @@ foldlevelIndent(flp)
30253025
flp->lvl = -1;
30263026
}
30273027
else
3028-
flp->lvl = get_indent_buf(buf, lnum) / buf->b_p_sw;
3028+
flp->lvl = get_indent_buf(buf, lnum) / get_sw_value();
30293029
if (flp->lvl > flp->wp->w_p_fdn)
30303030
{
30313031
flp->lvl = flp->wp->w_p_fdn;

src/misc1.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,9 +1389,11 @@ open_line(dir, flags, second_line_indent)
13891389
#ifdef FEAT_SMARTINDENT
13901390
if (did_si)
13911391
{
1392+
int sw = (int)get_sw_value();
1393+
13921394
if (p_sr)
1393-
newindent -= newindent % (int)curbuf->b_p_sw;
1394-
newindent += (int)curbuf->b_p_sw;
1395+
newindent -= newindent % sw;
1396+
newindent += sw;
13951397
}
13961398
#endif
13971399
/* Copy the indent */
@@ -6461,11 +6463,14 @@ find_last_paren(l, start, end)
64616463
int
64626464
get_c_indent()
64636465
{
6466+
int sw = (int)get_sw_value();
6467+
64646468
/*
64656469
* spaces from a block's opening brace the prevailing indent for that
64666470
* block should be
64676471
*/
6468-
int ind_level = curbuf->b_p_sw;
6472+
6473+
int ind_level = sw;
64696474

64706475
/*
64716476
* spaces from the edge of the line an open brace that's at the end of a
@@ -6512,12 +6517,12 @@ get_c_indent()
65126517
/*
65136518
* spaces from the switch() indent a "case xx" label should be located
65146519
*/
6515-
int ind_case = curbuf->b_p_sw;
6520+
int ind_case = sw;
65166521

65176522
/*
65186523
* spaces from the "case xx:" code after a switch() should be located
65196524
*/
6520-
int ind_case_code = curbuf->b_p_sw;
6525+
int ind_case_code = sw;
65216526

65226527
/*
65236528
* lineup break at end of case in switch() with case label
@@ -6528,45 +6533,45 @@ get_c_indent()
65286533
* spaces from the class declaration indent a scope declaration label
65296534
* should be located
65306535
*/
6531-
int ind_scopedecl = curbuf->b_p_sw;
6536+
int ind_scopedecl = sw;
65326537

65336538
/*
65346539
* spaces from the scope declaration label code should be located
65356540
*/
6536-
int ind_scopedecl_code = curbuf->b_p_sw;
6541+
int ind_scopedecl_code = sw;
65376542

65386543
/*
65396544
* amount K&R-style parameters should be indented
65406545
*/
6541-
int ind_param = curbuf->b_p_sw;
6546+
int ind_param = sw;
65426547

65436548
/*
65446549
* amount a function type spec should be indented
65456550
*/
6546-
int ind_func_type = curbuf->b_p_sw;
6551+
int ind_func_type = sw;
65476552

65486553
/*
65496554
* amount a cpp base class declaration or constructor initialization
65506555
* should be indented
65516556
*/
6552-
int ind_cpp_baseclass = curbuf->b_p_sw;
6557+
int ind_cpp_baseclass = sw;
65536558

65546559
/*
65556560
* additional spaces beyond the prevailing indent a continuation line
65566561
* should be located
65576562
*/
6558-
int ind_continuation = curbuf->b_p_sw;
6563+
int ind_continuation = sw;
65596564

65606565
/*
65616566
* spaces from the indent of the line with an unclosed parentheses
65626567
*/
6563-
int ind_unclosed = curbuf->b_p_sw * 2;
6568+
int ind_unclosed = sw * 2;
65646569

65656570
/*
65666571
* spaces from the indent of the line with an unclosed parentheses, which
65676572
* itself is also unclosed
65686573
*/
6569-
int ind_unclosed2 = curbuf->b_p_sw;
6574+
int ind_unclosed2 = sw;
65706575

65716576
/*
65726577
* suppress ignoring spaces from the indent of a line starting with an
@@ -6719,12 +6724,12 @@ get_c_indent()
67196724
if (*options == 's') /* "2s" means two times 'shiftwidth' */
67206725
{
67216726
if (options == digits)
6722-
n = curbuf->b_p_sw; /* just "s" is one 'shiftwidth' */
6727+
n = sw; /* just "s" is one 'shiftwidth' */
67236728
else
67246729
{
6725-
n *= curbuf->b_p_sw;
6730+
n *= sw;
67266731
if (divider)
6727-
n += (curbuf->b_p_sw * fraction + divider / 2) / divider;
6732+
n += (sw * fraction + divider / 2) / divider;
67286733
}
67296734
++options;
67306735
}

src/ops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ shift_line(left, round, amount, call_changed_bytes)
332332
{
333333
int count;
334334
int i, j;
335-
int p_sw = (int)curbuf->b_p_sw;
335+
int p_sw = (int)get_sw_value();
336336

337337
count = get_indent(); /* get current indent */
338338

@@ -388,7 +388,7 @@ shift_block(oap, amount)
388388
int total;
389389
char_u *newp, *oldp;
390390
int oldcol = curwin->w_cursor.col;
391-
int p_sw = (int)curbuf->b_p_sw;
391+
int p_sw = (int)get_sw_value();
392392
int p_ts = (int)curbuf->b_p_ts;
393393
struct block_def bd;
394394
int incr;

src/option.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8125,7 +8125,7 @@ set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
81258125
need_mouse_correct = TRUE;
81268126
#endif
81278127

8128-
if (curbuf->b_p_sw <= 0)
8128+
if (curbuf->b_p_sw < 0)
81298129
{
81308130
errmsg = e_positive;
81318131
curbuf->b_p_sw = curbuf->b_p_ts;
@@ -11419,3 +11419,13 @@ check_ff_value(p)
1141911419
{
1142011420
return check_opt_strings(p, p_ff_values, FALSE);
1142111421
}
11422+
11423+
/*
11424+
* Return the effective shiftwidth value for current buffer, using the
11425+
* 'tabstop' value when 'shiftwidth' is zero.
11426+
*/
11427+
long
11428+
get_sw_value()
11429+
{
11430+
return curbuf->b_p_sw ? curbuf->b_p_sw : curbuf->b_p_ts;
11431+
}

src/proto/option.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ int can_bs __ARGS((int what));
5656
void save_file_ff __ARGS((buf_T *buf));
5757
int file_ff_differs __ARGS((buf_T *buf, int ignore_empty));
5858
int check_ff_value __ARGS((char_u *p));
59+
long get_sw_value __ARGS((void));
5960
/* vim: set ft=c : */

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,8 @@ static char *(features[]) =
714714

715715
static int included_patches[] =
716716
{ /* Add new patch number below this line */
717+
/**/
718+
629,
717719
/**/
718720
628,
719721
/**/

0 commit comments

Comments
 (0)