Closed umlx5h closed 4 months ago
@NMAC427
I force pushed because other PR was merged and conflicted recently, could you please consider this PR as well? This PR is related to some other Issues and PRs and may be able to close them.
If you don't like this approach, I would be happy to consider other approaches.
At least when tabs are detected, changing only the tabstop
is not enough, usually shiftwidth
must be set to 0
at the same time.
If shiftwidth
is not set to a value that matches tabstop
or to 0
, then it end up with strange indentation with the >
and <
operators.
I have written a lengthy explanation in the PR description, but the current hard-coded indentation settings are not appropriate for this reason alone. It is better to give plugin users freedom of setting.
Sorry for not getting to this earlier. These changes look very reasonable. I also really like that it also adresses #12. Thanks for the contribution!
Thanks!
Hello.
I have added an option to set any vim option when indentation is detected. Right now the options to set are hard coded, but I do not think this is appropriate from a customizability standpoint. Because vim's indentation-related settings are so complex, I thought it best to allow users to set them freely.
There are many vim users who have the tab width set to 8 or have not changed it. I do not think it is good from the user's point of view to change the 'tabstop' when spaces are detected.
For example, projects such as gcc and vim use an indentation style that mixes tabs and spaces, but only assumes that the tab width is 8. The old-fashioned GNU style seems to use this indent style. Therefore, making the tab width the same as the indent width will mess up the layout. You can see this by opening the following code in vim. (Please disable modeline in vim project) https://github.com/gcc-mirror/gcc/blob/8f8db5553935edcb4731db32279418ca37e1f094/libgomp/config/posix/sem.c#L73-L76 https://github.com/vim/vim/blob/1bf1bf569b96d2f9b28e0cce0968ffbf2fb80aac/src/alloc.c#L97-L102
Another advantage of separating 'tabstop' from 'shiftwidth' is that if a tab is mistakenly entered, it is easier to tell that it is a tab without using :set list. The same size makes it impossible to distinguish between tabs and spaces.
For example, vim-sleuth does not change it. The vim help below explains why.
I am going to define the default values as follows and change the following options.
default: 2 spaces, 8-width tab
This is advantageous from a performance standpoint because it reduces the number of options to be set as much as possible. Currently the same value is set for 'tabstop', 'softtabstop', and 'shiftwidth' when spaces are detected, but If 'softtabstop' is set to -1, there is no need to set it. or if 'tabstop' and 'softabstop' are equal, 'softtabstop' is almost no point, so it can be set to 0 or 1 instead.
BTW, The editorconfig that comes with neovim has almost the same configuration values. (The fact that 'tabstop' is also changed is a result of following the editorconfig specification.) https://github.com/neovim/neovim/blob/master/runtime/lua/editorconfig.lua#L50-L71
Also, the specific options to be set will be written in the README, which will make it easier to understand.
Default values are to be taken over from the current settings for compatibility reason.
This PR also fixes PR: #9 Issue: #12
also related PR: #14