简体   繁体   中英

Emacs JavaScript auto-indentation

I'm looking for a way to turn off automatic indentation in emacs. I don't want emacs to automatically indent code when I enter special characters like ; or /*

Thanks for any help.

Steve Yegge's js2-mode is great.

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

An improved JavaScript mode for GNU Emacs.

Features:

  • variable (adjustable) indentation
  • accurate syntax highlighting
  • syntax-error highlighting
  • strict-mode warning reporting (such as duplicate var declaration)
  • 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)
  • customizable colors, or use font-lock defaults
  • many customization options

Eventually aims to be competitive with IntelliJ and other best-of-class JavaScript editors.

Note - this mode is for GNU Emacs, version 21 and higher. It does not support XEmacs.

If you're using an old mode based on CC-mode, Cc Cl will toggle electricity.

There's a new Javascript mode that ships with Emacs that can be interactively toggled with 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).

Set javascript-auto-indent-flag to nil before loading javascript-mode. You can either add a line to your .emacs file or type

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; at least in the version of javascript.el that I have, the flag is only consulted when setting up the keymap.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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