[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fri, 15 Jun 2012 07:24:10 +0400
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1
On 14.06.2012 20:54, Lennart Borgman wrote:
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
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.
Fully isolating the chunks might not be the best course of action, even
if it were not too hard to do.
For example, if we want to adjust indentation inside <% if %> <% end%>
blocks, we need to be able to actually look inside them while we're in
the primary mode chunk (between those two).
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.
I don't think I understand the code enough to answer that, but I'm
inclined to fault implementation (not necessarily of the stage you
described above). For example, one of the problems shows that
indentation function behaves differently, depending on where inside the
(same) line the point is.
As an aside, this bit from the docstring sounds not very useful, maybe
"- However first non-empty line indentation in a chunk when going
in is special if prev-prev chunk is on same mumamo-depth and
have the same major mode. Then indent relative last non-empty
line in prev-prev chunk."
So far I have two problems without obvious solutions:
1) js-mode uses (widen) at the beginning of js-indent-line, and then calls
nxml-mode is one. Stopping nxml-mode from crossing the chunks
boundaries is not easy.
js2-mode's indentation function is very similar to js-mode, since
multi-mode context, though, and while fixing that shouldn't be too hard,
I'm not sure it's worth spending time on, because js2-mode's advantages
over js-mode are most evident with larger files, not small snippets.
I have yet to look into using nxml as primary mode. Do you have any
suggestions how that could be made easier?
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.
Could you show where this is implemented?
Re: web-mode.el, Dmitry Gutov, 2012/06/14
- Re: web-mode.el, (continued)
Re: web-mode.el, Stefan Monnier, 2012/06/14
- Re: web-mode.el, Lennart Borgman, 2012/06/14
- Re: web-mode.el,
Dmitry Gutov <=
- Re: web-mode.el, Lennart Borgman, 2012/06/15
- Re: web-mode.el, Dmitry Gutov, 2012/06/16
- Re: web-mode.el, Lennart Borgman, 2012/06/16
- Re: web-mode.el, Dmitry Gutov, 2012/06/18
- Re: web-mode.el, Lennart Borgman, 2012/06/18
- Re: web-mode.el, Dmitry Gutov, 2012/06/19