tamzinblake / js3-mode

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

function-literal indentation #73

Open TaylanUB opened 12 years ago

TaylanUB commented 12 years ago

It seems function-literal indentation is not properly handled in some cases. Examples include function-literals in arrays, and assignment to the result of a function call with a function-literal argument:

foo = bar(function(){
        blah
      });
foo([function(){

     }]);

Detecting each such case is probably not necessary. Can't we just look back for the regex \bfunction *(\( *[a-zA-Z$_][a-zA-Z0-9$_]*\)* *) *{ *\n * or so (emacs regex). (I probably left out some valid identifier characters from the []. And I disregarded tabs.)

I should point out that the new js2-mode on GitHub has this issue fixed. Unfortunately it's still not the first Google hit for "js2-mode": https://github.com/mooz/js2-mode

tamzinblake commented 12 years ago

js2-mode's issue would be different since it has entirely different indentation code. Where possible I don't use regexes since the language is too complex (just put a regular expression literal containing slashes in that chain).

There are a number of special cases that I'd like to handle differently, but there are caveats to all of them. I think I'll put a page up on the wiki soon detailing the problem.