tamzinblake / js3-mode

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

function argument in call with return value being assigned #59

Closed daaku closed 12 years ago

daaku commented 12 years ago

I think based on the intended goals this is not as expected:

var interval = setInterval(function() {
                 var foo = 1;
               });

Instead it should be:

var interval = setInterval(function() {
  var foo = 1;
});
tamzinblake commented 12 years ago

Hmm... that's a bug, though a very odd one - that should have been a solved special case by now, but it's easily reproducible.

Depending on configuration, the correct behavior is either:

var interval = setInterval(function() {
                             var foo = 1;
                          });

OR:


var interval = setInterval(function() {
       var foo = 1;
    });

OR

var interval = setInterval(function() {
  var foo = 1;
});
tamzinblake commented 12 years ago

Nevermind, that's the default behavior. I need to stop looking at these things first thing in the morning.

The default indentation for a function call with a function as the first argument is:

setInterval(function() {
  var foo = 1;
});

Which in this case yields the observed indentation:

var interval = setInterval(function() {
                 var foo = 1;
               });

You can get your desired indentation by setting js3-consistent-level-indent-inner-bracket t - this can be done via M-x customize-group. This option assumes that all function body indentation should be a single step from the previous line. So you get:

var interval = setInterval(function() {
  var foo = 1;
});

As always, if you can think of a better suite of consistent indentation rules, please do send a gist.

daaku commented 12 years ago

Thanks, that fixed it!