Is there any *good* HTML-mode for emacs?

23

3

I love emacs,

and I want to do my web-programming work in it,
but I can't find a way to get it to edit HTML properly.

I mean it's seriously awful.

It will do HTML fine, but not PHP, javascript, etc.

I tried getting html-helper-mode... I downloaded it, put it in /usr/local/share/emacs/site-lisp, and added it to my .emacs file:

(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
  (setq auto-mode-alist (cons '("\\.html$" . html-helper-mode) auto-mode-alist))

copied and pasted from some site (I don't know elisp).
it just, doesn't highlight anything at all.

I tried downloading a whole bunch of modes and using some other mode to string them together, to no avail.

Emacs is so great in every other way--why can't it do the simple task of editing web pages? I mean, it's a pretty standard thing to do for editors these days.

So, does anyone know how to do this?

Carson Myers

Posted 2009-08-09T02:10:54.660

Reputation: 2 611

Answers

4

Have you checked out Emacs Wiki html page? nxhtml in particular looks useful.

luapyad

Posted 2009-08-09T02:10:54.660

Reputation: 335

4it looks useful but it's very painful to use... it loads slowly, doesn't indent properly, is ugly, runs slow, highlights everything red and then makes it all italic and just, is painful... – Carson Myers – 2009-08-09T03:15:04.580

1I've used nxhtml with success. Font colors and italics are all controllable by customizing the faces – Doug Harris – 2009-08-27T20:11:30.063

35

I had the same problem as you so I decided to write web-mode.

enter image description here

Web-mode.el is a major mode for Emacs that is intended for editing mixed web templaces (HTML with Java/JSP, PHP, CSS, JavaScript).

It doesn't rely on any other mode. It does syntax highlight et indenting according to the code block type. I've written a little HOWTO page on

About

  • web-mode.el is a major-mode for editing web templates (HTML with PHP, Java/JSP, JavaScripts, CSS styles).
  • web-mode.el is will never be a full featured PHP or JS mode. (We don’t encourage multi-lines blocs of code in templates !).

Native Features

  • smart indentation (according to the context : HTML, PHP, Java/JSP, JavaScript or CSS)
  • code navigation : C-c C-n between opening and closing HTML tag or between PHP controls > - if ... else ... endif, for ... endfor
  • HTML tag autoclosing (after
  • syntax highlighting (according to the type of bloc)
  • snippet insertion C-c C-i (auto indented, aware of text selection)
  • auto-inserts (ex. ?> after <?php)

fxbois

Posted 2009-08-09T02:10:54.660

Reputation: 451

Go to say, it saves my day... Thanks @fxbois! I love it. Finally I can get the indentation of mix between html,css,java, etc. Can it be done with Python ? – swdev – 2013-09-11T01:04:03.037

@swdev could you open an issue on github about this request of python compatibility. Could send d a link to the template syntax documentation and an example of such a template. – fxbois – 2013-09-12T06:23:38.380

Looks neat, but seems to use regexp for parsing HTML, rather than having a real parser like psgml... – David N. Welton – 2013-09-27T13:20:30.257

3What do you mean by real parser ? I traverse the document to find tags that begin with < and end with > etc etc .. Have you find any limitation ? If you find any, do not hesitate to report issues on the github repo – fxbois – 2013-09-28T14:44:50.690

3

I've been dissatisified with the available modes, but I have found happiness recently using plain old html-mode augmented with yasnippet and tidy.el. As the other answers have mentioned nxhtml mode is useful if you are writing xhtml.

If you are wanting to get highlighted php and javascript, you might want to look at mmm-mode, which will allow you to run multiple major modes at once. I've never used it, so I don't know who it handles conflicting key bindings, etc... so you'll have to feel your way around there.

Pinochle

Posted 2009-08-09T02:10:54.660

Reputation: 335

3

Give multi-web mode a try, it's a minor mode designed with web editing in mind, it selects the appropriate major when the point moves around.

skwee rell

Posted 2009-08-09T02:10:54.660

Reputation: 31

0

I too use nXhtml mode for mixed mode editing having failed to get Multiple Modes working correctly. It has been a bit of a rocky ride but recent builds have proved to be useful. I'm running with Emacs 23 FWIW.

stsquad

Posted 2009-08-09T02:10:54.660

Reputation: 449