Feature request: shiftwidth=0 to make it equal to tabstop

83 views
Skip to first unread message

Michał Górny

unread,
Aug 7, 2012, 10:34:39 AM8/7/12
to vim...@vim.org
Hello,

I am working on a C project where the coding style enforces using tab
indentation only. Thus, I would like to enforce that policy via
modeline without affecting user preferred tabstop.

In order to do that, right now I use:
// vim:noet:sts=0

Sadly, I don't think it is currently possible to reset shiftwidth to
the value of tabstop. Thus, a user having 'ts=8:sw=4' in his
preferences will still be inserting spaces.

Thus, I'd like to request the following feature: option to reset
the shiftwidth to the value of tabstop. Practically, it could be
implemented by allowing 'sw=0' (much like 'sts=0'), and using the value
of 'ts' in that case.

Right now, setting 'sw=0' is prohibited so I don't think this would
introduce any compatibility problems. Of course, the 'sw=0' will be
useful only in modelines for newer vim versions.

--
Best regards,
Michał Górny
signature.asc

Christian J. Robinson

unread,
Aug 7, 2012, 1:41:19 PM8/7/12
to vim...@googlegroups.com, vim...@vim.org
On Tue, 7 Aug 2012, Michał Górny wrote:

> Thus, I'd like to request the following feature: option to reset
> the shiftwidth to the value of tabstop. Practically, it could be
> implemented by allowing 'sw=0' (much like 'sts=0'), and using the
> value of 'ts' in that case.

For me, this is one of those "why didn't someone think of this
sooner!" type of things. I wholeheartedly support this idea.

- Christian

--
Sushido, n.: The way of the tuna.
Christian J. Robinson <hep...@gmail.com> http://christianrobinson.name/

Christian Brabandt

unread,
Aug 7, 2012, 3:09:05 PM8/7/12
to vim...@vim.org
Hi Michał!
Actually, I think, although Vim complains, It already sets 'sw' to the
current value of 'ts', if 'sw' is less than 1.


,----[ option.c ]-
| [...]
| if (curbuf->b_p_sw <= 0)
| {
| errmsg = e_positive;
| curbuf->b_p_sw = curbuf->b_p_ts;
| }
| [...]
`----

But anyhow, here is a patch, which should do what you want. Let's see,
what Bram thinks.

regards,
Christian
--
Es gibt keinen größeren Hochmut als den der Fachleute.
-- Thornton Niven Wilder
shiftwidth_defaults_to_tabstop.diff

Bram Moolenaar

unread,
Aug 8, 2012, 8:12:43 AM8/8/12
to Christian Brabandt, vim...@vim.org
I think the idea to have 'sw' set to zero behave like it's set to 'ts'
makes a lot of sense.

In your patch you have an awful lot of:

sw = curbuf->b_p_sw ? curbuf->b_p_sw : curbuf->b_p_ts;

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?

--
hundred-and-one symptoms of being an internet addict:
219. Your spouse has his or her lawyer deliver the divorce papers...
via e-mail.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Christian Brabandt

unread,
Aug 8, 2012, 10:37:11 AM8/8/12
to vim...@vim.org
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.
shiftwidth_defaults_to_tabstop.diff

Bram Moolenaar

unread,
Aug 8, 2012, 11:46:36 AM8/8/12
to Christian Brabandt, vim...@vim.org

Christian Brabandt wrote:

> 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

That was quick! There are a few "sw" variables I think we don't need,
otherwise it looks fine.


--
hundred-and-one symptoms of being an internet addict:
227. You sleep next to your monitor. Or on top of it.
Reply all
Reply to author
Forward
0 new messages