I spend most of my entire day, every day inside js2-mode, so thank you!
One big problem for me, however, is the way it indents anonymous functions. My preferred style is as follows:
setTimeout(function() { // <-- function body starts here. // ... });
js2-mode, however, seems to want the function to look like:
setTimeout(function() { // <-- js2 indents to here. });
The worst thing is that even when I indent the first line to the preferred indentation level, all subsequent enter keystrokes bring the indentation level back to js2-mode's preferred level. (I noticed a separate issue was filed proposing that enter indent to the previous line's level, which I wholeheartedly support).
I'm using js2mode version 20080616.
Aaron
Comment #1
Posted on Sep 28, 2009 by Quick WombatI just thought I'd add that this is a frequent annoyance with small page scripts. If you're using jQuery you often stick everything into an anonymous function like this:
$(function () { // define a couple of functions function foo(...) { ... }
// bind functions to events
$(".hello").click(foo);
});
Here js2-mode wants to indent to 6 instead of 4 inside the $();, so it's really inconsistent with code written with the Karl's Javascript mode.
Comment #2
Posted on Oct 28, 2009 by Quick WombatI 3rd this. I stopped using js2-mode because of this since most of the javascript I write uses a lot of anonymous functions.
Comment #3
Posted on Nov 9, 2009 by Helpful RhinoThis appears to have been fixed in the latest versions (I am using 20090723b). But the fix is not complete.
The simple case reported above is fixed:
something(function() { another(): });
However if there are previous parameters to the function call and they have been split over more than one line then the behaviour is as reported:
something("foo", function() { indentsToHere(); });
Note that putting all the parameters on the same line gives the requested behaviour:
something("foo", function() { asDesired(); });
That putting the function on the same line as an earlier parameter (but having earlier parameters split over lines) give the undesirable indentation:
something("foo", "bar", function() { booBoo(); });
And that this is also true if the thing that is split over two lines is an expression rather than multiple parameters (like a split string):
something("foo and " + "bar", function() { goesHere(); });
[And this is actually the case I care about. I would like to split Screw.Unit specs with long text like so:
it("should allow me to split my very long spec descriptions so that " + "they are readable and indent like a single block", function() { expect(indentsToHere()).to(be_true); });
]
Comment #4
Posted on Oct 11, 2010 by Grumpy Birdpeople like js2-mode but not quite content with its indentation should
really check this out:
http://mihai.bazon.net/projects/editing-javascript-with-emacs-js2-mode
it not only fixes the problems listed above, but also fix indentation with:
var a, b = function(){ }, c;
Comment #5
Posted on Oct 8, 2012 by Quick BirdIs there any fix available?
Status: New