Hi Bram!

On Mi, 08 Aug 2012, Bram Moolenaar wrote:

> I think we should have a function get_sw_value();  Calling a function
> without arguments is efficient, no need to have this code in many
> places.  It appears curbuf is used in all cases.
> 
> Can you also make a patch for the help?

[X] Attached

regards,
Christian
-- 
Ich sage wenig, denke desto mehr.

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -6119,6 +6119,7 @@
 			local to buffer
 	Number of spaces to use for each step of (auto)indent.  Used for
 	|'cindent'|, |>>|, |<<|, etc.
+	If set to zero, the 'ts' setting will be used.
 
 						*'shortmess'* *'shm'*
 'shortmess' 'shm'	string	(Vim default "filnxtToO", Vi default: "",
diff --git a/src/edit.c b/src/edit.c
--- a/src/edit.c
+++ b/src/edit.c
@@ -8896,10 +8896,11 @@
 	    colnr_T	vcol;
 	    colnr_T	want_vcol;
 	    colnr_T	start_vcol;
+	    long        sw = get_sw_value();
 
 	    *inserted_space_p = FALSE;
 	    if (p_sta && in_indent)
-		ts = curbuf->b_p_sw;
+		ts = sw;
 	    else
 		ts = curbuf->b_p_sts;
 	    /* Compute the virtual column where we want to be.  Since
@@ -9573,6 +9574,7 @@
     int		ind;
     int		i;
     int		temp;
+    long	sw = get_sw_value();
 
     if (Insstart_blank_vcol == MAXCOL && curwin->w_cursor.lnum == Insstart.lnum)
 	Insstart_blank_vcol = get_nolist_virtcol();
@@ -9605,7 +9607,7 @@
     AppendToRedobuff((char_u *)"\t");
 
     if (p_sta && ind)		/* insert tab in indent, use 'shiftwidth' */
-	temp = (int)curbuf->b_p_sw;
+	temp = (int)sw;
     else if (curbuf->b_p_sts > 0) /* use 'softtabstop' when set */
 	temp = (int)curbuf->b_p_sts;
     else			/* otherwise use 'tabstop' */
diff --git a/src/ex_getln.c b/src/ex_getln.c
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -2268,10 +2268,13 @@
 
 	    if (c1 == Ctrl_T)
 	    {
+		long        sw;
+		sw = get_sw_value();
+
 		p = (char_u *)line_ga.ga_data;
 		p[line_ga.ga_len] = NUL;
 		indent = get_indent_str(p, 8);
-		indent += curbuf->b_p_sw - indent % curbuf->b_p_sw;
+		indent += sw - indent % sw;
 add_indent:
 		while (get_indent_str(p, 8) < indent)
 		{
@@ -2320,10 +2323,12 @@
 		}
 		else
 		{
+		    long        sw = get_sw_value();
+
 		    p[line_ga.ga_len] = NUL;
 		    indent = get_indent_str(p, 8);
 		    --indent;
-		    indent -= indent % curbuf->b_p_sw;
+		    indent -= indent % sw;
 		}
 		while (get_indent_str(p, 8) > indent)
 		{
diff --git a/src/fold.c b/src/fold.c
--- a/src/fold.c
+++ b/src/fold.c
@@ -3010,6 +3010,7 @@
     char_u	*s;
     buf_T	*buf;
     linenr_T	lnum = flp->lnum + flp->off;
+    long	sw = get_sw_value();
 
     buf = flp->wp->w_buffer;
     s = skipwhite(ml_get_buf(buf, lnum, FALSE));
@@ -3025,7 +3026,7 @@
 	    flp->lvl = -1;
     }
     else
-	flp->lvl = get_indent_buf(buf, lnum) / buf->b_p_sw;
+	flp->lvl = get_indent_buf(buf, lnum) / sw;
     if (flp->lvl > flp->wp->w_p_fdn)
     {
 	flp->lvl = flp->wp->w_p_fdn;
diff --git a/src/misc1.c b/src/misc1.c
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -1389,9 +1389,11 @@
 #ifdef FEAT_SMARTINDENT
 	if (did_si)
 	{
+	    long        sw = get_sw_value();
+
 	    if (p_sr)
-		newindent -= newindent % (int)curbuf->b_p_sw;
-	    newindent += (int)curbuf->b_p_sw;
+		newindent -= newindent % (int)sw;
+	    newindent += (int)sw;
 	}
 #endif
 	/* Copy the indent */
@@ -6461,11 +6463,13 @@
     int
 get_c_indent()
 {
+    int sw = (int)get_sw_value();
     /*
      * spaces from a block's opening brace the prevailing indent for that
      * block should be
      */
-    int ind_level = curbuf->b_p_sw;
+
+    int ind_level = sw;
 
     /*
      * spaces from the edge of the line an open brace that's at the end of a
@@ -6512,12 +6516,12 @@
     /*
      * spaces from the switch() indent a "case xx" label should be located
      */
-    int ind_case = curbuf->b_p_sw;
+    int ind_case = sw;
 
     /*
      * spaces from the "case xx:" code after a switch() should be located
      */
-    int ind_case_code = curbuf->b_p_sw;
+    int ind_case_code = sw;
 
     /*
      * lineup break at end of case in switch() with case label
@@ -6528,45 +6532,45 @@
      * spaces from the class declaration indent a scope declaration label
      * should be located
      */
-    int ind_scopedecl = curbuf->b_p_sw;
+    int ind_scopedecl = sw;
 
     /*
      * spaces from the scope declaration label code should be located
      */
-    int ind_scopedecl_code = curbuf->b_p_sw;
+    int ind_scopedecl_code = sw;
 
     /*
      * amount K&R-style parameters should be indented
      */
-    int ind_param = curbuf->b_p_sw;
+    int ind_param = sw;
 
     /*
      * amount a function type spec should be indented
      */
-    int ind_func_type = curbuf->b_p_sw;
+    int ind_func_type = sw;
 
     /*
      * amount a cpp base class declaration or constructor initialization
      * should be indented
      */
-    int ind_cpp_baseclass = curbuf->b_p_sw;
+    int ind_cpp_baseclass = sw;
 
     /*
      * additional spaces beyond the prevailing indent a continuation line
      * should be located
      */
-    int ind_continuation = curbuf->b_p_sw;
+    int ind_continuation = sw;
 
     /*
      * spaces from the indent of the line with an unclosed parentheses
      */
-    int ind_unclosed = curbuf->b_p_sw * 2;
+    int ind_unclosed = sw * 2;
 
     /*
      * spaces from the indent of the line with an unclosed parentheses, which
      * itself is also unclosed
      */
-    int ind_unclosed2 = curbuf->b_p_sw;
+    int ind_unclosed2 = sw;
 
     /*
      * suppress ignoring spaces from the indent of a line starting with an
@@ -6719,12 +6723,12 @@
 	if (*options == 's')	    /* "2s" means two times 'shiftwidth' */
 	{
 	    if (options == digits)
-		n = curbuf->b_p_sw;	/* just "s" is one 'shiftwidth' */
+		n = sw;	/* just "s" is one 'shiftwidth' */
 	    else
 	    {
-		n *= curbuf->b_p_sw;
+		n *= sw;
 		if (divider)
-		    n += (curbuf->b_p_sw * fraction + divider / 2) / divider;
+		    n += (sw * fraction + divider / 2) / divider;
 	    }
 	    ++options;
 	}
diff --git a/src/ops.c b/src/ops.c
--- a/src/ops.c
+++ b/src/ops.c
@@ -332,7 +332,7 @@
 {
     int		count;
     int		i, j;
-    int		p_sw = (int)curbuf->b_p_sw;
+    int		p_sw = (int)get_sw_value();
 
     count = get_indent();	/* get current indent */
 
@@ -388,7 +388,7 @@
     int			total;
     char_u		*newp, *oldp;
     int			oldcol = curwin->w_cursor.col;
-    int			p_sw = (int)curbuf->b_p_sw;
+    int			p_sw = (int)get_sw_value();
     int			p_ts = (int)curbuf->b_p_ts;
     struct block_def	bd;
     int			incr;
diff --git a/src/option.c b/src/option.c
--- a/src/option.c
+++ b/src/option.c
@@ -8125,7 +8125,7 @@
     need_mouse_correct = TRUE;
 #endif
 
-    if (curbuf->b_p_sw <= 0)
+    if (curbuf->b_p_sw < 0)
     {
 	errmsg = e_positive;
 	curbuf->b_p_sw = curbuf->b_p_ts;
@@ -11419,3 +11419,12 @@
 {
     return check_opt_strings(p, p_ff_values, FALSE);
 }
+
+/*
+ * return correct shiftwidth size for current buffer
+ */
+    long
+get_sw_value()
+{
+    return curbuf->b_p_sw ? curbuf->b_p_sw : curbuf->b_p_ts;
+}
diff --git a/src/proto/option.pro b/src/proto/option.pro
--- a/src/proto/option.pro
+++ b/src/proto/option.pro
@@ -56,4 +56,5 @@
 void save_file_ff __ARGS((buf_T *buf));
 int file_ff_differs __ARGS((buf_T *buf, int ignore_empty));
 int check_ff_value __ARGS((char_u *p));
+long get_sw_value __ARGS((void));
 /* vim: set ft=c : */

Raspunde prin e-mail lui