From: Chong Yidong Date: Wed, 10 Aug 2011 19:03:56 +0000 (-0400) Subject: New function `string-mark-left-to-right' for handling LRMs. X-Git-Tag: emacs-pretest-24.0.90~104^2~124^2~62^2~12 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3e26a4a28c6ad382f3bea07a1a6e0175ed8acdc6;p=emacs.git New function `string-mark-left-to-right' for handling LRMs. * lisp/subr.el (string-mark-left-to-right): New function. * lisp/buff-menu.el (Buffer-menu-buffer+size): Remove LRM argument. Use string-mark-left-to-right. (list-buffers-noselect): Caller changed. * lisp/emacs-lisp/tabulated-list.el (tabulated-list-print-entry): Use string-mark-left-to-right. (tabulated-list-print): Recenter after moving point. --- diff --git a/etc/NEWS b/etc/NEWS index 6a1bb6c1c5e..6f8c125f7f9 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1038,6 +1038,12 @@ of function value which looks like (closure ENV ARGS &rest BODY). *** New function `special-variable-p' to check whether a variable is declared as dynamically bound. +** New function `string-mark-left-to-right' appends a Unicode LRM +(left-to-right mark) character to a string if it terminates in +right-to-left script. This is useful when the buffer has overall +left-to-right 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. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 780ea61a7ac..ad300b10f47 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,15 @@ +2011-08-10 Chong Yidong + + * subr.el (string-mark-left-to-right): New function. + + * buff-menu.el (Buffer-menu-buffer+size): Remove LRM argument. + Use string-mark-left-to-right. + (list-buffers-noselect): Caller changed. + + * emacs-lisp/tabulated-list.el (tabulated-list-print-entry): Use + string-mark-left-to-right. + (tabulated-list-print): Recenter after moving point. + 2011-08-10 Juri Linkov * progmodes/grep.el (rgrep): Don't bind `process-connection-type'. diff --git a/lisp/buff-menu.el b/lisp/buff-menu.el index f0a44747378..a5b45921d28 100644 --- a/lisp/buff-menu.el +++ b/lisp/buff-menu.el @@ -666,7 +666,7 @@ For more information, see the function `buffer-menu'." ":" ;; (if (char-displayable-p ?…) "…" ":") ) -(defun Buffer-menu-buffer+size (name size &optional name-props size-props lrm) +(defun Buffer-menu-buffer+size (name size &optional name-props size-props) (if (> (+ (string-width name) (string-width size) 2) Buffer-menu-buffer+size-width) (setq name @@ -681,17 +681,9 @@ For more information, see the function `buffer-menu'." (string-width tail) 2)) Buffer-menu-short-ellipsis - tail - ;; Append an invisible LRM character to the - ;; buffer's name to avoid ugly display with the - ;; buffer size to the left of the name, when the - ;; name begins with R2L character. - (if lrm (propertize (string ?\x200e) 'invisible t) "")))) + (string-mark-left-to-right tail)))) ;; Don't put properties on (buffer-name). - (setq name (concat (copy-sequence name) - (if lrm - (propertize (string ?\x200e) 'invisible t) - "")))) + (setq name (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 @@ -929,8 +921,7 @@ For more information, see the function `buffer-menu'." (max (length size) 3) 2)) name - "mouse-2: select this buffer")) - nil t)) + "mouse-2: select this buffer")))) " " (if (> (string-width (nth 4 buffer)) Buffer-menu-mode-width) (truncate-string-to-width (nth 4 buffer) diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el index 2fdfa9525b1..9b485b58608 100644 --- a/lisp/emacs-lisp/tabulated-list.el +++ b/lisp/emacs-lisp/tabulated-list.el @@ -258,7 +258,8 @@ to the entry with the same ID element as the current line." ;; If REMEMBER-POS was specified, move to the "old" location. (if saved-pt (progn (goto-char saved-pt) - (move-to-column saved-col)) + (move-to-column saved-col) + (recenter)) (goto-char (point-min))))) (defun tabulated-list-print-entry (id cols) @@ -282,6 +283,7 @@ of column descriptors." (> (length label) width) (setq label (concat (substring label 0 (- width 3)) "..."))) + (setq label (string-mark-left-to-right label)) (if (stringp desc) (insert (propertize label 'help-echo help-echo)) (apply 'insert-text-button label (cdr desc))) diff --git a/lisp/subr.el b/lisp/subr.el index d57c507a548..a897da1d9ba 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3538,6 +3538,20 @@ If IGNORE-CASE is non-nil, the comparison is done without paying attention to case differences." (eq t (compare-strings str1 nil nil str2 0 (length str1) ignore-case))) + +(defun string-mark-left-to-right (str) + "Return a string that can be safely embedded in left-to-right text. +If STR ends in right-to-left (RTL) script, return a string +consisting of STR followed by an invisible left-to-right +mark (LRM) character. Otherwise, return STR." + (unless (stringp str) + (signal 'wrong-type-argument (list 'stringp str))) + (if (and (> (length str) 0) + (eq (get-char-code-property (aref str (1- (length str))) + 'bidi-class) + 'R)) + (concat str (propertize (string ?\x200e) 'invisible t)) + str)) ;;;; invisibility specs