tpope / vim-sleuth

sleuth.vim: Heuristically set buffer options
https://www.vim.org/scripts/script.php?script_id=4375
1.92k stars 86 forks source link

Why does this plugin enforce `:filetype indent on`? #31

Closed lydell closed 7 years ago

lydell commented 8 years ago

I’ve been running vim-sleuth with this patch all day:

diff --git a/plugin/sleuth.vim b/plugin/sleuth.vim
index 560135e..9d25d03 100644
--- a/plugin/sleuth.vim
+++ b/plugin/sleuth.vim
@@ -159,9 +159,9 @@ endfunction

 setglobal smarttab

-if !exists('g:did_indent_on')
-  filetype indent on
-endif
+" if !exists('g:did_indent_on')
+"   filetype indent on
+" endif

 augroup sleuth
   autocmd!

It has detected the indentatition of all files I’ve worked with perfectly.

I want :filetype indent off.

Here are three alternate suggestions:

  1. Get rid of the :filetype indent on enforcement.
  2. Make it configurable via a variable, say g:sleuth_enforce_filetype_indent_on.
  3. Enlighten me why it’s needed and I’ll go maintain my own fork or something :)

Thanks for the best indentation detector I’ve come across so far!

lydell commented 8 years ago

A hack (IMO) is to put let g:did_indent_on = 0 after filetype indent off (because filetype indent off unlets that variable) in your .vimrc. That causes vim-sleuth not to run filetype indent on. However, I'm not sure what side effects this hack may have, considering that the variable is only supposed to exist when filetype indent on is used. (As an attempt to reduce such side effects, I at least set the variable to a falsy value. Perhaps that helps, perhaps it makes things worse.)

So there is a hacky solution. But I'm still curious why vim-sleuth has this behavior which is seemingly unneeded and unrelated to the plugin's functionality. :)

AWhetter commented 7 years ago

I am also having troubles with this where commit b6347df73719dea0fb14695eae4d3506ebc4a36c has broken compatibility with vim-python-pep8-indent because sleuth is restoring the options that vim-python-pep8-indent sets when turning filetype indent back on.

tpope commented 7 years ago

@lydell :filetype indent on enables the wealth of language specific indent plugins that live in the indent subdirectories that live in the runtime path. A few of those set options like 'shiftwidth' but mostly they just set 'indentexpr'. It's possible you want to disable them, I guess, in the same way you might want to disable syntax highlighting, but I think it's a weird edge case, and let g:did_indent_on = 0 is probably good enough, unless someone can point out a problem with it.

@AWhetter if I understand your assertion correctly, I think overriding those settings in vim-python-pep8-indent should usually be beneficial. I would expect it to handle pep8 confirming files the same, but make the appropriate adjustments for files that march to the beat of their own drum. Are you running into a specific problem?

AWhetter commented 7 years ago

Running :filetype indent on after sleuth is causing vim-python-pep8-indent to set tabstop, shiftwidth, and expandtab after sleuth does. Really I want :filetype indent on to run before sleuth so that I still get the indent plugin goodness, but with sleuth overriding the indent settings specific to the file.

Maybe an option to run :filetype indent on before or after sleuth would make sense. Giving you the option to have sleuth yield to an indent plugin, or have sleuth override an indent plugin.

tpope commented 7 years ago

Oh, right, now I remember the purpose of moving it.

You can work around on your end by just calling filetype indent on in your vimrc. That's just as good as an option best I can tell. I'll mull over whether we should go back to the earlier default.