[Top][All Lists]

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

Re: web-mode.el

From: Dmitry Gutov
Subject: Re: web-mode.el
Date: Fri, 15 Jun 2012 05:40:13 +0400
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1

On 14.06.2012 21:28, Stefan Monnier wrote:
1) js-mode uses (widen) at the beginning of js-indent-line, and then calls

Depending on how multi-major-mode works, widen is not necessarily
a problem.  Clearly, it would need to hook into syntax-ppss.

That's good.

2) sgml-indent-line calls sgml-parse-tag-backward, which does
(re-search-backward "[<>]"), finds "<" and performs simple regexp check.
Thus,<% if a<  3 %>  breaks indentation on following lines, until first
closing tag.

I think we can treat this as a bug in sgml-indent-line, which should try
and use syntax-ppss or something like that instead of regexps.

I wonder how that could be fixed exactly. parse-partial-sexp doesn't look helpful, because it works with single characters, and sgml is concerned with full tags. It also has to handle unclosed tags like <br>, some closing tags are optional, and HTML 4 has self-closing tags.

Of course, tweaking some parts of the C mode might help.  E.g. we could
maybe extend syntax-tables slightly so that chunk boundaries are marked
with a special syntax-table value which then makes forward-comment skip
over "other language" chunks, so that any indentation code which
consistently ignores comments would then work in multi-major-mode.

As far as I can see, enhanced (forward-comment) won't help much with

It would, if you combine it with parse-sexp-ignore-comments.

If parse-partial-sexp just starts from (point-min), and then skips over "comments", it will never visit submode regions this way, no?

Another thing to consider - having "visibility" into previous chunks of the same submode may be more harmful than useful in some cases.
For example, when indenting the chunk in the middle,

  <% if true %>
  <% end %>

the chunk will see the "if" statement, and decide that it should be indented only 2 spaces from. And since it does do some indenting, I can't with my current heuristic decide that it should be instead indented relative to the line 2.

This is kinda handwavy, the example is contrived, the heuristic could be improved (suggestions welcome), but this could become more important for some other combinations of modes.

Also, if I have an extra paren inside some <script> tag, I, as a user, might be surprised to see JS code code inside another <script> tag down below indent weirdly.

And crossing two boundaries won't necessarily mean that we're in a chunk
in the same mode (or we're limited to supporting only two modes in the
same buffer), so that means syntax-table values can't be trivial.
Cons cell (mode-above . mode-below), and related code will need
to consider movement direction?

Something like (mode-above . mode-below) is what I had in mind, yes.


reply via email to

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