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: Alex Schroeder
Subject: Re: [emacs-bidi] reordering based on implicit levels
Date: Mon, 12 Nov 2001 23:56:20 +0100
User-agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/21.1 (i686-pc-linux-gnu)

Eli Zaretskii <address@hidden> writes:

> I think you should invert the entire string first, if the paragraph is
> right-to-left.  _Then_ apply your code to the inverted string.

Ok, I fixed my code such that the top-level function does the right
thing.  I've pasted it here so that you can look at the doc string to
see wether it makes sense, and I pasted some test cases for you to
look at.  I think it all works as expected for the obvious cases, now.

Take a look at the last example, though.  I don't really understand
the result.  It seems that the two spaces are considered to be part of
the R2L context instead of being considered part of the sentence.

I'll keep thinking about it.

As always, if anybody is interested in the code, let me know.

Alex.


;;;###autoload
(defun bidi-reorder (str &optional context)
  "Reorder STR line by line.
What UAX#9 calls a paragraph is actually a line in Emacs because Emacs
doesn't store the text of a paragraph in one long line.  Instead of
applying rule P1, therefore, we reorder STR line by line.

Optional argument CONTEXT indicates wether STR is from a left-to-right
context, from a right-to-left context, or wether STR stands on its own.
This is used to find the paragraph embedding level.  The possible values
of CONTEXT are:

 nil -- embedding is guessed using the first strong character in STR
 L2R -- left-to-right embedding is assumed
 R2L -- right-to-left embedding is assumed"
  (let ((paragraph-level
         (cond ((not context)
                (bidi-apply-p3
                 (bidi-apply-p2 str)))
               ((eq context 'L2R)
                0)
               ((eq context 'R2L)
                1)
               ((integerp context); undocumented feature
                context)
               (t (error "Illegal bidi context: %S" context)))))
    (mapconcat (function identity)
               (mapcar (lambda (s)
                         (bidi-reorder-1 s paragraph-level))
                       (split-string str "\n"))
               "\n")))


L2R context detected automatically

(bidi-reorder "this is either arabic or hebrew and should all be inverted.  
currently
it is not really as justified as it could be.  we'll look at this
later.  CHEERS, ALEX.")

"this is either arabic or hebrew and should all be inverted.  currently
it is not really as justified as it could be.  we'll look at this
later.  XELA ,SREEHC."


L2R context forced

(bidi-reorder "THIS IS EITHER ARABIC OR HEBREW AND SHOULD ALL BE INVERTED.  
CURRENTLY
IT IS NOT REALLY AS JUSTIFIED AS IT COULD BE.  WE'LL LOOK AT THIS
LATER.  cheers, alex." 'L2R)

"YLTNERRUC  .DETREVNI EB LLA DLUOHS DNA WERBEH RO CIBARA REHTIE SI SIHT
SIHT TA KOOL LL'EW  .EB DLUOC TI SA DEIFITSUJ SA YLLAER TON SI TI
RETAL.  cheers, alex."


R2L context detected automatically, problem with two spaces on the
last line

(bidi-reorder "THIS IS EITHER ARABIC OR HEBREW AND SHOULD ALL BE INVERTED.  
CURRENTLY
IT IS NOT REALLY AS JUSTIFIED AS IT COULD BE.  WE'LL LOOK AT THIS
LATER.  cheers, alex.")

"YLTNERRUC  .DETREVNI EB LLA DLUOHS DNA WERBEH RO CIBARA REHTIE SI SIHT
SIHT TA KOOL LL'EW  .EB DLUOC TI SA DEIFITSUJ SA YLLAER TON SI TI
.  cheers, alex.RETAL"

-- 
http://www.emacswiki.org/



reply via email to

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