Cheeso
Cheeso

Reputation: 192437

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?

Upvotes: 9

Views: 802

Answers (1)

yibe
yibe

Reputation: 4109

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

Upvotes: 9

Related Questions