Skip to content

Consolidate applying indent settings #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

idbrii
Copy link
Contributor

@idbrii idbrii commented Mar 9, 2015

Move applying indent settings into a single function to ensure we set them consistently.

Currently, there's some variance between which settings are applied. This ensures we always set values consistently. I'm trying to make us follow the guidelines in :help tabstop.

This PR changes behavior to set expandtab when we find both tabs and spaces. That case sets tabstop after calling SetIndent which is a bit weird, but presumably the guessing behavior is more useful than forcing tabstop=8.

Also, set softtabstop=-1 on supported versions of vim.

idbrii added 3 commits March 9, 2015 13:15
Add s:SetIndent() so we can set our desired indentation consistently. It
always sets expandtab and sets widths only if valid (positive nonzero).

I'm following the advice laid out on the 'tabstop' help about when
softtabstop is set and ensuring some settings have the same value.

That documentation recommends using softtabstop with noexpandtab and not
with expandtab. (Whereas detectindent used to do the opposite.)

TODO: I'm no longer convinced that my reading is correct in this case
since softtabstop isn't useful when tabstop and shiftwidth are the same.
Maybe I should always set it?
shiftwidth=0 keeps it in sync with tabstop, but that breaks many
indentation plugins that read 'sw' instead of calling the new
shiftwidth().

See tpope/vim-sleuth#25

Or try indenting this vimscript file on Vim 7.4.
Always set softtabstop. This is more consistent with previous behavior
and from reading the softtabstop help seems to make more sense that we
set all of these values to the same thing.

In the case where we find both tabs and spaces, now we set expandtab as
described in ciaranm#2:

	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.

Alternatively, we could follow ciaranm#1 and set tabstop=8 (instead of
guessing) and use noexpandtab:

	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.

That's what vim-sleuth does, so why copy their recipe? Guessing is
probably more useful to users.
Default detectindent_preferred_indent behavior (0) is to retain current
tabstop. But on a file containing only tabs, and user's default is to
use shiftwidth=4, we end up with

    softtabstop=4, shiftwidth=4, tabstop=8, noexpandtabs

Which means we insert tabs, but indent with >> inserts only half a tab
(inserting 4 spaces). This madness occurs in python files containing
tabs with g:python_recommended_style undefined or 1.
@idbrii
Copy link
Contributor Author

idbrii commented Jan 22, 2020

I found a bug with tabs-only files and added the fix to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant