ciaranm / detectindent

Vim script for automatically detecting indent settings
173 stars 48 forks source link

Make the indentation guessing much less invasive. #15

Closed ogier closed 12 years ago

ogier commented 12 years ago

In my experience this plugin gets the indentation wrong too often to be useful in its current state, and it adjusts different settings depending on what it finds. So I modified it to only ever adjust shiftwidth, softtabstop and of course expandtab, and only when it can make a reasonable guess about what's going on.

I'm not sure whether this is an appropriate pull request to actually be merged in upstream, because it does change behavior in some noticeable ways. In any case, here it is, and here's what I changed:

  1. Never set tabstop: just let the default from vimrc take priority. The only interesting case is when leading tabs and spaces are mixed, and in my experience the only sane guess in that situation is "4". This change removes the need for g:detectindent_preferred_indent
  2. Count how many times we see leading tabs vs. leading spaces, so that we can make a better guess about what the file is using. This change makes g:detectindent_preferred_expandtab just a hint as to which setting to lean towards when guessing.
  3. If we don't see any leading tabs or spaces, don't do anything. Users can set filetype defaults easily for this kind of situation anyways.
ciaranm commented 12 years ago

Sorry, I'm not a fan. If you're resorting to guesswork based upon ratios, it strongly suggests that your indenting style is screwed up and inconsistent. If that's the case, automatic detection is a lost cause.

ogier commented 12 years ago

Fair enough. In my experience, the most common time for indentation to be messed up is when someone who is less anal about whitespace than I am commits a few lines with wonky indentation. At that point, I don't want my indentation checker to suddenly switch to adjusting tabstop and using tabs or suddenly switch to adjusting softtabstop and using spaces.

It's a big change, and I can understand having different preferences, so I guess it will have to just live on as a fork.

idbrii commented 9 years ago

@ogier FYI, #20 has been merged and may provide an alternative solution to your problem: add options to use the "preferred" setting when mixed indentation is found.