简体   繁体   English

Emacs JavaScript自动缩进

[英]Emacs JavaScript auto-indentation

I'm looking for a way to turn off automatic indentation in emacs. 我正在寻找一种方法来关闭emacs中的自动缩进。 I don't want emacs to automatically indent code when I enter special characters like ; 当我输入特殊字符时,我不希望emacs自动缩进代码; or /* 要么 /*

Thanks for any help. 谢谢你的帮助。

Steve Yegge's js2-mode is great. Steve Yegge的js2模式很棒。

From http://code.google.com/p/js2-mode/ 来自http://code.google.com/p/js2-mode/

An improved JavaScript mode for GNU Emacs. GNU Emacs的改进JavaScript模式。

Features: 特征:

  • variable (adjustable) indentation 变量(可调)缩进
  • accurate syntax highlighting 准确的语法高亮
  • syntax-error highlighting 语法错误突出显示
  • strict-mode warning reporting (such as duplicate var declaration) 严格模式警告报告(例如重复的var声明)
  • smart line-wrapping in comments and strings 注释和字符串中的智能换行
  • typing helpers (eg matching quotes/brackets) 键入助手(例如匹配引号/括号)
  • code-folding (collapse element as {...}) 代码折叠(折叠元素为{...})
  • supports JavaScript 1.5, 1.6 and 1.7 (including E4X) 支持JavaScript 1.5,1.6和1.7(包括E4X)
  • customizable colors, or use font-lock defaults 可自定义的颜色,或使用字体锁默认值
  • many customization options 许多自定义选项

Eventually aims to be competitive with IntelliJ and other best-of-class JavaScript editors. 最终旨在与IntelliJ和其他一流的JavaScript编辑器竞争。

Note - this mode is for GNU Emacs, version 21 and higher. 注意 - 此模式适用于GNU Emacs,版本21及更高版本。 It does not support XEmacs. 它不支持XEmacs。

If you're using an old mode based on CC-mode, Cc Cl will toggle electricity. 如果您使用基于CC模式的旧模式, Cc Cl将切换电力。

There's a new Javascript mode that ships with Emacs that can be interactively toggled with Mx electric-indent-mode Emacs附带了一个新的Javascript模式,可以通过Mx electric-indent-mode进行交互式切换

Apparently, the new blessed way to achieve this is: 显然,实现这一目标的新方法是:

M-x electric-indent-mode

This command toggles "electric indentation", ie auto-indenting whenever certain special characters are hit. 此命令切换“电子缩进”,即每当遇到某些特殊字符时自动缩进。

The best thing is that it works accross major modes, not only for js-mode (the default javascript major mode in recent version of Emacs). 最好的是它适用于主要模式,不仅适用于js-mode (最近版本的Emacs中的默认javascript主模式)。

Set javascript-auto-indent-flag to nil before loading javascript-mode. 在加载javascript-mode之前将javascript-auto-indent-flagnil You can either add a line to your .emacs file or type 您可以在.emacs文件中添加一行或输入

M-x customize-group RET javascript RET

and edit the value there and save. 并在那里编辑值并保存。 You may need to restart Emacs for this to take effect; 您可能需要重新启动Emacs才能生效; at least in the version of javascript.el that I have, the flag is only consulted when setting up the keymap. 至少在我所拥有的javascript.el版本中,只有在设置keymap时才会查询该标志。

这将关闭所有缩进: Mx基本模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM