ciaranm / detectindent

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

Ignore indentation for shiftwidth in comment blocks (phpdoc style) #3

Closed blueyed closed 13 years ago

blueyed commented 13 years ago

The following code should not set shiftwidth=1, based on the indentation of the multiline doc block, but only consider the "outer" level of the doc block.

<?php
/**
 * foo
 */

function foo() {
  bar();
}

Looking at the syntax of this block (on line 3) shows: group: phpComment->Comment guifg=244(244) guibg=-1(-1)

(via SyntaxAttr script, https://github.com/vim-scripts/SyntaxAttr.vim)

ciaranm commented 13 years ago

I'm deliberately not using syntax things for this. I think this is one of those cases where your code is too complicated for a program to be able to guess the correct settings.

blueyed commented 13 years ago

I see. The syntax thing was just an idea, after having seen https://github.com/ciaranm/detectindent/commit/d8e0426c4ecde626b51169a4e7725b5a87984146

Going another route, it should not assume shiftwidth=1 given that the other block uses a value of 2. Either it should not set it at all (because there's no clear answer), or use the more likely case (but that would be guess work).

Would you accept a pull request where the syntax information gets used instead of manually detecting comments?

ciaranm commented 13 years ago

The problem with using syntax is that there's a huge amount of variety in how things are treated between all those different languages. Although using syntax will avoid having to explicitly list a few things for a few languages, it will very likely screw up a lot more than it fixes. The way it's done now works for most languages, and for those that it doesn't we can add in extra tweaks.

2 is a multiple of 1, so it's entirely reasonable to assume that 1's a good shiftwidth there.