[Top][All Lists]

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

Re: web-mode.el

From: Lennart Borgman
Subject: Re: web-mode.el
Date: Thu, 14 Jun 2012 18:54:04 +0200

On Thu, Jun 14, 2012 at 4:24 PM, Dmitry Gutov <address@hidden> wrote:
> Stefan Monnier <address@hidden> writes:
>>> I'm also using narrowing during indentation, but some modes (like js)
>>> use (widen) in indent-line-function. It should be somewhat fixable by
>> I don't think it's worthwhile trying to make a "multi-major-mode" that
>> works with any major mode, no matter what wicked thing it does.
>> So it's OK to impose a few conventions that the major mode needs
>> to obey.  The important and difficult part is to figure what those
>> conventions need to be.
> I agree in principle. And since fontification of chunks can already be
> done reliably enough (if not with best performance), I think indentation
> function conventions would be more important. Shall we start with
> collecting cases?

I am not sure I agree. The way I have proposed to do it is to change
the low level functions reading the buffer so that you can lie to them
and say that the chunks in other major modes are just whitespace+line
feeds. It would be reliable (I think), but it requires much effort so
it still may not be worth it.

I took a look at what I had done so far (it was some time ago now). I
have not touched the C code. I have only made some changes in
mumamo.el towards this goal.

As Dmitry says, fontification is rather simple (but you have to be
careful to make it fast). Indentation is harder.

First of all I have tried to write down the logic to use. I have
rewritten that part a few times. Even this was harder then I expected.
You can see my current comments here in mumamo-indent-line-function-1
(at line 7915 currently):


Second I have moved towards doing indentation the way it should have
been done if the changes in the C code were done. I do this by copying
the code to a mirror buffer, replacing everything in "other" chunks
with whitespace+line feeds.

It is easy to get things a bit wrong when you do this of course. I am
not sure if the problem you have seen, Dmitry, is because (1) failed
to copy correctly, (2) the idea is somehow buggy, or (3) I just did
not implement all cases or did not finish implementing them.

> So far I have two problems without obvious solutions:
> 1) js-mode uses (widen) at the beginning of js-indent-line, and then calls
> (syntax-ppss).

There are several modes for javascript. And of course for html too;
nxml-mode is one. Stopping nxml-mode from crossing the chunks
boundaries is not easy.

>> 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.

I have tried to implement something like that in mumamo.el, but I
think it is not working correctly anymore. Something might have
changed since I did that.

reply via email to

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