[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: html, css, and js modes working together

From: Dmitry Gutov
Subject: Re: html, css, and js modes working together
Date: Mon, 6 Feb 2017 05:08:05 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0

Hi Tom,

On 31.01.2017 22:34, Tom Tromey wrote:
I tried to send this last night but it bounced for some reason.

This patch changes the html, css, and js modes to work together a bit.
With this, the contents of a <style> element are syntax-highlighted and
indented according to css-mode rules, and the contents of a <script>
element are syntax-highlighted and indented according to js-mode rules.
I'd appreciate comments on this approach.

I'm glad you are interested in the problem of mixed modes, but implementing it inside html-mode is likely to make life more difficult for the existing mixed-mode frameworks because now html-mode's indentation code and font-lock rules are that much more complex.

So this is great as an experiment, and maybe a direction toward creating a built-in mixed-mode solution, but why not call the result html-and-stuff-mode in the meantime?

One might argue that we wouldn't need mmm-mode for the HTML-CSS-and-JS combination, but even aside from backward compatibility considerations, the third-party frameworks will continue to be useful for the edge cases they handle, such as solving some of the problems you mentioned in your next-to-last item.

* I used the existing (but apparently unused) prog-indentation-context
   variable in this.

So far it's only used in python-mode, I think.

I was initially skeptical of using a global
   variable but it did turn out to be pretty handy for SMIE.

A global variable is usually easy to use, if you remember to do so. I'd like to replace it with a different indent-line-function variable and calling convention, but that's a separate discussion.

* This work doesn't address the need for per-region font locking at all.

Not sure what you mean by that. But I've applied the patch, and I don't see any JS or CSS specific highlighting. Indentation kinda works, though.

Couple more things to think about:

- Both css-mode and js-mode call syntax-ppss in their indentation code. Luckily, their syntax tables are fairly compatible. But sgml-syntax-propertize-rules calls syntax-ppss as well.

That might lead to some problems with the cache. Maybe it's not a problem as long as () and {} have the same syntax classes in html-mode.

- Try this example:

    var a = 4;


It indents fine. Now try replacing "4" with "4 < 5" and reindenting the "alert" line. It jumps to the right.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]