emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r105488: Add L and R categories to st


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r105488: Add L and R categories to standard category table, and use them.
Date: Thu, 18 Aug 2011 11:53:29 -0400
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 105488
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Thu 2011-08-18 11:53:29 -0400
message:
  Add L and R categories to standard category table, and use them.
  
  * lisp/international/characters.el: Add L and R categories.
  
  * lisp/subr.el (bidi-string-mark-left-to-right): Rename from
  string-mark-left-to-right.  Use category search.
  
  * lisp/buff-menu.el (Buffer-menu-buffer+size): Callers changed.
modified:
  etc/NEWS
  lisp/ChangeLog
  lisp/buff-menu.el
  lisp/emacs-lisp/tabulated-list.el
  lisp/international/characters.el
  lisp/subr.el
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2011-08-18 11:36:19 +0000
+++ b/etc/NEWS  2011-08-18 15:53:29 +0000
@@ -1047,15 +1047,16 @@
 declared as dynamically bound.
 
 +++
-** New function `string-mark-left-to-right'.
+** New function `bidi-string-mark-left-to-right'.
 Given a string containing right-to-left (RTL) script, this function
-returns another string with a terminating LRM (left-to-right mark)
-character.  If this string is inserted into a buffer, Emacs treats the
-LRM as the end of an RTL segment and displays following text as LTR.
+returns another string which can be safely inserted into a buffer as a
+distinct RTL "segment", without causing any following text to be
+displayed as RTL.  (This is done by appending a Unicode "left-to-right
+mark" character.)
 
 This is useful when the buffer has overall left-to-right (LTR)
-paragraph direction and you need to insert a string whose contents
-(and hence directionality) are not known in advance.
+paragraph direction and you need to insert a string whose contents and
+directionality are not known in advance.
 
 ** pre/post-command-hook are not reset to nil upon error.
 Instead, the offending function is removed.

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-08-18 11:36:19 +0000
+++ b/lisp/ChangeLog    2011-08-18 15:53:29 +0000
@@ -1,3 +1,12 @@
+2011-08-18  Chong Yidong  <address@hidden>
+
+       * international/characters.el: Add L and R categories.
+
+       * subr.el (bidi-string-mark-left-to-right): Rename from
+       string-mark-left-to-right.  Use category search.
+
+       * buff-menu.el (Buffer-menu-buffer+size): Callers changed.
+
 2011-08-18  Juri Linkov  <address@hidden>
 
        * faces.el (error, warning, success): New faces with definitions

=== modified file 'lisp/buff-menu.el'
--- a/lisp/buff-menu.el 2011-08-10 19:03:56 +0000
+++ b/lisp/buff-menu.el 2011-08-18 15:53:29 +0000
@@ -681,9 +681,9 @@
                           (string-width tail)
                           2))
                       Buffer-menu-short-ellipsis
-                      (string-mark-left-to-right tail))))
+                      (bidi-string-mark-left-to-right tail))))
     ;; Don't put properties on (buffer-name).
-    (setq name (string-mark-left-to-right name)))
+    (setq name (bidi-string-mark-left-to-right name)))
   (add-text-properties 0 (length name) name-props name)
   (add-text-properties 0 (length size) size-props size)
   (let ((name+space-width (- Buffer-menu-buffer+size-width

=== modified file 'lisp/emacs-lisp/tabulated-list.el'
--- a/lisp/emacs-lisp/tabulated-list.el 2011-08-10 19:03:56 +0000
+++ b/lisp/emacs-lisp/tabulated-list.el 2011-08-18 15:53:29 +0000
@@ -283,7 +283,7 @@
             (> (length label) width)
             (setq label (concat (substring label 0 (- width 3))
                                 "...")))
-       (setq label (string-mark-left-to-right label))
+       (setq label (bidi-string-mark-left-to-right label))
        (if (stringp desc)
            (insert (propertize label 'help-echo help-echo))
          (apply 'insert-text-button label (cdr desc)))

=== modified file 'lisp/international/characters.el'
--- a/lisp/international/characters.el  2011-07-06 22:43:48 +0000
+++ b/lisp/international/characters.el  2011-08-18 15:53:29 +0000
@@ -114,6 +114,16 @@
 Base characters (Unicode General Category L,N,P,S,Zs)")
 (define-category ?^ "Combining
 Combining diacritic or mark (Unicode General Category M)")
+
+;; bidi types
+(define-category ?R "Right-to-left (strong)
+Characters with \"strong\" right-to-left directionality, i.e.
+with R, AL, RLE, or RLO Unicode bidi character type.")
+
+(define-category ?L "Left-to-right (strong)
+Characters with \"strong\" left-to-right directionality, i.e.
+with L, LRE, or LRO Unicode bidi character type.")
+
 
 ;;; Setting syntax and category.
 
@@ -478,6 +488,16 @@
                  (modify-category-entry x category))
              chars)))))
 
+;; Bidi categories
+
+(map-char-table (lambda (key val)
+                 (cond
+                  ((memq val '(R AL RLO RLE))
+                   (modify-category-entry key ?R))
+                  ((memq val '(L LRE LRO))
+                   (modify-category-entry key ?L))))
+               (unicode-property-table-internal 'bidi-class))
+
 ;; Latin
 
 (modify-category-entry '(#x80 . #x024F) ?l)

=== modified file 'lisp/subr.el'
--- a/lisp/subr.el      2011-08-12 15:43:30 +0000
+++ b/lisp/subr.el      2011-08-18 15:53:29 +0000
@@ -3539,30 +3539,23 @@
   (eq t (compare-strings str1 nil nil
                          str2 0 (length str1) ignore-case)))
 
-(defun string-mark-left-to-right (str)
+(defun bidi-string-mark-left-to-right (str)
   "Return a string that can be safely inserted in left-to-right text.
-If STR contains right-to-left (RTL) script, return a string
-consisting of STR followed by a terminating invisible
-left-to-right mark (LRM) character.
-
-The LRM character marks the end of an RTL segment, and resets the
-display direction of any subsequent text to left-to-right.
-\(Otherwise, some of that text might be displayed as part of the
-RTL segment, based on the bidirectional display algorithm.)
-
-If STR contains no RTL characters, return STR."
+
+Normally, inserting a string with right-to-left (RTL) script into
+a buffer may cause some subsequent text to be displayed as part
+of the RTL segment (usually this affects punctuation characters).
+This function returns a string which displays as STR but forces
+subsequent text to be displayed as left-to-right.
+
+If STR contains any RTL character, this function returns a string
+consisting of STR followed by an invisible left-to-right mark
+\(LRM) character.  Otherwise, it returns STR."
   (unless (stringp str)
     (signal 'wrong-type-argument (list 'stringp str)))
-  (let ((len (length str))
-       (n 0)
-       rtl-found)
-    (while (and (not rtl-found) (< n len))
-      (setq rtl-found (memq (get-char-code-property
-                            (aref str n) 'bidi-class) '(R AL RLO))
-           n (1+ n)))
-    (if rtl-found
-       (concat str (propertize (string ?\x200e) 'invisible t))
-      str)))
+  (if (string-match "\\cR" str)
+      (concat str (propertize (string ?\x200e) 'invisible t))
+    str))
 
 ;;;; invisibility specs
 


reply via email to

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