Skip to content
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

Feature request: Disable for specific filetypes #29

Closed
lutzky opened this issue Jun 2, 2015 · 11 comments
Closed

Feature request: Disable for specific filetypes #29

lutzky opened this issue Jun 2, 2015 · 11 comments

Comments

@lutzky
Copy link

lutzky commented Jun 2, 2015

My preferences for go (golang) files don't always mesh well with this plugin, which I otherwise really like. See #28 for a concrete example. It could be nice to be able to do something like this:

let g:vim_sleuth_exclude_languages = "go"
@dbarnett
Copy link

dbarnett commented Jun 2, 2015

Does it try to auto-detect settings even when you've explicitly configured them for the filetype?

@tpope
Copy link
Owner

tpope commented Jun 2, 2015

The idea is that autocmd FileType go set sw=2 should override sleuth.vim. Though it might be possible to break it if you order things weird in your vimrc.

@lutzky
Copy link
Author

lutzky commented Jun 7, 2015

Okay, more analysis: Vim versions 7.4.488 and 7.4.622 exhibit identical behaviors with the following minimal .vimrc:

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
"Plugin 'tpope/vim-sleuth'
call vundle#end()
filetype plugin indent on
au FileType go set ts=2 sw=2

This form (sleuth disabled) works correctly, with ts=2 and the file described in #28 looking right. When uncommenting line 4 (sleuth enabled), ts=8, ignoring my setting. Moving the filetype lines around the file doesn't seem to have any effect.

lutzky added a commit to lutzky/vim-sleuth that referenced this issue Jun 7, 2015
@dbarnett
Copy link

dbarnett commented Jun 7, 2015

Yeah, there's no mystery why vim-sleuth overrides your custom settings. It registers an autocmd in plugin/sleuth.vim, after your vimrc executes, so the autocmd will fire late and override other autocmds. The question is whether there's anything vim-sleuth can do to give precedence to other plugins.

If there's nothing automatic, maybe a convention of setting b:options_applied to disable sleuth's detection fallback would work:

au Filetype go set ts=2 sw=2 | let b:options_applied = 1

@tpope
Copy link
Owner

tpope commented Jun 7, 2015

I could have sworn that I had this working, but you're right, the sleuth autocommand is defined later and will always win over the vimrc.

One thing you could do is stick your overrides in after/plugin/sleuth.vim, or define them from within a VimEnter autocommand.

au VimEnter * au indent_override FileType go set ts=2 sw=2

You could also explicitly runtime! plugin/sleuth.vim before defining your autocommands.

These are all crude hacks, but I think they are better than b:options_applied, which will stick around even if you change file types.

@dbarnett
Copy link

dbarnett commented Dec 3, 2015

I ran into this again and added this to my vimrc as a workaround:

VAMActivate sleuth
" Workaround for https://github.com/tpope/vim-sleuth/issues/29.                
" Define autocmd as early as possible so other autocmds can override.          
runtime! plugin/sleuth.vim

The VimEnter option is much less flexible because it forces you to repeat your explicit configuration values inline. It's not an option if you want to give other filetype plugins control over indent settings instead of hard-coding your own.

I'd really appreciate a fix that could get vim-sleuth to have the right precedence out of the box, though. =)

@ewilliam
Copy link

vim-sleuth struggles with mail. takes forever for vim to open within mutt (goes away when i remove plugin), so +1 for exclude ft support

@anntzer
Copy link
Contributor

anntzer commented Jul 27, 2017

A similar issue occurs with rst.vim, which uses 3-space indents (see marshallward/vim-restructuredtext#8 for rationale); but if you have item lists à la

- foo bar this is a loooooong
  line
- and so on

then vim-sleuth will set a 2-space indent.

I'm not sure whether the autocommand ordering would make the following work, but perhaps(?) sleuth_automatic could be made a buffer-local variable, so that one could set b:sleuth_automatic to 0 in ~/.vim/ftplugin/foo.vim?

@alecdwm
Copy link

alecdwm commented Mar 16, 2018

This would also be a great workaround for #43

@tpope
Copy link
Owner

tpope commented Mar 16, 2018

Merged #44 which should provide for this. I also limited it to 20 neighbor files before giving up, which I have a hunch is what was causing the mail slowdown.

@tpope tpope closed this as completed Mar 16, 2018
tpope added a commit that referenced this issue Mar 18, 2022
@tpope
Copy link
Owner

tpope commented Mar 18, 2022

I've added options to opt-out of heuristic detection on a per-filetype basis:

let g:sleuth_mail_heuristics = 0

There's also g:sleuth_heuristics to change it from opt-out to opt-in.

This is a bit less flexible than a buffer-local option, but easier to use and not subject to autocommand ordering issues, so I am deprecating b:sleuth_automatic and maybe the global version too, unless someone gives me a good reason not to.

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

No branches or pull requests

6 participants