[英]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. 我正在使用js2-mode在emacs中使用javascript,并且在大多数情况下它非常有用。 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:
但是,在使用jQuery,闭包和JSON时,缩进方法非常令人沮丧...例如,我希望缩进的代码如下所示:
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? 有没有办法我可以关闭所有缩进的“帮助器”,只有当我按Tab键时,emacs插入N个空格? 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.
我知道手动缩进是一个倒退,但有可读代码,恕我直言,比一个不能按预期工作的工具更有用。
Not a direct answer to your question, but here is a fork of js2-mode
that has improved indenting. 不是你的问题的直接答案,但这里是一个改进缩进的
js2-mode
的分支 。
One of the improvements is that your example code is indented the way you ask here. 其中一项改进是您的示例代码以您在此处提出的方式缩进。
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). espresso-mode
包含在Emacs中,旨在成为Emacs的Javascript模式(而不是恰好在Emacs中运行的Javascript模式)。 It works like regular programming modes, and also happens to indent things the way you like. 它像常规编程模式一样工作,也可以按照你喜欢的方式缩进。
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): 查看此解决方案,在js2-mode中映射缩进功能以部分使用esresso-mode中的缩进(现在称为emacs 23.2和更新版本中包含的js-mode):
http://mihai.bazon.net/projects/editing-javascript-with-emacs-js2-mode 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. 完全像我期望在emacs中缩进工作,你仍然可以从js2模式获得解析的精彩。
Have you tried new versions of js2-mode? 你尝试过新版本的js2-mode吗? It looks like there's a fix out: http://code.google.com/p/js2-mode/issues/detail?id=94
看起来有一个问题: http : //code.google.com/p/js2-mode/issues/detail?id = 94
js2-mode supports "bounce" indenting; js2-mode支持“弹跳”缩进; you can press tab multiple times to choose different likely indenting levels, so you might be able to get the effect you want that way:
你可以多次按Tab键选择不同的可能缩进级别,这样你就可以获得你想要的效果:
(setq js2-bounce-indent-p t)
You can simply bind TAB to insert itself: 您可以简单地绑定TAB以插入自身:
(add-hook 'js2-mode-hook 'my-js2-mode-hook)
(defun my-js2-mode-hook ()
(define-key js2-mode-map [tab] 'self-insert-command))
(But the better solution would, of course, be to find out why the mode thinks it needs so much indentation for anonymous functions, and fix it.) (但更好的解决方案当然是找出为什么模式认为它需要对匿名函数进行如此多的缩进,并修复它。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.