What mode do people use when using Emacs to edit web pages that contain CSS, javascript, and HTML?

Viewed 5428

typically the code is something like:

<html>
  <head>
    <style type="text/css">
       body { font-size:12pt; font-family: Arial;}
        ....
    </style>
    <script type="text/javascript" src="jquery.1.3.2js"></script>
    <script type="text/javascript">
    <!--
        $(document).ready(function(){
          ...
        });
        ...
    -->
    </script>
    <meta ... />
  </head>
  <body>
    <div>
      <p>
       ....
      </p>
      ...
    </div>
    ....
  </body>
</html>

I like javascript-mode for the syntaxt highlighting and indenting. Likewise for sgml-mode for the HTML. Also I get auto-complete on the open tags. Css-mode is not so important so it's not so much a priority.

That's 3 disparate languages and 3 modes. Right now I've been swapping modes manually as I edit different sections. This works, sort of.

Anyone got a better approach?

6 Answers

I use nXhtml for emacs. Quoting from the page

One of the main parts of nXhtml is nxhtml-mode, a GNU Emacs major mode that builds on nxml-mode. It knows about XHTML syntax and can check this as you type. It can also tell you what tags and attributes you can use at a certain point and help you insert them.

That feature, which we call completion, is one of the main features of this mode. Another important feature is the ability to mix several languages in one buffer and get the correct syntax highlighting and indentation for each of them.

I'd be loathe to call my approach better, but fwiw, I avoid this situation like the plague by putting CSS into .css files and javascript into .js files and then put "include" tags in the html file. Then Emacs handles each nicely. Admittedly, having three, large monitors with full screen Emacs on each makes side by side buffers containing the files I need hardly painful at all. -:) And it doesn't work real well in an enterprise environment where I don't have control over what other engineers choose to do.

Related