Initial Commit
[packages] / mule-packages / mule-base / texi / R2L.texi
1 \input texinfo  @c -*-texinfo-*-
2 @setfilename ../info/R2L
3 @settitle Right-to-left writing
4
5 @titlepage
6 @sp 6
7 @center @titlefont{Right-to-left writing}
8 @sp 4
9 @center Version 2.0
10 @sp 5
11 @center Ken'ichi HANDA
12 @center handa@@etl.go.jp
13 @page
14
15 @end titlepage
16
17 @comment ============================================================
18 @node Top, , , (mule)
19 @section Right-to-left writing
20
21   This document describes how Mule handles a text written from right to
22 left.
23
24 @menu
25 * Right-to-left Character Set::
26 * Direction of Buffer::
27 * Cursor Motion::
28 * LR Commands::
29 @ignore
30 * Double cursor::
31 * Highlighing::
32 * Visual inputting::
33 @end ignore
34 @end menu
35
36 @comment ============================================================
37 @node Right-to-left Character Set, Direction of Buffer, , Top
38 @section Right-to-left Character Set
39
40   In Mule, each character set has the attribute @dfn{direction}.  The
41 value is either 0 (l2r, left-to-right) or 1 (r2l, right-to-left).  For
42 the moment, Mule has four r2l character sets, namely, Hebrew
43 (ISO8859-8), ASCII-r2l (private) Arabic1 (private) and Arabic2
44 (private).  ASCII-r2l is for providing r2l space and punctuation
45 characters to Hebrew.  Consecutive r2l characters are shown from right
46 to left on the screen.
47
48 Hereafter, we denote r2l characters by capital letters and l2r
49 characters by lowercase letters in strings.  Punctuation marks (e.g.,
50 period) mean normal ASCII characters.  For r2l space and punctuations,
51 we use the letter @samp{_} (underscore).
52
53 @comment ============================================================
54 @node Direction of Buffer, Cursor Motion, Right-to-left character set, Top
55 @section Direction of buffer
56
57   Each buffer also has the attribute @dfn{direction} (buffer local
58 variable @code{display-direction}).  By default, the value is @code{nil}
59 (means l2r direction).  Provided that a buffer contains:
60
61 @example
62 this is a DESREVER word.
63 @end example
64
65   If @code{display-direction} is @code{nil} (this is the default), what
66 you see on your screen is:
67
68 @example
69 +---------------------------------+
70 |this is a DESREVER word.         |
71 |                                 |
72 +---------------------------------+
73 @end example
74
75 but, if the direction is non-@code{nil}, what you see is:
76
77 @example
78 +---------------------------------+
79 |          word.DESREVERthis is a |
80 |                                 |
81 +---------------------------------+
82 @end example
83
84   If you are in visual-mode, the value of @code{display-direction} is
85 reflected in the mode-line.  The string @samp{L2R} means
86 @code{display-direction} is @code{nil}; @samp{R2L} means non-@code{nil}.
87 In visual-mode, you can set @code{display-direction} to @code{nil} by
88 typing @kbd{C-c <}, and to @code{t} (this means non-@code{nil}) by
89 typing @kbd{C-c >}.
90
91   If you read a file that has the extension @file{.l2r}, the buffer
92 automatically turns into visual-mode and @code{display-direction} is set
93 to @code{nil}.  Likewise, if a file has the extension @file{.r2l}, the
94 buffer automatically goes in visual-mode and @code{display-direction} is
95 set to @code{t}.
96
97 @comment ============================================================
98 @node Cursor Motion, LR commands, Direction of Buffer, Top
99 @section Cursor Motion
100
101   If you are not in visual-mode and type @kbd{C-f} (or @kbd{M-x
102 forward-char}, the cursor moves as follows:
103
104 @example
105 |this is a DESREVER word.      |
106         ^
107 |this is a DESREVER word.      |
108          ^
109 |this is a DESREVER word.      |
110           ^
111 |this is a DESREVER word.      |
112                   ^
113 |this is a DESREVER word.      |
114                  ^
115 |this is a DESREVER word.      |
116                 ^
117 |this is a DESREVER word.      |
118                ^
119 |this is a DESREVER word.      |
120               ^
121 |this is a DESREVER word.      |
122              ^
123 |this is a DESREVER word.      |
124             ^
125 |this is a DESREVER word.      |
126            ^
127 |this is a DESREVER word.      |
128                    ^
129 |this is a DESREVER word.      |
130                     ^
131 |this is a DESREVER word.      |
132                      ^
133 @end example
134
135   This is rather complicated and misleading.  To avoid confusions, the
136 following cursor motion commands are prepared in visual-mode to handle
137 bi-directional texts easily.  All these commands accept an additional
138 prefix numeric argument.
139
140 @table @asis
141 @item @kbd{C-f} or @kbd{M-x visual-forward-char}
142 Move the cursor visually forward in characters.
143
144 @item @kbd{C-b} or @kbd{M-x visual-backward-char}
145 Move the cursor visually backward in characters.
146
147 @item @kbd{C-p}, @kbd{@key{UP}} or @kbd{M-x visual-previous-line}
148 Move the cursor up in lines.
149
150 @item @kbd{C-n}, @kbd{@key{DOWN}} or @kbd{M-x visual-next-line}
151 Move the cursor down in lines.
152
153 @item @kbd{C-a} or @kbd{M-x visual-beginning-of-line}
154 Move the cursor to the visual beginning of the current line.
155
156 @item @kbd{M-f} or @kbd{M-x visual-forward-word}
157 Move the cursor visually forward in words.
158
159 @item @kbd{M-b} or @kbd{M-x visual-backward-word}
160 Move the cursor visually backward in words.
161
162 @item @kbd{M-<}, @kbd{HOME} or @kbd{M-x visual-beginning-of-buffer}
163 Move the cursor to the visual beginning of the current buffer.
164
165 @item @kbd{M->}, @kbd{END} or @kbd{M-x visual-end-of-buffer}
166 Move the cursor to the visual end of the current buffer.
167 @end table
168
169   Note that ordinary cursor motion commands (@code{forward-char},
170 @code{backward-char}, etc.) behave according to the @dfn{logical order}
171 of the text, whilst the above commands behave according to the
172 @dfn{visual order}.  Compare the difference of the two @kbd{C-f}
173 commands.  (You can exit visual-mode by typing @kbd{C-c C-c}.)
174
175   Some of you may be confused by the words @dfn{forward} and
176 @dfn{backward}.  Here is a summary:
177
178 @example
179 display-direction       nil             non-nil
180 ------------------------------------------------
181 forward                 right           left
182 backward                left            right
183 @end example
184
185 @comment ============================================================
186 @node LR Commands, , Cursor Motion, Top
187 @section LR Commands
188
189   If you have been using Emacs or Mule for a long time, it is possible
190 that @kbd{C-b} and @dfn{move to left} are so strongly associated in your
191 mind that you want to move the cursor to left by @kbd{C-b} no matter how
192 @code{display-direction} is set.  Likewise, you may want to move the
193 cursor to the right, to the left-most column and to the right-most
194 column by @kbd{C-f}, @kbd{C-a} and @kbd{C-e}, respectively.
195
196   In such cases, include the following line in your @file{~/.emacs}
197 file:
198
199 @lisp
200 (setq visual-use-lr-commands t)
201 @end lisp
202
203   This lisp command enables so called @dfn{LR commands}.  LR commands
204 act according to the absolute screen direction (such as @dfn{left} or
205 @dfn{right}) rather than the relative direction (@dfn{forward} or
206 @dfn{backward}).
207
208 @table @asis
209 @item @kbd{C-b}, @kbd{@key{LEFT}} or @kbd{M-x visual-move-to-left-char}
210 Move the cursor to the left in characters.
211
212 @item @kbd{C-f}, @kbd{@key{RIGHT}} or @kbd{M-x visual-move-to-right-char}
213 Move the cursor to the right in characters.
214
215 @item @kbd{M-b}, @kbd{@key{M-LEFT}} or @kbd{M-x visual-move-to-left-word}
216 Move the cursor to the left in words.
217
218 @item @kbd{M-f}, @kbd{@key{M-RIGHT}} or @kbd{M-x visual-move-to-right-word}
219 Move the cursor to the right in words.
220
221 @item @kbd{C-a} or @kbd{M-x visual-left-end-of-line}
222 Move the cursor to the left-most column of the current line.
223
224 @item @kbd{C-e} or @kbd{M-x visual-right-end-of-line}
225 Move the cursor to the right-most column of the current line.
226 @end table
227
228   As a matter of fact, the four keys, @key{LEFT}, @key{RIGHT},
229 @key{M-LEFT} and @key{M-RIGHT} are active even though your
230 @file{~/.emacs} file does not contain the @code{setq} line above.  So if
231 you are confused, use the arrow keys.
232
233 @ignore
234
235 @node Double cursor, Highlighing, Direction of buffer, Top
236 @section Double cursor
237
238 If the value of 'r2l-double-cursor' is non-nil, when POINT
239 is in between r2l char and l2r (normal) char, two cursor are
240 displayed to denote insertion points for both types of
241 character.  For instance, in the above example, when you
242 move POINT forward one by one, the cursor changes as
243 follows:
244
245 @example
246         |this is a WERBEH word.      |
247                 ^
248         |this is a WERBEH word.      |
249                  ^
250         |this is a WERBEH word.      |
251                   ^     ^
252         |this is a WERBEH word.      |
253                        ^
254         |this is a WERBEH word.      |
255                       ^
256         |this is a WERBEH word.      |
257                      ^
258         |this is a WERBEH word.      |
259                     ^
260         |this is a WERBEH word.      |
261                    ^
262         |this is a WERBEH word.      |
263                    ^     ^
264         |this is a WERBEH word.      |
265                           ^
266 @end example
267
268 @node Highlighing, Visual inputting, Double cursor, Top
269 @section Highlighing characters of reverse direction
270
271 If the value of 'highlight-reverse-direction' is non-nil
272 (default), a character whose direction is different from
273 that of the current buffer is highlighted by gray-color (or
274 background mesh).
275
276 @node Visual inputting, , Highlighing, Top
277 @section Visual inputting
278
279 As mentioned above, cursor motion in r2l text is rather complicated.
280 Further, even with the double cursor function, you may need some time
281 to learn inserting/deleting characters in an r2l text.
282
283 To faciliate the manipulation of r2l texts, quail provides a set of
284 functions which make cursor motion and insertion/deletion behave as
285 you expect.
286
287         visually-forward-char         
288           Function: Move cursor visually forward by ARG chars.
289         
290         visually-backward-char        
291           Function: Move cursor visually backward by ARG chars.
292         
293         visually-beginning-of-line    
294           Function: Move cursor to the visually beginning of line.
295         
296         visually-insert-char          
297           Function: With argument CH, call VISUALLY-INSERT-CHAR ARG times.
298         
299         visually-backward-delete-char 
300           Function: Delete ARG chars visually before cursor.
301         
302         visually-delete-char          
303           Function: Delete ARG chars under cursor.
304
305  These functions behave as if the whole buffer were filled with
306 characters of same direction: for example, when the buffer direction
307 is l2r, visually-forward-char moves the cursor to the right (or left,
308 if the buffer direction is r2l) step by step; visually-insert-char
309 puts the typed character just under the cursor and moves the cursor to
310 the right (left) by one column; visually-backward-delete-char removes
311 the character left (right) to the cursor, etc.
312
313 In quail/hebrew.el these visual functions are called via appropriate
314 quail cursor motion functions.  As quail cursor motion functions are
315 bound to appropriate keys, you will not be puzzled by the complicated
316 cursor behaviours as long as you use the hebrew package of quail-mode.
317
318 @end ignore
319
320 @contents
321 @bye