Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

5 Answers 5

up vote 4 down vote accepted

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

share|improve this answer
4  
it 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 Aug 9 '09 at 3:15
1  
I've used nxhtml with success. Font colors and italics are all controllable by customizing the faces –  Doug Harris Aug 27 '09 at 20:11

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)
share|improve this answer
    
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 Sep 11 '13 at 1:04
    
@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 Sep 12 '13 at 6:23
    
Looks neat, but seems to use regexp for parsing HTML, rather than having a real parser like psgml... –  David N. Welton Sep 27 '13 at 13:20
1  
What 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 Sep 28 '13 at 14:44

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

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.