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's 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 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

  1. Simple Changes Emacs Should Adopt
  2. Why Emacs Keys are Painful
  3. Problems of the Scratch Buffer
  4. M-key Notation vs Alt+key Notation
  5. Menu Problem
  6. Mode Line Problem
  7. cua-mode Problems
  8. kill-buffer Induces Buffer Accumulation
  9. Emacs Form Feed ^L
  10. Inconsistency of Search Features
  11. Single Key to Delete Whole Line
  12. Emacs HTML Mode Sucks
  13. Emacs Does Not Support Viewing Images Files In Windows
  14. Emacs Spell Checker Problems
  15. Adopt HTML as Texinfo Replacement
  16. Support HTML Mail
  17. Problems of “man” Command
  18. Emacs Lisp Mode Syntax Coloring Problem
  19. Emacs Ahk Mode Problems
  20. Problems of Emacs's Manual
  21. Problems of Emacs's Manual; Examples
  22. Emacs: Have You Read Emacs Manual?
  23. Elisp: Ban Syntax Table
  24. Emacs: Make elisp-index-search use Current Symbol
  25. Emacs: Usability Problems of Mode Documentation
  26. Problems of Emacswiki
  27. Emacs GNU Texinfo Problems; Invalid HTML
  28. A Record of Frustration in IT Industry; Disappearing FSF URLs, 2006
  29. Emacs Manual Node Persistency Issues
  30. Emacs: dired-do-query-replace-regex Replace ALL (fixed)
  31. Problems of Emacs Supporting Obsolete Systems
  32. Elisp: Function to Copy/Delete a Dir Recursively (fixed)
  33. Thoughts on Common Lisp Scheme Lisp Based Emacs
  34. Text Editors Popularity and Market Research
  35. Text Editor's Cursor Movement Behavior (emacs, vi, Notepad++)
  36. GNU Emacs Development Inefficiency
  37. Emacs Dev Inefficiency and Emacs Web 2.0?
  38. Letter-Case Commands Usability Problems
  39. Emacs: Select Line, between Quotes, Extend Selection
  40. Emacs: isearch Current Word
  41. Suggestions on Line Wrap Commands
  42. Emacs: Single Key to Delete Whole Line
  43. Emacs Cult Problem: Emacs vs Windows Notepad
  44. Emacs Undo and Emacs Cult Problem

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs

Emacs

Emacs Lisp

Misc