views:

252

answers:

3

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?

+4  A: 

I think mumamo is generally used for this. http://www.emacswiki.org/emacs/MuMaMo

Elfred
Yes, perfect. Clicking on the link I learned that the best way to get Mumamo is to download and install nXhtml mode. It's working perfectly.
Cheeso
+4  A: 

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.

themis
nXhtml works great, but I am often happy with just sgml-mode. The real tricky question is not "what mode to use for (X)HTML?", but "what mode to use for a file with mixed content?"
Cheeso
I take back every doubt I had about nXhtml mode. The cool part about nXhtml is Mumamo mode, which does exactly what I described - it supports multiple modes in a single buffer. I can edit and indent Javascript, CSS, and (X)HTML all in the same file. Nice. Thanks.
Cheeso
+3  A: 

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.

pajato0
Patient: "It hurts when I do this, Doc." Doctor: "Don't do that."
Cheeso
I do this to, and when I can't (PHP and JSP code) I rely on nXhtml.
stsquad