Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get js-mode to properly indent continued (compound?) var declarations?

If I use distinct var statements like

function stretchDiv(){
    var wh = $(window).height();
    var sz2 = wh - ((paddingTop + paddingBottom) + (mainTop + 2) * 2);
    // the scrollbar happens only when the height of the elt is constrained
    var sz3 = sz2 - outTop - 2;
    $('#out').css({'height': sz3 + 'px'});
}

then JSLint complains, telling me to combine the second and third with the previous.

enter image description here

If I follow that advice, JSLint is happy, but Emacs' builtin js-mode.el (Emacs v23.2) does not indent the additional var declarations the way I want. Also, it does not do the font-lock on the additional variables. See:

function stretchDiv(){
    var wh = $(window).height(),
    sz2 = wh - ((paddingTop + paddingBottom) + (mainTop + 2) * 2),
    // the scrollbar happens only when the height of the elt is constrained
    sz3 = sz2 - outTop - 2;
    $('#out').css({'height': sz3 + 'px'});
}

enter image description here

How can I get the proper indentation and font-locking?

like image 857
Cheeso Avatar asked Sep 07 '11 16:09

Cheeso


1 Answers

A forked version of js2-mode does exactly what you want.

like image 86
yibe Avatar answered Nov 03 '22 01:11

yibe