tamzinblake / js3-mode

A chimeric fork of js2-mode and js-mode
GNU General Public License v3.0
181 stars 13 forks source link

immediate function invocation indentation is a bit weird #50

Closed mbriggs closed 12 years ago

mbriggs commented 12 years ago

Probably my only complaint with js3 indentation is this style of function (using 2 spaces for indentation)

(function(){
   var foo = 1,
       bar = 2
 })()

where it adds an extra space to align code against the f in function, and the closing }. it is more noticeable if you are one of the "no semicolons except on lines starting with (" hippy like me :)

;(function(){
    var foo = 1,
        bar = 2
  })()

I think ideally, it would look like this

;(function(){
  var foo = 1,
      bar = 2
})()

probably one of those things that is mind rendingly hard to implement, but I figured I would ask in the off chance that its easy :)

tamzinblake commented 12 years ago

You might get the behavior you want from setting js3-consistent-level-indent-inner-bracket t. You can do this with M-x customize-group RET js3-mode RET. This forces function bodies to always just be indented once.

I've been thinking about implementing a special case for just certain function idioms. Let me know whether js3-consistent-level-indent-inner-bracket does what you want.

tamzinblake commented 12 years ago

So far I've been erring on the side of consistency. I try to always indent from the start of whatever expression is being continued, except for obvious special cases. Currently there are some terrible compromises where it's not clear what's best, like function expressions in var statements. I can indent from the start of the variable assignment sub-expression or just one indent, and both options look weird in some special cases. I'm hoping the js3-consistent-level-indent-inner-bracket solves most people's problems, but I should probably document it somewhere.

mbriggs commented 12 years ago

js3-consistent-level-indent-inner-bracket worked for the cases above, and also for function declarations in multi expression vars, which makes me really happy :) huge fan of js3, keep up the good work