Commit 9ccaaa4b authored by Chong Yidong's avatar Chong Yidong
Browse files

Fix behavior of string-mark-left-to-right.

* lisp/subr.el (string-mark-left-to-right): Search the entire string
for RTL script, not just the terminating character.  Doc fix.
parent 6cd18349
...@@ -1038,11 +1038,15 @@ of function value which looks like (closure ENV ARGS &rest BODY). ...@@ -1038,11 +1038,15 @@ of function value which looks like (closure ENV ARGS &rest BODY).
*** New function `special-variable-p' to check whether a variable is *** New function `special-variable-p' to check whether a variable is
declared as dynamically bound. declared as dynamically bound.
** New function `string-mark-left-to-right' appends a Unicode LRM ** New function `string-mark-left-to-right'.
(left-to-right mark) character to a string if it terminates in Given a string containing right-to-left (RTL) script, this function
right-to-left script. This is useful when the buffer has overall returns another string with a terminating LRM (left-to-right mark)
left-to-right paragraph direction and you need to insert a string character. If this string is inserted into a buffer, Emacs treats the
whose contents (and directionality) are not known in advance. LRM as the end of an RTL segment and displays following text as LTR.
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.
** pre/post-command-hook are not reset to nil upon error. ** pre/post-command-hook are not reset to nil upon error.
Instead, the offending function is removed. Instead, the offending function is removed.
......
2011-08-12 Chong Yidong <cyd@stupidchicken.com>
* subr.el (string-mark-left-to-right): Search the entire string
for RTL script, not just the terminating character. Doc fix.
2011-08-12 Stefan Monnier <monnier@iro.umontreal.ca> 2011-08-12 Stefan Monnier <monnier@iro.umontreal.ca>
* progmodes/js.el (js-syntax-propertize, js-syntax-propertize-regexp): * progmodes/js.el (js-syntax-propertize, js-syntax-propertize-regexp):
......
...@@ -3540,18 +3540,29 @@ to case differences." ...@@ -3540,18 +3540,29 @@ to case differences."
str2 0 (length str1) ignore-case))) str2 0 (length str1) ignore-case)))
(defun string-mark-left-to-right (str) (defun string-mark-left-to-right (str)
"Return a string that can be safely embedded in left-to-right text. "Return a string that can be safely inserted in left-to-right text.
If STR ends in right-to-left (RTL) script, return a string If STR contains right-to-left (RTL) script, return a string
consisting of STR followed by an invisible left-to-right consisting of STR followed by a terminating invisible
mark (LRM) character. Otherwise, return STR." 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."
(unless (stringp str) (unless (stringp str)
(signal 'wrong-type-argument (list 'stringp str))) (signal 'wrong-type-argument (list 'stringp str)))
(if (and (> (length str) 0) (let ((len (length str))
(eq (get-char-code-property (aref str (1- (length str))) (n 0)
'bidi-class) rtl-found)
'R)) (while (and (not rtl-found) (< n len))
(concat str (propertize (string ?\x200e) 'invisible t)) (setq rtl-found (memq (get-char-code-property
str)) (aref str n) 'bidi-class) '(R AL RLO))
n (1+ n)))
(if rtl-found
(concat str (propertize (string ?\x200e) 'invisible t))
str)))
;;;; invisibility specs ;;;; invisibility specs
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment