Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get JavaScript syntax coloring in emacs inside the .html file? [duplicate]

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

Using emacs built-in JavaScript mode or SteveY's js2 mode, I get great syntax coloring of JavaScript in a *.js file. Is there a way to get good syntax coloring of the bits of JavaScript inside a *.html file? (maybe a better html mode than what comes with the editor by default, or some way to select a region and colorize it as *.js?). Thanks!

like image 531
Peter Williamson Avatar asked Feb 07 '11 18:02

Peter Williamson


People also ask

How do I get syntax highlighting in emacs?

5.43 How do I turn on syntax highlighting? font-lock-mode is the standard way to have Emacs perform syntax highlighting in the current buffer. It is enabled by default. With font-lock-mode turned on, different types of text will appear in different colors.

How do you configure Emacs for editing HTML files that contain JavaScript?

Using web-mode-el: This way of configuring emacs is simplest and easiest. We can use major mode “web-mode. el” for this kind of usage where we want to edit HTML files that have JavaScript, CSS, JAVA(JSP), PHP.


2 Answers

web-mode can let you edit HTML documents embedding CSS / JavaScript and Server blocks

like image 53
L42y Avatar answered Oct 29 '22 05:10

L42y


Yes, this turns out to be a duplicate of the link above.

Short answer: One can use nxhtml with it's multiple major modes (MuMaMo), but I couldn't get that to work for me. One can search the emacs wiki for mumamo to see several multiple mode alternative packages, but none of them did it for me. One can also use indirect buffers and put them into different modes than eachother. I also tried changing the major mode of my html file to js, but it had a hard time finding the js inside the script tags.

Finally, a co-worker suggested narrowing the buffer and putting it into Javascript mode, and that worked well for me.

like image 39
Peter Williamson Avatar answered Oct 29 '22 03:10

Peter Williamson