1eaa18b4d465fb1c1b39d93410e7dea65ca353aa
[chise/xemacs-chise.git.1] / man / xemacs / mule.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1997 Free Software Foundation, Inc.
3 @c See file emacs.texi for copying conditions.
4 @node Mule, Major Modes, Windows, Top
5 @chapter World Scripts Support
6 @cindex MULE
7 @cindex international scripts
8 @cindex multibyte characters
9 @cindex encoding of characters
10
11 @cindex Chinese
12 @cindex Greek
13 @cindex IPA
14 @cindex Japanese
15 @cindex Korean
16 @cindex Russian
17   If you compile XEmacs with mule option, it supports a wide variety of
18 world scripts, including Latin script, as well as Arabic script,
19 Simplified Chinese script (for mainland of China), Traditional Chinese
20 script (for Taiwan and Hong-Kong), Greek script, Hebrew script, IPA
21 symbols, Japanese scripts (Hiragana, Katakana and Kanji), Korean scripts
22 (Hangul and Hanja) and Cyrillic script (for Byelorussian, Bulgarian,
23 Russian, Serbian and Ukrainian).  These features have been merged from
24 the modified version of Emacs known as MULE (for ``MULti-lingual
25 Enhancement to GNU Emacs'').
26
27 @menu
28 * Mule Intro::              Basic concepts of Mule.
29 * Language Environments::   Setting things up for the language you use.
30 * Input Methods::           Entering text characters not on your keyboard.
31 * Select Input Method::     Specifying your choice of input methods.
32 * Coding Systems::          Character set conversion when you read and
33                               write files, and so on.
34 * Recognize Coding::        How XEmacs figures out which conversion to use.
35 * Specify Coding::          Various ways to choose which conversion to use.
36 @end menu
37
38 @node Mule Intro, Language Environments, Mule, Mule
39 @section Introduction to world scripts
40
41   The users of these scripts have established many more-or-less standard
42 coding systems for storing files.
43 @c XEmacs internally uses a single multibyte character encoding, so that it
44 @c can intermix characters from all these scripts in a single buffer or
45 @c string.  This encoding represents each non-ASCII character as a sequence
46 @c of bytes in the range 0200 through 0377.
47 XEmacs translates between the internal character encoding and various
48 other coding systems when reading and writing files, when exchanging
49 data with subprocesses, and (in some cases) in the @kbd{C-q} command
50 (see below).
51
52 @kindex C-h h
53 @findex view-hello-file
54   The command @kbd{C-h h} (@code{view-hello-file}) displays the file
55 @file{etc/HELLO}, which shows how to say ``hello'' in many languages.
56 This illustrates various scripts.
57
58   Keyboards, even in the countries where these character sets are used,
59 generally don't have keys for all the characters in them.  So XEmacs
60 supports various @dfn{input methods}, typically one for each script or
61 language, to make it convenient to type them.
62
63 @kindex C-x RET
64   The prefix key @kbd{C-x @key{RET}} is used for commands that pertain
65 to world scripts, coding systems, and input methods.
66
67
68 @node Language Environments, Input Methods, Mule Intro, Mule
69 @section Language Environments
70 @cindex language environments
71
72   All supported character sets are supported in XEmacs buffers if it is
73 compile with mule; there is no need to select a particular language in
74 order to display its characters in an XEmacs buffer.  However, it is
75 important to select a @dfn{language environment} in order to set various
76 defaults.  The language environment really represents a choice of
77 preferred script (more or less) rather that a choice of language.
78
79   The language environment controls which coding systems to recognize
80 when reading text (@pxref{Recognize Coding}).  This applies to files,
81 incoming mail, netnews, and any other text you read into XEmacs.  It may
82 also specify the default coding system to use when you create a file.
83 Each language environment also specifies a default input method.
84
85 @findex set-language-environment
86   The command to select a language environment is @kbd{M-x
87 set-language-environment}.  It makes no difference which buffer is
88 current when you use this command, because the effects apply globally to
89 the XEmacs session.  The supported language environments include:
90
91 @quotation
92 Chinese-BIG5, Chinese-CNS, Chinese-GB, Cyrillic-ISO, English, Ethiopic,
93 Greek, Japanese, Korean, Latin-1, Latin-2, Latin-3, Latin-4, Latin-5.
94 @end quotation
95
96   Some operating systems let you specify the language you are using by
97 setting locale environment variables.  XEmacs handles one common special
98 case of this: if your locale name for character types contains the
99 string @samp{8859-@var{n}}, XEmacs automatically selects the
100 corresponding language environment.
101
102 @kindex C-h L
103 @findex describe-language-environment
104   To display information about the effects of a certain language
105 environment @var{lang-env}, use the command @kbd{C-h L @var{lang-env}
106 @key{RET}} (@code{describe-language-environment}).  This tells you which
107 languages this language environment is useful for, and lists the
108 character sets, coding systems, and input methods that go with it.  It
109 also shows some sample text to illustrate scripts used in this language
110 environment.  By default, this command describes the chosen language
111 environment.
112
113 @node Input Methods, Select Input Method, Language Environments, Mule
114 @section Input Methods
115
116 @cindex input methods
117   An @dfn{input method} is a kind of character conversion designed
118 specifically for interactive input.  In XEmacs, typically each language
119 has its own input method; sometimes several languages which use the same
120 characters can share one input method.  A few languages support several
121 input methods.
122
123   The simplest kind of input method works by mapping ASCII letters into
124 another alphabet.  This is how the Greek and Russian input methods work.
125
126   A more powerful technique is composition: converting sequences of
127 characters into one letter.  Many European input methods use composition
128 to produce a single non-ASCII letter from a sequence that consists of a
129 letter followed by accent characters.  For example, some methods convert
130 the sequence @kbd{'a} into a single accented letter.
131
132   The input methods for syllabic scripts typically use mapping followed
133 by composition.  The input methods for Thai and Korean work this way.
134 First, letters are mapped into symbols for particular sounds or tone
135 marks; then, sequences of these which make up a whole syllable are
136 mapped into one syllable sign.
137
138   Chinese and Japanese require more complex methods.  In Chinese input
139 methods, first you enter the phonetic spelling of a Chinese word (in
140 input method @code{chinese-py}, among others), or a sequence of portions
141 of the character (input methods @code{chinese-4corner} and
142 @code{chinese-sw}, and others).  Since one phonetic spelling typically
143 corresponds to many different Chinese characters, you must select one of
144 the alternatives using special XEmacs commands.  Keys such as @kbd{C-f},
145 @kbd{C-b}, @kbd{C-n}, @kbd{C-p}, and digits have special definitions in
146 this situation, used for selecting among the alternatives.  @key{TAB}
147 displays a buffer showing all the possibilities.
148
149    In Japanese input methods, first you input a whole word using
150 phonetic spelling; then, after the word is in the buffer, XEmacs
151 converts it into one or more characters using a large dictionary.  One
152 phonetic spelling corresponds to many differently written Japanese
153 words, so you must select one of them; use @kbd{C-n} and @kbd{C-p} to
154 cycle through the alternatives.
155
156   Sometimes it is useful to cut off input method processing so that the
157 characters you have just entered will not combine with subsequent
158 characters.  For example, in input method @code{latin-1-postfix}, the
159 sequence @kbd{e '} combines to form an @samp{e} with an accent.  What if
160 you want to enter them as separate characters?
161
162   One way is to type the accent twice; that is a special feature for
163 entering the separate letter and accent.  For example, @kbd{e ' '} gives
164 you the two characters @samp{e'}.  Another way is to type another letter
165 after the @kbd{e}---something that won't combine with that---and
166 immediately delete it.  For example, you could type @kbd{e e @key{DEL}
167 '} to get separate @samp{e} and @samp{'}.
168
169   Another method, more general but not quite as easy to type, is to use
170 @kbd{C-\ C-\} between two characters to stop them from combining.  This
171 is the command @kbd{C-\} (@code{toggle-input-method}) used twice.
172 @ifinfo
173 @xref{Select Input Method}.
174 @end ifinfo
175
176   @kbd{C-\ C-\} is especially useful inside an incremental search,
177 because stops waiting for more characters to combine, and starts
178 searching for what you have already entered.
179
180 @vindex input-method-verbose-flag
181 @vindex input-method-highlight-flag
182   The variables @code{input-method-highlight-flag} and
183 @code{input-method-verbose-flag} control how input methods explain what
184 is happening.  If @code{input-method-highlight-flag} is non-@code{nil},
185 the partial sequence is highlighted in the buffer.  If
186 @code{input-method-verbose-flag} is non-@code{nil}, the list of possible
187 characters to type next is displayed in the echo area (but not when you
188 are in the minibuffer).
189
190 @node Select Input Method, Coding Systems, Input Methods, Mule
191 @section Selecting an Input Method
192
193 @table @kbd
194 @item C-\
195 Enable or disable use of the selected input method.
196
197 @item C-x @key{RET} C-\ @var{method} @key{RET}
198 Select a new input method for the current buffer.
199
200 @item C-h I @var{method} @key{RET}
201 @itemx C-h C-\ @var{method} @key{RET}
202 @findex describe-input-method
203 @kindex C-h I
204 @kindex C-h C-\
205 Describe the input method @var{method} (@code{describe-input-method}).
206 By default, it describes the current input method (if any).
207
208 @item M-x list-input-methods
209 Display a list of all the supported input methods.
210 @end table
211
212 @findex select-input-method
213 @vindex current-input-method
214 @kindex C-x RET C-\
215   To choose an input method for the current buffer, use @kbd{C-x
216 @key{RET} C-\} (@code{select-input-method}).  This command reads the
217 input method name with the minibuffer; the name normally starts with the
218 language environment that it is meant to be used with.  The variable
219 @code{current-input-method} records which input method is selected.
220   
221 @findex toggle-input-method
222 @kindex C-\
223   Input methods use various sequences of ASCII characters to stand for
224 non-ASCII characters.  Sometimes it is useful to turn off the input
225 method temporarily.  To do this, type @kbd{C-\}
226 (@code{toggle-input-method}).  To reenable the input method, type
227 @kbd{C-\} again.
228
229   If you type @kbd{C-\} and you have not yet selected an input method,
230 it prompts for you to specify one.  This has the same effect as using
231 @kbd{C-x @key{RET} C-\} to specify an input method.
232
233 @vindex default-input-method
234   Selecting a language environment specifies a default input method for
235 use in various buffers.  When you have a default input method, you can
236 select it in the current buffer by typing @kbd{C-\}.  The variable
237 @code{default-input-method} specifies the default input method
238 (@code{nil} means there is none).
239
240 @findex quail-set-keyboard-layout
241   Some input methods for alphabetic scripts work by (in effect)
242 remapping the keyboard to emulate various keyboard layouts commonly used
243 for those scripts.  How to do this remapping properly depends on your
244 actual keyboard layout.  To specify which layout your keyboard has, use
245 the command @kbd{M-x quail-set-keyboard-layout}.
246
247 @findex list-input-methods
248   To display a list of all the supported input methods, type @kbd{M-x
249 list-input-methods}.  The list gives information about each input
250 method, including the string that stands for it in the mode line.
251
252 @node Coding Systems, Recognize Coding, Select Input Method, Mule
253 @section Coding Systems
254 @cindex coding systems
255
256   Users of various languages have established many more-or-less standard
257 coding systems for representing them.  XEmacs does not use these coding
258 systems internally; instead, it converts from various coding systems to
259 its own system when reading data, and converts the internal coding
260 system to other coding systems when writing data.  Conversion is
261 possible in reading or writing files, in sending or receiving from the
262 terminal, and in exchanging data with subprocesses.
263
264   XEmacs assigns a name to each coding system.  Most coding systems are
265 used for one language, and the name of the coding system starts with the
266 language name.  Some coding systems are used for several languages;
267 their names usually start with @samp{iso}.  There are also special
268 coding systems @code{binary} and @code{no-conversion} which do not
269 convert printing characters at all.
270
271   In addition to converting various representations of non-ASCII
272 characters, a coding system can perform end-of-line conversion.  XEmacs
273 handles three different conventions for how to separate lines in a file:
274 newline, carriage-return linefeed, and just carriage-return.
275
276 @table @kbd
277 @item C-h C @var{coding} @key{RET}
278 Describe coding system @var{coding}.
279
280 @item C-h C @key{RET}
281 Describe the coding systems currently in use.
282
283 @item M-x list-coding-systems
284 Display a list of all the supported coding systems.
285 @end table
286
287 @kindex C-h C
288 @findex describe-coding-system
289   The command @kbd{C-h C} (@code{describe-coding-system}) displays
290 information about particular coding systems.  You can specify a coding
291 system name as argument; alternatively, with an empty argument, it
292 describes the coding systems currently selected for various purposes,
293 both in the current buffer and as the defaults, and the priority list
294 for recognizing coding systems (@pxref{Recognize Coding}).
295
296 @findex list-coding-systems
297   To display a list of all the supported coding systems, type @kbd{M-x
298 list-coding-systems}.  The list gives information about each coding
299 system, including the letter that stands for it in the mode line
300 (@pxref{Mode Line}).
301
302   Each of the coding systems that appear in this list---except for
303 @code{binary}, which means no conversion of any kind---specifies how and
304 whether to convert printing characters, but leaves the choice of
305 end-of-line conversion to be decided based on the contents of each file.
306 For example, if the file appears to use carriage-return linefeed between
307 lines, that end-of-line conversion will be used.
308
309   Each of the listed coding systems has three variants which specify
310 exactly what to do for end-of-line conversion:
311
312 @table @code
313 @item @dots{}-unix
314 Don't do any end-of-line conversion; assume the file uses
315 newline to separate lines.  (This is the convention normally used
316 on Unix and GNU systems.)
317
318 @item @dots{}-dos
319 Assume the file uses carriage-return linefeed to separate lines,
320 and do the appropriate conversion.  (This is the convention normally used
321 on Microsoft systems.)
322
323 @item @dots{}-mac
324 Assume the file uses carriage-return to separate lines, and do the
325 appropriate conversion.  (This is the convention normally used on the
326 Macintosh system.)
327 @end table
328
329   These variant coding systems are omitted from the
330 @code{list-coding-systems} display for brevity, since they are entirely
331 predictable.  For example, the coding system @code{iso-8859-1} has
332 variants @code{iso-8859-1-unix}, @code{iso-8859-1-dos} and
333 @code{iso-8859-1-mac}.
334
335   In contrast, the coding system @code{binary} specifies no character
336 code conversion at all---none for non-Latin-1 byte values and none for
337 end of line.  This is useful for reading or writing binary files, tar
338 files, and other files that must be examined verbatim.
339
340   The easiest way to edit a file with no conversion of any kind is with
341 the @kbd{M-x find-file-literally} command.  This uses @code{binary}, and
342 also suppresses other XEmacs features that might convert the file
343 contents before you see them.  @xref{Visiting}.
344
345   The coding system @code{no-conversion} means that the file contains
346 non-Latin-1 characters stored with the internal XEmacs encoding.  It
347 handles end-of-line conversion based on the data encountered, and has
348 the usual three variants to specify the kind of end-of-line conversion.
349
350
351 @node Recognize Coding, Specify Coding, Coding Systems, Mule
352 @section Recognizing Coding Systems
353
354   Most of the time, XEmacs can recognize which coding system to use for
355 any given file--once you have specified your preferences.
356
357   Some coding systems can be recognized or distinguished by which byte
358 sequences appear in the data.  However, there are coding systems that
359 cannot be distinguished, not even potentially.  For example, there is no
360 way to distinguish between Latin-1 and Latin-2; they use the same byte
361 values with different meanings.
362
363   XEmacs handles this situation by means of a priority list of coding
364 systems.  Whenever XEmacs reads a file, if you do not specify the coding
365 system to use, XEmacs checks the data against each coding system,
366 starting with the first in priority and working down the list, until it
367 finds a coding system that fits the data.  Then it converts the file
368 contents assuming that they are represented in this coding system.
369
370   The priority list of coding systems depends on the selected language
371 environment (@pxref{Language Environments}).  For example, if you use
372 French, you probably want XEmacs to prefer Latin-1 to Latin-2; if you
373 use Czech, you probably want Latin-2 to be preferred.  This is one of
374 the reasons to specify a language environment.
375
376 @findex prefer-coding-system
377   However, you can alter the priority list in detail with the command
378 @kbd{M-x prefer-coding-system}.  This command reads the name of a coding
379 system from the minibuffer, and adds it to the front of the priority
380 list, so that it is preferred to all others.  If you use this command
381 several times, each use adds one element to the front of the priority
382 list.
383
384 @vindex file-coding-system-alist
385   Sometimes a file name indicates which coding system to use for the
386 file.  The variable @code{file-coding-system-alist} specifies this
387 correspondence.  There is a special function
388 @code{modify-coding-system-alist} for adding elements to this list.  For
389 example, to read and write all @samp{.txt} using the coding system
390 @code{china-iso-8bit}, you can execute this Lisp expression:
391
392 @smallexample
393 (modify-coding-system-alist 'file "\\.txt\\'" 'china-iso-8bit)
394 @end smallexample
395
396 @noindent
397 The first argument should be @code{file}, the second argument should be
398 a regular expression that determines which files this applies to, and
399 the third argument says which coding system to use for these files.
400
401 @vindex coding
402   You can specify the coding system for a particular file using the
403 @samp{-*-@dots{}-*-} construct at the beginning of a file, or a local
404 variables list at the end (@pxref{File Variables}).  You do this by
405 defining a value for the ``variable'' named @code{coding}.  XEmacs does
406 not really have a variable @code{coding}; instead of setting a variable,
407 it uses the specified coding system for the file.  For example,
408 @samp{-*-mode: C; coding: iso-8859-1;-*-} specifies use of the
409 iso-8859-1 coding system, as well as C mode.
410
411 @vindex buffer-file-coding-system
412   Once XEmacs has chosen a coding system for a buffer, it stores that
413 coding system in @code{buffer-file-coding-system} and uses that coding
414 system, by default, for operations that write from this buffer into a
415 file.  This includes the commands @code{save-buffer} and
416 @code{write-region}.  If you want to write files from this buffer using
417 a different coding system, you can specify a different coding system for
418 the buffer using @code{set-buffer-file-coding-system} (@pxref{Specify
419 Coding}).
420
421
422 @node Specify Coding,  , Recognize Coding, Mule
423 @section Specifying a Coding System
424
425   In cases where XEmacs does not automatically choose the right coding
426 system, you can use these commands to specify one:
427
428 @table @kbd
429 @item C-x @key{RET} f @var{coding} @key{RET}
430 Use coding system @var{coding} for the visited file
431 in the current buffer.
432
433 @item C-x @key{RET} c @var{coding} @key{RET}
434 Specify coding system @var{coding} for the immediately following
435 command.
436
437 @item C-x @key{RET} k @var{coding} @key{RET}
438 Use coding system @var{coding} for keyboard input.
439
440 @item C-x @key{RET} t @var{coding} @key{RET}
441 Use coding system @var{coding} for terminal output.
442
443 @item C-x @key{RET} p @var{coding} @key{RET}
444 Use coding system @var{coding} for subprocess input and output
445 in the current buffer.
446 @end table
447
448 @kindex C-x RET f
449 @findex set-buffer-file-coding-system
450   The command @kbd{C-x RET f} (@code{set-buffer-file-coding-system})
451 specifies the file coding system for the current buffer---in other
452 words, which coding system to use when saving or rereading the visited
453 file.  You specify which coding system using the minibuffer.  Since this
454 command applies to a file you have already visited, it affects only the
455 way the file is saved.
456
457 @kindex C-x RET c
458 @findex universal-coding-system-argument
459   Another way to specify the coding system for a file is when you visit
460 the file.  First use the command @kbd{C-x @key{RET} c}
461 (@code{universal-coding-system-argument}); this command uses the
462 minibuffer to read a coding system name.  After you exit the minibuffer,
463 the specified coding system is used for @emph{the immediately following
464 command}.
465
466   So if the immediately following command is @kbd{C-x C-f}, for example,
467 it reads the file using that coding system (and records the coding
468 system for when the file is saved).  Or if the immediately following
469 command is @kbd{C-x C-w}, it writes the file using that coding system.
470 Other file commands affected by a specified coding system include
471 @kbd{C-x C-i} and @kbd{C-x C-v}, as well as the other-window variants of
472 @kbd{C-x C-f}.
473
474   In addition, if you run some file input commands with the precedent
475 @kbd{C-u}, you can specify coding system to read from minibuffer.  So if
476 the immediately following command is @kbd{C-x C-f}, for example, it
477 reads the file using that coding system (and records the coding system
478 for when the file is saved).  Other file commands affected by a
479 specified coding system include @kbd{C-x C-i} and @kbd{C-x C-v}, as well
480 as the other-window variants of @kbd{C-x C-f}.
481
482 @vindex default-buffer-file-coding-system
483   The variable @code{default-buffer-file-coding-system} specifies the
484 choice of coding system to use when you create a new file.  It applies
485 when you find a new file, and when you create a buffer and then save it
486 in a file.  Selecting a language environment typically sets this
487 variable to a good choice of default coding system for that language
488 environment.
489
490 @kindex C-x RET t
491 @findex set-terminal-coding-system
492   The command @kbd{C-x @key{RET} t} (@code{set-terminal-coding-system})
493 specifies the coding system for terminal output.  If you specify a
494 character code for terminal output, all characters output to the
495 terminal are translated into that coding system.
496
497   This feature is useful for certain character-only terminals built to
498 support specific languages or character sets---for example, European
499 terminals that support one of the ISO Latin character sets.
500
501   By default, output to the terminal is not translated at all.
502
503 @kindex C-x RET k
504 @findex set-keyboard-coding-system
505   The command @kbd{C-x @key{RET} k} (@code{set-keyboard-coding-system})
506 specifies the coding system for keyboard input.  Character-code
507 translation of keyboard input is useful for terminals with keys that
508 send non-ASCII graphic characters---for example, some terminals designed
509 for ISO Latin-1 or subsets of it.
510
511   By default, keyboard input is not translated at all.
512
513   There is a similarity between using a coding system translation for
514 keyboard input, and using an input method: both define sequences of
515 keyboard input that translate into single characters.  However, input
516 methods are designed to be convenient for interactive use by humans, and
517 the sequences that are translated are typically sequences of ASCII
518 printing characters.  Coding systems typically translate sequences of
519 non-graphic characters.
520
521 @kindex C-x RET p
522 @findex set-buffer-process-coding-system
523   The command @kbd{C-x @key{RET} p} (@code{set-buffer-process-coding-system})
524 specifies the coding system for input and output to a subprocess.  This
525 command applies to the current buffer; normally, each subprocess has its
526 own buffer, and thus you can use this command to specify translation to
527 and from a particular subprocess by giving the command in the
528 corresponding buffer.
529
530   By default, process input and output are not translated at all.
531
532 @vindex file-name-coding-system
533   The variable @code{file-name-coding-system} specifies a coding system
534 to use for encoding file names.  If you set the variable to a coding
535 system name (as a Lisp symbol or a string), XEmacs encodes file names
536 using that coding system for all file operations.  This makes it
537 possible to use non-Latin-1 characters in file names---or, at least,
538 those non-Latin-1 characters which the specified coding system can
539 encode.  By default, this variable is @code{nil}, which implies that you
540 cannot use non-Latin-1 characters in file names.