Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Have you encountered an OS X text editor capable of indenting both the line

var x = 2;

and the lines

<it>Item A</it>
<it>Item B</it>

in the following html?

<meta http-equiv="content-type" content="text/html; charset=UTF-8">
function foo_bar() {
var x = 2;
<body onload="foo_bar()">


<it>Item A</it>
<it>Item B</it>


I have tried all emacs packages purporting to do this simple task properly (through a major and a minor mode), but none is adequate. I am too heavily into emacs to abandon it altogether, but I am now looking for an editor other than emacs for this task.

share|improve this question
No-one else is going to choose a text editor based on whether it can auto-indent JavaScript embedded in HTML. (Or search for this question.) –  ؘؘؘ Jul 6 '12 at 9:51
Is that so? Do elucidate us. –  Calaf Jul 6 '12 at 12:46
@LauriRanta That's not a good assumption. If one person had the question, it's entirely likely that more will. If you're interested in fussing about obscure questions, have a crack at a few of mine. –  CajunLuke Jul 6 '12 at 22:52
It is interesting so I don't think we should close it. OTOH it appears to be solvable with some clever Emacs Lisp hacking so maybe AskDifferent is just the wrong place to ask. –  patrix Aug 14 '12 at 17:34
@patrix I have tried multi-web-mode and nXhtml. Neither fits the bill. Support for two modes has been missing from emacs ever since Knuth mixed TeX with programs in a single file. It is safe not to bet that emacs will have this capability anytime soon. Of course, should you publish the "clever Lisp hacks", you will make many people rather delighted. –  Calaf Aug 14 '12 at 20:44

2 Answers 2

up vote 2 down vote accepted

I use Textmate heavily and love how auto indents for me when doing my Rails Developments. It is a really good text editor and totally worth the price. Has a lot of good features.

Though, most text editors usually have auto indentation. Coda 2 does and I believe Textwrangler and a few others. Shouldn't be too hard to find that works and most of them all have free trials to play with first to see if they are to your liking.

I hope that this answer helps you out.

share|improve this answer
Sublime Text is another good choice: sublimetext.com –  Vickash Jul 5 '12 at 18:26
Yes it is, thank you, I had for got about that one. –  de_an777 Jul 5 '12 at 18:31
Textmate does indeed indent Javascript embedded within HTML (Edit\Select\All = Command-A; Text\Indent Selection Option-Command-[). I don't see how either Coda 2 or Textwrangler can indent a selection. Sublime Text 2 has several selection and indentation options. None of my trials indented the selected buffer. Now if only Textmate would somehow import my emacs color scheme. –  Calaf Jul 5 '12 at 19:31
Textmate does allow for you to change the color scheme to whatever you like. Its pretty awesome, there are plenty of themes to download for it. You can make and create your own too. Here is one that I found that looks like a dark theme for emacs: mac.softpedia.com/get/Graphics/Emacs-TextMate.shtml –  de_an777 Jul 5 '12 at 20:49
..and to use a theme one double-clicks the .tmTheme file, rather than loads it through Textmate itself. Also, as indicated in the "14 Themes" section of the manual, the wiki (wiki.macromates.com/Themes/UserSubmittedThemes) has a number of additional themes. –  Calaf Jul 5 '12 at 22:11

I've written web-mode.el (available on http://web-mode.org) because I add the same problems as you. This Emacs Major Mode for editing HTML templates (HTML with CSS/JS/PHP/JSP) is autonomous (no other major required) and syntaxhighlights et indents according to the block's type.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.