diff options
| author | Chong Yidong | 2011-08-12 11:43:30 -0400 |
|---|---|---|
| committer | Chong Yidong | 2011-08-12 11:43:30 -0400 |
| commit | 9ccaaa4be77d1698784cceb983ef987cc80212c2 (patch) | |
| tree | 4b9f4e801d8a5069933a3b2bad23d3e62cdb0c60 | |
| parent | 6cd18349b892a5c432991e8231364e7a4d1ea33d (diff) | |
| download | emacs-9ccaaa4be77d1698784cceb983ef987cc80212c2.tar.gz emacs-9ccaaa4be77d1698784cceb983ef987cc80212c2.zip | |
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.
| -rw-r--r-- | etc/NEWS | 14 | ||||
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/subr.el | 31 |
3 files changed, 35 insertions, 15 deletions
| @@ -1038,11 +1038,15 @@ of function value which looks like (closure ENV ARGS &rest BODY). | |||
| 1038 | *** New function `special-variable-p' to check whether a variable is | 1038 | *** New function `special-variable-p' to check whether a variable is |
| 1039 | declared as dynamically bound. | 1039 | declared as dynamically bound. |
| 1040 | 1040 | ||
| 1041 | ** New function `string-mark-left-to-right' appends a Unicode LRM | 1041 | ** New function `string-mark-left-to-right'. |
| 1042 | (left-to-right mark) character to a string if it terminates in | 1042 | Given a string containing right-to-left (RTL) script, this function |
| 1043 | right-to-left script. This is useful when the buffer has overall | 1043 | returns another string with a terminating LRM (left-to-right mark) |
| 1044 | left-to-right paragraph direction and you need to insert a string | 1044 | character. If this string is inserted into a buffer, Emacs treats the |
| 1045 | whose contents (and directionality) are not known in advance. | 1045 | LRM as the end of an RTL segment and displays following text as LTR. |
| 1046 | |||
| 1047 | This is useful when the buffer has overall left-to-right (LTR) | ||
| 1048 | paragraph direction and you need to insert a string whose contents | ||
| 1049 | (and hence directionality) are not known in advance. | ||
| 1046 | 1050 | ||
| 1047 | ** pre/post-command-hook are not reset to nil upon error. | 1051 | ** pre/post-command-hook are not reset to nil upon error. |
| 1048 | Instead, the offending function is removed. | 1052 | Instead, the offending function is removed. |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index bde9d54cfa2..b9cf5367bf0 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2011-08-12 Chong Yidong <cyd@stupidchicken.com> | ||
| 2 | |||
| 3 | * subr.el (string-mark-left-to-right): Search the entire string | ||
| 4 | for RTL script, not just the terminating character. Doc fix. | ||
| 5 | |||
| 1 | 2011-08-12 Stefan Monnier <monnier@iro.umontreal.ca> | 6 | 2011-08-12 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 7 | ||
| 3 | * progmodes/js.el (js-syntax-propertize, js-syntax-propertize-regexp): | 8 | * progmodes/js.el (js-syntax-propertize, js-syntax-propertize-regexp): |
diff --git a/lisp/subr.el b/lisp/subr.el index a897da1d9ba..a4251b6fee6 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -3540,18 +3540,29 @@ to case differences." | |||
| 3540 | str2 0 (length str1) ignore-case))) | 3540 | str2 0 (length str1) ignore-case))) |
| 3541 | 3541 | ||
| 3542 | (defun string-mark-left-to-right (str) | 3542 | (defun string-mark-left-to-right (str) |
| 3543 | "Return a string that can be safely embedded in left-to-right text. | 3543 | "Return a string that can be safely inserted in left-to-right text. |
| 3544 | If STR ends in right-to-left (RTL) script, return a string | 3544 | If STR contains right-to-left (RTL) script, return a string |
| 3545 | consisting of STR followed by an invisible left-to-right | 3545 | consisting of STR followed by a terminating invisible |
| 3546 | mark (LRM) character. Otherwise, return STR." | 3546 | left-to-right mark (LRM) character. |
| 3547 | |||
| 3548 | The LRM character marks the end of an RTL segment, and resets the | ||
| 3549 | display direction of any subsequent text to left-to-right. | ||
| 3550 | \(Otherwise, some of that text might be displayed as part of the | ||
| 3551 | RTL segment, based on the bidirectional display algorithm.) | ||
| 3552 | |||
| 3553 | If STR contains no RTL characters, return STR." | ||
| 3547 | (unless (stringp str) | 3554 | (unless (stringp str) |
| 3548 | (signal 'wrong-type-argument (list 'stringp str))) | 3555 | (signal 'wrong-type-argument (list 'stringp str))) |
| 3549 | (if (and (> (length str) 0) | 3556 | (let ((len (length str)) |
| 3550 | (eq (get-char-code-property (aref str (1- (length str))) | 3557 | (n 0) |
| 3551 | 'bidi-class) | 3558 | rtl-found) |
| 3552 | 'R)) | 3559 | (while (and (not rtl-found) (< n len)) |
| 3553 | (concat str (propertize (string ?\x200e) 'invisible t)) | 3560 | (setq rtl-found (memq (get-char-code-property |
| 3554 | str)) | 3561 | (aref str n) 'bidi-class) '(R AL RLO)) |
| 3562 | n (1+ n))) | ||
| 3563 | (if rtl-found | ||
| 3564 | (concat str (propertize (string ?\x200e) 'invisible t)) | ||
| 3565 | str))) | ||
| 3555 | 3566 | ||
| 3556 | ;;;; invisibility specs | 3567 | ;;;; invisibility specs |
| 3557 | 3568 | ||