Friday, February 25, 2011

Re: bidi in vim

Hi, Moshe,

I've rearranged things a bit to suit my reply.

> Of course I also would prefer to have full bidi support, but I can also
> see that this would require some serious changes and complications in
> the code,

I think basing it on syntax regions/matches/whatever also would require
serious changes. I don't think there is any 'easy' way to do this, and
if we have to pick between 'hard' ways, I think it would be smartest to
pick the way that is actually most standard/correct.

> and even if this is done, there will probably be a rather serious
> performance penalty (for instance, the full bidi algorithm works on
> whole paragraphs, so you would have to compute something for the whole
> paragraph for every keystroke).

Optimisations can be made so that calculations aren't too inefficient.
Also, the same is true for syntax regions--recalculations must be made
for whole paragraphs/sections on each keypress.

> I also don't see that what I'm suggesting is a hack or a workaround.

I think it is a hack because which direction text should be displayed
really has nothing to do with syntax regions conceptually. It is about
what language the text is in, what script the characters in the text
come from, etc..

That said, there are bound to be edge cases, and perhaps syntax regions
could help solve them. But I would think this would be more of a 'bidi
algorithm override' than where the bidi algorithm actually takes effect
in the first place.

> It could actually be part of a general mechanism: for instance, the
> highlight or the syntax command could take a function as an optional
> argument. This function will be called with the start and end of the
> corresponding region (and maybe other arguments) and will output a new
> string to be displayed instead of the original one. This way the
> reversing can be done in Vim language (and you could use this system
> for other purposes, for instance capitalise all text in the region).

This would not work at all. It is not just a display issue where you can
get different display text from a Vimscript function. Vim also needs to
know where your cursor is within the text, whether to add new characters
to the left or the right of where the cursor is, etc., etc.. Best to
keep Vimscript right out of it.

>>> If this can be done, I think it will solve most practical problems,
>>> since when editing latex, for example, text in different direction will
>>> appear in particular commands or environments.

My perspective is a bit different. When I want bidi text, it's not
because I have text of one language embedded in particular regions of a
program or script or markup. It's because I'm writing in multiple
languages. I would have thought this, too, was quite common, i.e. simply
editing text.

This stuff should also work when syntax highlighting is turned off,
IMHO.

So, as I said before, my opinion is that bidi would be great, but I'd
love to see it done properly. There are a number of other benefits to
this, too: e.g. if Vim knows the underlying terminal supports bidi, it
can omit doing the character swapping itself, but just interface
properly with the terminal; how well that would work, I don't know, but
it may be worth a try.

Ben.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment