views:

1459

answers:

4

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.

A: 
M-x fundamental-mode
Trey Jackson
A: 

If you're using a mode based on CC-mode, C-c C-l will toggle electricity.

ashawley
+5  A: 

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 (e.g. 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.

Mike Samuel
He can't compete with Aptana which is free. It comes with a JS parsers which is as good as js2-modes (if not better b/c of intellisence). His indentation rules are not adjustable, all you can do is set them to tabs, or variable number of spaces. Which doesn't keep js2-mode from indenting 8 spaces instead of 4, even if you have it set that way. It doesn't handle comma delimited vars or things like this statement $.each(array,function(), next line will indent against the function
Drew
From the docs:;; Unlike cc-engine based language modes, js2-mode's line-indentation is not;; customizable. It is a surprising amount of work to support customizable;; indentation. The current compromise is that the tab key lets you cycle among;; various likely indentation points, similar to the behavior of python-mode.
Drew
Drew, do you have a link to Aptana's emacs mode?
Mike Samuel
A: 

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.

Jouni K. Seppänen
Or if using `js2-mode`, set variable `js2-auto-indent-flag` to nil.
Török Gábor