pangloss / vim-javascript

Vastly improved Javascript indentation and syntax support in Vim.
http://www.vim.org/scripts/script.php?script_id=4452
3.8k stars 358 forks source link

Chained methods are indented #514

Closed jeremija closed 8 years ago

jeremija commented 8 years ago

Hi there,

It looks like PR #385 broke the way I'm used to write chained function calls:

db.fetch()
.then(doSomething)
.then(doSomethingElse);

Instead, it's now forcing an indent:

db.fetch()
    .then(doSomething)
    .then(doSomethingElse);

Is there an easy way to bring back the old behavior without checking out an old commit before the PR?

Thanks!

bounceme commented 8 years ago

https://github.com/pangloss/vim-javascript/issues/467

cireric commented 8 years ago

HI, I also have this problem current (master & develop) when I write React component

<Abc className="xxx" data={this.props.data}>
    <Def 
      className="yay"
    />
</Abc>

instead, when indent Component property, it will be

<Abc className="xxx" data={this.props.data}>
<Def
className="yay" />
</Abc>

when I use 8c56957, it no problem

amadeus commented 8 years ago

This should all be fixed in develop

bounceme commented 8 years ago

566

JetFault commented 8 years ago

What config options needs to be set to not indent chained funcitons?

bounceme commented 8 years ago

https://github.com/pangloss/vim-javascript#indentation-specific . though see if the behaviour on develop is preferable for you first (there were some small changes with operators)

tribou commented 8 years ago

For anyone searching and finding this issue, I was able to disable indenting chained methods with this new config variable:

let g:javascript_opfirst = 1
bounceme commented 8 years ago

the reason i removed the documentation for them^^. probably a better idea to change that to '' unless you want to indent when a line starts with 1

tribou commented 8 years ago

@bounceme I tried using let g:javascript_opfirst = '', but it caused the indentation to continue.

bounceme commented 8 years ago

true, that is a terrible suggestion, '' matches everything.

bounceme commented 8 years ago

Anyway, this issue is about chained functions, so suggesting a change to an option which removes indenting for all operators isn't helpful.

bounceme commented 8 years ago

just to clarify, this is a regex option

tribou commented 8 years ago

Ah ok, thank you for clarifying. In that case, which indentation option would apply to chained functions? When I check the help from the link above, the cino-: section references switch statements.

bounceme commented 8 years ago

I removed the options from the readme as they are very complicated to get right. just remove the dots in these regexes https://github.com/pangloss/vim-javascript/blob/develop/indent/javascript.vim#L70

tribou commented 8 years ago

Thanks for your patience with this issue. I tried removing the dots by setting these in my .vimrc:

let g:javascript_opfirst = '\%([<>,?^%|*&]\|\/[^/*]\|\([-:+]\)\1\@!\|=>\@!\|in\%(stanceof\)\=\>\)'
let g:javascript_continuation = '\%([<=,?/*^%|&:]\|+\@<!+\|-\@<!-\|=\@<!>\|\<in\%(stanceof\)\=\)'

However, it's still indenting chained functions.

bounceme commented 8 years ago

those work for me, maybe a issue with your vimrc?