如何使js模式正确缩进继续(复合?)var声明? [英] How to get js-mode to properly indent continued (compound?) var declarations?

查看:149
本文介绍了如何使js模式正确缩进继续(复合?)var声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用不同的 var 语句,如

  function stretchDiv ){
var wh = $(window).height();
var sz2 = wh - ((paddingTop + paddingBottom)+(mainTop + 2)* 2);
//只有当elt的高度被限制时,滚动条才会发生
var sz3 = sz2 - outTop - 2;
$('#out')。css({'height':sz3 +'px'});
}

然后做你想要的


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.

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'});
}

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

解决方案

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

这篇关于如何使js模式正确缩进继续(复合?)var声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆