Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs + js2-mode: disable indenting completely?

I'm using js2-mode for working with javascript in emacs and for the most part it's very useful. However, the indenting methods are terribly frustrating when working with jQuery, closures, and JSON... for instance, code that I wish to be indented like this:

var foo = jQuery('#mycontainer ul li').each(function(el){
    var bar = el.html();
});

Turns out as:

var foo = jQuery('#mycontainer ul li').each(function(el){
                                          var bar = el.html();
                                       });

Is there a way I can just switch off all the indenting "helpers" and just have emacs insert N spaces when I hit the tab key? I know manual-indentation is a step backwards, but having readable code is, IMHO, more useful than a tool that doesn't work as expected.

like image 535
Phillip B Oldham Avatar asked Mar 03 '10 09:03

Phillip B Oldham


3 Answers

Not a direct answer to your question, but here is a fork of js2-mode that has improved indenting.

One of the improvements is that your example code is indented the way you ask here.

like image 150
Dmitry Avatar answered Oct 20 '22 13:10

Dmitry


I guess I will make this a full answer instead of a comment; espresso-mode is included with Emacs, and is designed to be a Javascript mode for Emacs (instead of a Javascript mode that happens to run inside of Emacs). It works like regular programming modes, and also happens to indent things the way you like.

like image 6
jrockway Avatar answered Oct 20 '22 14:10

jrockway


Check out this solution, maps indentation function in js2-mode to partially use indentation from esresso-mode (now known as js-mode included in emacs 23.2 and newer):

http://mihai.bazon.net/projects/editing-javascript-with-emacs-js2-mode

Works exactly as I expect indentation in emacs to work and you still get the parsing awesomeness from js2-mode.

like image 5
antonj Avatar answered Oct 20 '22 14:10

antonj