Hi So8res!

On Di, 02 Okt 2012, So8res wrote:

> Recently a patch went in such that if shiftwidth is zero then the value of 
> tabstop is used:
> 
> https://groups.google.com/forum/?fromgroups=#!searchin/vim_dev/shiftwidth=0/vim_dev/5Pq0B7dXGGA
> 
> I like that feature a lot.
> 
> It would be very nice to have a similar feature for softtabstop. 
> Unfortunately, setting softtabstop=0 disables the softtabstop feature, so 0 
> might not work here. I propose either:
> 
> * Change softtabstop so that 0 sets it equal to tabstop and a negative number 
> turns it of
> * Make it so 0 turns it off and a negative number makes it equal to tabstop
> 
> Justification: To quote from the tabstop help,
> 
>       There are four main ways to use tabs in Vim:
>       1. Always keep 'tabstop' at 8, set 'softtabstop' and 'shiftwidth' to 4
>          (or 3 or whatever you prefer) and use 'noexpandtab'.  Then Vim
>          will use a mix of tabs and spaces, but typing <Tab> and <BS> will
>          behave like a tab appears every 4 (or 3) characters.
>       2. Set 'tabstop' and 'shiftwidth' to whatever you prefer and use
>          'expandtab'.  This way you will always insert spaces.  The
>          formatting will never be messed up when 'tabstop' is changed.
>       3. Set 'tabstop' and 'shiftwidth' to whatever you prefer and use a
>          |modeline| to set these values when editing the file again.  Only
>          works when using Vim to edit the file.
>       4. Always set 'tabstop' and 'shiftwidth' to the same value, and
>          'noexpandtab'.  This should then work (for initial indents only)
>          for any tabstop setting that people use.  It might be nice to have
>          tabs after the first non-blank inserted as spaces if you do this
>          though.  Otherwise aligned comments will be wrong when 'tabstop' is
>          changed.
> 
> 
> I'm a big proponent of #4. #1 mixes tabs and spaces at the top level which I 
> find abhorrent. #2 removes the reader's ability to adjust the tabstop to 
> their comfort level and have the code comply. #3 requires modelines don't 
> work well for people using other editors and can have security concerns.
> 
> If you use #4 then it's helpful to change <tab> (as suggested) to insert 
> spaces after the first non-blank. At this point you pretty much always want 
> tabstop, shiftwidth, and softtabstop to *always* be equal to each other. It 
> gets annoying to have to "set ts=N sw=N sts=N" or whatever when you want to 
> change the width of tabs to N.
> 
> The above mentioned patch allows you to "set sw=0" once and then you need 
> only "set ts=N sts=N" when you're changing your indent level, but that's 
> still repetitive. I would love a patch that allows me to "set sw=0 sts=0" or 
> something in my vimrc and then only ever touch tabstop thereafter.

Could you try the attached patch? (use sts=-1 to set it to the 'ts' value)

Mit freundlichen Grüßen
Christian

-- 
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
@@ -6383,6 +6383,7 @@
 	of 8, while being able to edit like it is set to 'sts'.  However,
 	commands like "x" still work on the actual characters.
 	When 'sts' is zero, this feature is off.
+	When 'sts' is negative, the value of 'ts' is used.
 	'softtabstop' is set to 0 when the 'paste' option is set.
 	See also |ins-expandtab|.  When 'expandtab' is not set, the number of
 	spaces is minimized by using <Tab>s.
diff --git a/src/edit.c b/src/edit.c
--- a/src/edit.c
+++ b/src/edit.c
@@ -8885,7 +8885,7 @@
 	 */
 	if (	   mode == BACKSPACE_CHAR
 		&& ((p_sta && in_indent)
-		    || (curbuf->b_p_sts != 0
+		    || (get_sts_value() != 0
 			&& curwin->w_cursor.col > 0
 			&& (*(ml_get_cursor() - 1) == TAB
 			    || (*(ml_get_cursor() - 1) == ' '
@@ -8901,7 +8901,7 @@
 	    if (p_sta && in_indent)
 		ts = (int)get_sw_value();
 	    else
-		ts = (int)curbuf->b_p_sts;
+		ts = (int)get_sts_value();
 	    /* 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. */
@@ -9590,7 +9590,7 @@
      */
     if (!curbuf->b_p_et
 	    && !(p_sta && ind && curbuf->b_p_ts != get_sw_value())
-	    && curbuf->b_p_sts == 0)
+	    && get_sts_value() == 0)
 	return TRUE;
 
     if (stop_arrow() == FAIL)
@@ -9606,8 +9606,8 @@
 
     if (p_sta && ind)		/* insert tab in indent, use 'shiftwidth' */
 	temp = (int)get_sw_value();
-    else if (curbuf->b_p_sts > 0) /* use 'softtabstop' when set */
-	temp = (int)curbuf->b_p_sts;
+    else if (curbuf->b_p_sts != 0) /* use 'softtabstop' when set */
+	temp = (int)get_sts_value();
     else			/* otherwise use 'tabstop' */
 	temp = (int)curbuf->b_p_ts;
     temp -= get_nolist_virtcol() % temp;
@@ -9635,7 +9635,7 @@
     /*
      * When 'expandtab' not set: Replace spaces by TABs where possible.
      */
-    if (!curbuf->b_p_et && (curbuf->b_p_sts || (p_sta && ind)))
+    if (!curbuf->b_p_et && (get_sts_value() || (p_sta && ind)))
     {
 	char_u		*ptr;
 #ifdef FEAT_VREPLACE
diff --git a/src/option.c b/src/option.c
--- a/src/option.c
+++ b/src/option.c
@@ -8509,11 +8509,6 @@
 	    p_window = Rows - 1;
     }
 
-    if (curbuf->b_p_sts < 0)
-    {
-	errmsg = e_positive;
-	curbuf->b_p_sts = 0;
-    }
     if (curbuf->b_p_ts <= 0)
     {
 	errmsg = e_positive;
@@ -11429,3 +11424,13 @@
 {
     return curbuf->b_p_sw ? curbuf->b_p_sw : curbuf->b_p_ts;
 }
+
+/*
+ * Return the effective softtabstop value for current buffer, using the
+ * 'tabstop' value when 'softtabstop' is zero.
+ */
+    long
+get_sts_value()
+{
+    return curbuf->b_p_sts < 0 ? curbuf->b_p_ts : curbuf->b_p_sts;
+}
diff --git a/src/proto/option.pro b/src/proto/option.pro
--- a/src/proto/option.pro
+++ b/src/proto/option.pro
@@ -57,4 +57,5 @@
 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));
+long get_sts_value __ARGS((void));
 /* vim: set ft=c : */

Raspunde prin e-mail lui