diff options
author | Eli Zaretskii <eliz@gnu.org> | 2013-06-29 16:36:19 +0300 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2013-06-29 16:36:19 +0300 |
commit | 4c672a0fec1d18cc1a445acf3e6935d681d4048f (patch) | |
tree | c8fb2626c93a226bed5eaa0b92f95925734e893f /lisp | |
parent | 73b1b3ad6196234984a29298bc66eabf1299de66 (diff) | |
download | emacs-4c672a0fec1d18cc1a445acf3e6935d681d4048f.tar.gz |
Implement visual-order cursor motion.
src/xdisp.c (Fmove_point_visually): New function.
lisp/bindings.el (visual-order-cursor-movement): New defcustom.
(right-char, left-char): Provide visual-order cursor motion by
calling move-point-visually. Update the doc strings.
doc/emacs/basic.texi (Moving Point): Document visual-order-cursor-movement
and its effect on right-char and left-char.
doc/lispref/display.texi (Bidirectional Display): Document move-point-visually.
etc/NEWS: Document the new feature.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/ChangeLog | 6 | ||||
-rw-r--r-- | lisp/bindings.el | 58 |
2 files changed, 52 insertions, 12 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 826f270d8f8..1e1fff6fc25 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2013-06-29 Eli Zaretskii <eliz@gnu.org> + + * bindings.el (visual-order-cursor-movement): New defcustom. + (right-char, left-char): Provide visual-order cursor motion by + calling move-point-visually. Update the doc strings. + 2013-06-28 Kenichi Handa <handa@gnu.org> * international/mule.el (define-coding-system): New coding system diff --git a/lisp/bindings.el b/lisp/bindings.el index 2013c079820..7c42cc6c0a8 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -696,29 +696,63 @@ language you are using." (put 'narrow-to-region 'disabled t) ;; Moving with arrows in bidi-sensitive direction. +(defcustom visual-order-cursor-movement nil + "If non-nil, moving cursor with arrow keys follows the visual order. + +When this is non-nil, \\[right-char] will move to the character that is +to the right of point on display, and \\[left-char] will move to the left, +disregarding the surrounding bidirectional context. Depending on the +bidirectional context of the surrounding characters, this can move point +many buffer positions away. + +When the text is entirely left-to-right, logical-order and visual-order +cursor movements produce identical results." + :type '(choice (const :tag "Logical-order cursor movement" nil) + (const :tag "Visual-order cursor movement" t)) + :group 'display + :version "24.5") + (defun right-char (&optional n) "Move point N characters to the right (to the left if N is negative). On reaching beginning or end of buffer, stop and signal error. -Depending on the bidirectional context, this may move either forward -or backward in the buffer. This is in contrast with \\[forward-char] -and \\[backward-char], which see." +If `visual-order-cursor-movement' is non-nil, this always moves +to the right on display, wherever that is in the buffer. +Otherwise, depending on the bidirectional context, this may move +one position either forward or backward in the buffer. This is +in contrast with \\[forward-char] and \\[backward-char], which +see." (interactive "^p") - (if (eq (current-bidi-paragraph-direction) 'left-to-right) - (forward-char n) - (backward-char n))) + (if visual-order-cursor-movement + (dotimes (i (if (numberp n) (abs n) 1)) + (if (< n 0) + (move-point-visually -1) + (move-point-visually 1)) + (sit-for 0)) + (if (eq (current-bidi-paragraph-direction) 'left-to-right) + (forward-char n) + (backward-char n)))) (defun left-char ( &optional n) "Move point N characters to the left (to the right if N is negative). On reaching beginning or end of buffer, stop and signal error. -Depending on the bidirectional context, this may move either backward -or forward in the buffer. This is in contrast with \\[backward-char] -and \\[forward-char], which see." +If `visual-order-cursor-movement' is non-nil, this always moves +to the left on display, wherever that is in the buffer. +Otherwise, depending on the bidirectional context, this may move +one position either backward or forward in the buffer. This is +in contrast with \\[forward-char] and \\[backward-char], which +see." (interactive "^p") - (if (eq (current-bidi-paragraph-direction) 'left-to-right) - (backward-char n) - (forward-char n))) + (if visual-order-cursor-movement + (dotimes (i (if (numberp n) (abs n) 1)) + (if (< n 0) + (move-point-visually 1) + (move-point-visually -1)) + (sit-for 0)) + (if (eq (current-bidi-paragraph-direction) 'left-to-right) + (backward-char n) + (forward-char n)))) (defun right-word (&optional n) "Move point N words to the right (to the left if N is negative). |