emacs-bidi
[Top][All Lists]
Advanced

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

Re: [emacs-bidi] reordering based on implicit levels


From: Eli Zaretskii
Subject: Re: [emacs-bidi] reordering based on implicit levels
Date: Mon, 12 Nov 2001 11:22:57 +0200 (IST)

On Mon, 12 Nov 2001, Alex Schroeder wrote:

> > Note that UAX#9 rules that every line is a separate paragraph (because
> > \n is defined as a NEUTRAL_B character), but Emacs cannot behave like
> > this because we use newlines for filling text.  This is not much of a
> > complication for you, and perhaps you could even ignore that subtlety
> > altogether, since visual order doesn't have embedding levels, but
> > please be aware of this, just in case.
> 
> Hm.  Here's what happens if I don't do anything.  It seems to work...
> 
> (let ((str "this is a normal paragraph containing some
> words in ARAB and HEBREW.  these strings need to be
> reverted.  numbers like 123 should work, even when
> ENCLOSED IN ARAB TEXT SUCH AS 4567.89 IS ON THIS LINE."))
>   (bidi-reorder-string
>    str
>    (bidi-resolve-implicit-levels
>     (bidi-resolve-weak-types
>      (bidi-get-types str)))))
> 
>  =>
> 
> "this is a normal paragraph containing some
> words in BARA and WERBEH.  these strings need to be
> reverted.  numbers like 123 should work, even when
> ENIL SIHT NO SI 4567.89 SA HCUS TXET BARA NI DESOLCNE."

Beginner's luck ;-)  The key is that you have no R2L text here that
spans multiple lines, that's why it seems to work.

> I therefore assume that the following will work as expected.
> 
> (defun bidi-reorder-region (start end)
>   "Reorder the region between START and END."
>   (interactive "r")
>   (let ((str (buffer-substring start end)))
>     (delete-region start end)
>     (goto-char start)
>     (insert
>      (bidi-reorder-string
>       str
>       (bidi-resolve-implicit-levels
>        (bidi-resolve-weak-types
>       (bidi-get-types str)))))))
> 
> (defun bidi-reorder-paragraph ()
>   "Reorder the current paragraph."
>   (interactive)
>   (let ((start (save-excursion
>                (backward-paragraph)
>                (point)))
>       (end (save-excursion
>              (forward-paragraph)
>              (point))))
>     (bidi-reorder-region start end)))

No, this won't work.  You need to convert each line individually, as
if a newline were a paragraph separator, like UAX#9 says (that's what
I meant by ``ignore that subtlety'').



reply via email to

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