Emacs HTML Mode Sucks

By Xah Lee. Date:

Cezar Halmagean wrote:

I have been using emacs for the past 5 years or so and I've recently stumbled upon TextMate. I love the way TextMate handles *web modes* like integration of HTML + JavaScript + CSS in the same file and I've always had a problem doing that in emacs.

I wonder what's the problem, why has an editor like TextMate gone so far in just a few years and Emacs is still not there yet.

You might try “html-helper-mode”. I don't think it'll beat any major editor that do HTML, but it somewhat helps because by default it does syntax coloring various languages that are used together with HTML.

I think the fact that emacs doesn't by default support today's practical need for HTML coding (often mixed with JavaScript, CSS, PHP, ASP, JSP codes), is a major problem with emacs. Web dev is probably the largest segment in the programing industry. Adding hurt to the wound is that a good percentage of web developers, possibly majority, are entry level programers who codes HTML/CSS/PHP. These people, when they took a look at emacs, they laugh, and rightfully so. (emacs's obscure interface, keystrokes, terminologies, made it worse)

(of course emacs fans will tell you about several elisp code on the wild that do multi modes, but the sheer fact to shop around, install, get them to work is a pain and rather not trivial. for those interested, see http://www.emacswiki.org/cgi-bin/wiki/MultipleModes )

I think to have emacs work with today's web dev needs out of the box is one of the most important need for emacs. [see Modernization of Emacs]

Even for working with pure static HTML pages, emacs's default HTML mode is quite lacking. The default HTML mode in emacs 22 (released in 2007), is at a level of ~1998's commercial HTML editors. (of course emacs has redeeming qualities, i.e. its elisp system and all, that keeps us still sticking with emacs)

Web development is my primary area of expertise. I have to work with HTML mixed with CSS, JavaScript, PHP, Perl a lot. Fortunately, lacking proper syntax coloring isn't much problem. (after all, 99.99% web pages out there are so badly formed)

One trick i do when i need proper syntax coloring, is just to switch to that lang's mode. For example, if i'm working in a PHP segment, i just switch to PHP mode. You can assign single-press keys to switch to different modes.

One could guess why emacs doesn't have a robust mode for working with today's HTML. My guess is that it's a bit hard to write such a “mixed” mode possibly due to emacs infrastructure for modes, and of course because there are relatively very few emacs developers, and there's not a good tutorial on how to write a emacs mode (it involves quite a lot elisp knowledge in several areas. I'm currently picking it up and hope to write a tutorial soon).

Michael Schuerig wrote:

I need to edit HTML documents containing considerable amounts of JavaScript, therefore I'd like to be able to use “js2-mode” for the script sections and HTML mode for the markup proper. I was under the impression that MMM can somehow pull this off, but I don't quite see how.

That's one of the emacs major problem today.

Basically currently there is no solution. “js2-mode” have some problems working with several of the multi mode thing.

Your current work around is:

non of the above is robust.

The “nxhtml-mode” attempts to fix the HTML multi-language problem from the ground up, based on the “nxml-mode” and some multi-mode mechanism called something like mumbo-ma-muu.

The “html-helper-mode” is a basic attempt to have a mode that just works with the multi-lang nature of HTML.

none of the above i have much experience. They are too much headache to install, or dig into.

Or, what i do, is assign keyboard shortcuts [see Emacs Keys: Define Key] so that, when you want to work with js code block in HTML, press a button, it switches you to a simple js mode (just for the syntax coloring and comment purposes), and when you are in PHP code block, press a button, it uses “php-mode” (which makes the HTML reasonably readable too), and when in HTML, press, HTML code gets highlighted properly. [see Where to get JavaScript, Visual Basic, PHP modes?]

also, there are Ruby modes that are designed specifically for mixed Ruby and HTML. Search for Ruby On Rail something.

Emacs Modernization