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
7 @cindex international scripts
8 @cindex multibyte characters
9 @cindex encoding of characters
18 If you compile XEmacs with Mule option, it supports a wide variety of
19 world scripts, including Latin script, as well as Arabic script,
20 Simplified Chinese script (for mainland of China), Traditional Chinese
21 script (for Taiwan and Hong-Kong), Greek script, Hebrew script, IPA
22 symbols, Japanese scripts (Hiragana, Katakana and Kanji), Korean scripts
23 (Hangul and Hanja) and Cyrillic script (for Byelorussian, Bulgarian,
24 Russian, Serbian and Ukrainian). These features have been merged from
25 the modified version of Emacs known as MULE (for ``MULti-lingual
26 Enhancement to GNU Emacs'').
29 * Mule Intro:: Basic concepts of Mule.
30 * Language Environments:: Setting things up for the language you use.
31 * Input Methods:: Entering text characters not on your keyboard.
32 * Select Input Method:: Specifying your choice of input methods.
33 * Mule and Fonts:: Additional font-related issues
34 * Coding Systems:: Character set conversion when you read and
35 write files, and so on.
36 * Recognize Coding:: How XEmacs figures out which conversion to use.
37 * Specify Coding:: Various ways to choose which conversion to use.
40 @node Mule Intro, Language Environments, Mule, Mule
41 @section Introduction to world scripts
43 The users of these scripts have established many more-or-less standard
44 coding systems for storing files.
45 @c XEmacs internally uses a single multibyte character encoding, so that it
46 @c can intermix characters from all these scripts in a single buffer or
47 @c string. This encoding represents each non-ASCII character as a sequence
48 @c of bytes in the range 0200 through 0377.
49 XEmacs translates between the internal character encoding and various
50 other coding systems when reading and writing files, when exchanging
51 data with subprocesses, and (in some cases) in the @kbd{C-q} command
55 @findex view-hello-file
56 The command @kbd{C-h h} (@code{view-hello-file}) displays the file
57 @file{etc/HELLO}, which shows how to say ``hello'' in many languages.
58 This illustrates various scripts.
60 Keyboards, even in the countries where these character sets are used,
61 generally don't have keys for all the characters in them. So XEmacs
62 supports various @dfn{input methods}, typically one for each script or
63 language, to make it convenient to type them.
66 The prefix key @kbd{C-x @key{RET}} is used for commands that pertain
67 to world scripts, coding systems, and input methods.
70 @node Language Environments, Input Methods, Mule Intro, Mule
71 @section Language Environments
72 @cindex language environments
74 All supported character sets are supported in XEmacs buffers if it is
75 compiled with Mule; there is no need to select a particular language in
76 order to display its characters in an XEmacs buffer. However, it is
77 important to select a @dfn{language environment} in order to set various
78 defaults. The language environment really represents a choice of
79 preferred script (more or less) rather that a choice of language.
81 The language environment controls which coding systems to recognize
82 when reading text (@pxref{Recognize Coding}). This applies to files,
83 incoming mail, netnews, and any other text you read into XEmacs. It may
84 also specify the default coding system to use when you create a file.
85 Each language environment also specifies a default input method.
87 @findex set-language-environment
88 The command to select a language environment is @kbd{M-x
89 set-language-environment}. It makes no difference which buffer is
90 current when you use this command, because the effects apply globally to
91 the XEmacs session. The supported language environments include:
94 ASCII, Chinese-BIG5, Chinese-GB, Croatian, Cyrillic-ALT, Cyrillic-ISO,
95 Cyrillic-KOI8, Cyrillic-Win, Czech, English, Ethiopic, French, German,
96 Greek, Hebrew, IPA, Japanese, Korean, Latin-1, Latin-2, Latin-3, Latin-4,
97 Latin-5, Norwegian, Polish, Romanian, Slovenian, Thai-XTIS, Vietnamese.
100 Some operating systems let you specify the language you are using by
101 setting locale environment variables. XEmacs handles one common special
102 case of this: if your locale name for character types contains the
103 string @samp{8859-@var{n}}, XEmacs automatically selects the
104 corresponding language environment.
107 @findex describe-language-environment
108 To display information about the effects of a certain language
109 environment @var{lang-env}, use the command @kbd{C-h L @var{lang-env}
110 @key{RET}} (@code{describe-language-environment}). This tells you which
111 languages this language environment is useful for, and lists the
112 character sets, coding systems, and input methods that go with it. It
113 also shows some sample text to illustrate scripts used in this language
114 environment. By default, this command describes the chosen language
117 @node Input Methods, Select Input Method, Language Environments, Mule
118 @section Input Methods
120 @cindex input methods
121 An @dfn{input method} is a kind of character conversion designed
122 specifically for interactive input. In XEmacs, typically each language
123 has its own input method; sometimes several languages which use the same
124 characters can share one input method. A few languages support several
127 The simplest kind of input method works by mapping ASCII letters into
128 another alphabet. This is how the Greek and Russian input methods work.
130 A more powerful technique is composition: converting sequences of
131 characters into one letter. Many European input methods use composition
132 to produce a single non-ASCII letter from a sequence that consists of a
133 letter followed by accent characters. For example, some methods convert
134 the sequence @kbd{'a} into a single accented letter.
136 The input methods for syllabic scripts typically use mapping followed
137 by composition. The input methods for Thai and Korean work this way.
138 First, letters are mapped into symbols for particular sounds or tone
139 marks; then, sequences of these which make up a whole syllable are
140 mapped into one syllable sign.
142 Chinese and Japanese require more complex methods. In Chinese input
143 methods, first you enter the phonetic spelling of a Chinese word (in
144 input method @code{chinese-py}, among others), or a sequence of portions
145 of the character (input methods @code{chinese-4corner} and
146 @code{chinese-sw}, and others). Since one phonetic spelling typically
147 corresponds to many different Chinese characters, you must select one of
148 the alternatives using special XEmacs commands. Keys such as @kbd{C-f},
149 @kbd{C-b}, @kbd{C-n}, @kbd{C-p}, and digits have special definitions in
150 this situation, used for selecting among the alternatives. @key{TAB}
151 displays a buffer showing all the possibilities.
153 In Japanese input methods, first you input a whole word using
154 phonetic spelling; then, after the word is in the buffer, XEmacs
155 converts it into one or more characters using a large dictionary. One
156 phonetic spelling corresponds to many differently written Japanese
157 words, so you must select one of them; use @kbd{C-n} and @kbd{C-p} to
158 cycle through the alternatives.
160 Sometimes it is useful to cut off input method processing so that the
161 characters you have just entered will not combine with subsequent
162 characters. For example, in input method @code{latin-1-postfix}, the
163 sequence @kbd{e '} combines to form an @samp{e} with an accent. What if
164 you want to enter them as separate characters?
166 One way is to type the accent twice; that is a special feature for
167 entering the separate letter and accent. For example, @kbd{e ' '} gives
168 you the two characters @samp{e'}. Another way is to type another letter
169 after the @kbd{e}---something that won't combine with that---and
170 immediately delete it. For example, you could type @kbd{e e @key{DEL}
171 '} to get separate @samp{e} and @samp{'}.
173 Another method, more general but not quite as easy to type, is to use
174 @kbd{C-\ C-\} between two characters to stop them from combining. This
175 is the command @kbd{C-\} (@code{toggle-input-method}) used twice.
177 @xref{Select Input Method}.
180 @kbd{C-\ C-\} is especially useful inside an incremental search,
181 because stops waiting for more characters to combine, and starts
182 searching for what you have already entered.
184 @vindex input-method-verbose-flag
185 @vindex input-method-highlight-flag
186 The variables @code{input-method-highlight-flag} and
187 @code{input-method-verbose-flag} control how input methods explain what
188 is happening. If @code{input-method-highlight-flag} is non-@code{nil},
189 the partial sequence is highlighted in the buffer. If
190 @code{input-method-verbose-flag} is non-@code{nil}, the list of possible
191 characters to type next is displayed in the echo area (but not when you
192 are in the minibuffer).
194 @node Select Input Method, Mule and Fonts, Input Methods, Mule
195 @section Selecting an Input Method
199 Enable or disable use of the selected input method.
201 @item C-x @key{RET} C-\ @var{method} @key{RET}
202 Select a new input method for the current buffer.
204 @item C-h I @var{method} @key{RET}
205 @itemx C-h C-\ @var{method} @key{RET}
206 @findex describe-input-method
209 Describe the input method @var{method} (@code{describe-input-method}).
210 By default, it describes the current input method (if any).
212 @item M-x list-input-methods
213 Display a list of all the supported input methods.
216 @findex select-input-method
217 @vindex current-input-method
219 To choose an input method for the current buffer, use @kbd{C-x
220 @key{RET} C-\} (@code{select-input-method}). This command reads the
221 input method name with the minibuffer; the name normally starts with the
222 language environment that it is meant to be used with. The variable
223 @code{current-input-method} records which input method is selected.
225 @findex toggle-input-method
227 Input methods use various sequences of ASCII characters to stand for
228 non-ASCII characters. Sometimes it is useful to turn off the input
229 method temporarily. To do this, type @kbd{C-\}
230 (@code{toggle-input-method}). To reenable the input method, type
233 If you type @kbd{C-\} and you have not yet selected an input method,
234 it prompts for you to specify one. This has the same effect as using
235 @kbd{C-x @key{RET} C-\} to specify an input method.
237 @vindex default-input-method
238 Selecting a language environment specifies a default input method for
239 use in various buffers. When you have a default input method, you can
240 select it in the current buffer by typing @kbd{C-\}. The variable
241 @code{default-input-method} specifies the default input method
242 (@code{nil} means there is none).
244 @findex quail-set-keyboard-layout
245 Some input methods for alphabetic scripts work by (in effect)
246 remapping the keyboard to emulate various keyboard layouts commonly used
247 for those scripts. How to do this remapping properly depends on your
248 actual keyboard layout. To specify which layout your keyboard has, use
249 the command @kbd{M-x quail-set-keyboard-layout}.
251 @findex list-input-methods
252 To display a list of all the supported input methods, type @kbd{M-x
253 list-input-methods}. The list gives information about each input
254 method, including the string that stands for it in the mode line.
256 @node Mule and Fonts, Coding Systems, Select Input Method, Mule
257 @section Mule and Fonts
259 @cindex font registry
260 @cindex font encoding
263 (This section is X11-specific.)
265 Text in XEmacs buffers is displayed using various faces. In addition to
266 specifying properties of a face, such as font and color, there are some
267 additional properties of Mule charsets that are used in text.
269 There is currently two properties of a charset that could be adjusted by
270 user: font registry and so called @dfn{ccl-program}.
272 Font registry is a regular expression matching the font registry field
273 for this character set. For example, both the @code{ascii} and
274 @w{@code{latin-iso8859-1}} charsets use the registry @code{"ISO8859-1"}.
275 This field is used to choose an appropriate font when the user gives a
276 general font specification such as @w{@samp{-*-courier-medium-r-*-140-*}},
277 i.e. a 14-point upright medium-weight Courier font.
279 You can set font registry for a charset using
280 @samp{set-charset-registry} function in one of your startup files. This
281 function takes two arguments: character set (as a symbol) and font
282 registry (as a string).
284 E.@w{ }g., for Cyrillic texts Mule uses @w{@code{cyrillic-iso8859-5}}
285 charset with @samp{"ISO8859-5"} as a default registry, and we want to
286 use @samp{"koi8-r"} instead, because fonts in that encoding are
287 installed on our system. Use:
290 (set-charset-registry 'cyrillic-iso8859-5 "koi8-r")
293 (Please note that you probably also want to set font registry for
294 @samp{ascii} charset so that mixed English/Cyrillic texts be displayed
295 using the same font.)
297 "CCL-programs" are a little special-purpose scripts defined within
298 XEmacs or in some package. Those scripts allow XEmacs to use fonts that
299 are in different encoding from the encoding that is used by Mule for
300 text in buffer. Returning to the above example, we need to somehow tell
301 XEmacs that we have different encodings of fonts and text and so it
302 needs to convert characters between those encodings when displaying.
303 That's what @samp{set-charset-ccl-program} function is used for. There
304 are quite a few various CCL programs defined within XEmacs, and there is
305 no comprehensive list of them, so you currently have to consult sources.
306 @c FIXME: there must be a list of CCL programs
308 We know that there is a CCL program called @samp{ccl-encode-koi8-r-font}
309 that is used exactly for needed purpose: to convert characters between
310 @samp{ISO8859-5} encoding and @samp{koi8-r}. Use:
313 (set-charset-ccl-program 'cyrillic-iso8859-5 'ccl-encode-koi8-r-font)
316 There are several more uses for CCL programs, not related to fonts, but
317 those uses are not described here.
320 @node Coding Systems, Recognize Coding, Mule and Fonts, Mule
321 @section Coding Systems
322 @cindex coding systems
324 Users of various languages have established many more-or-less standard
325 coding systems for representing them. XEmacs does not use these coding
326 systems internally; instead, it converts from various coding systems to
327 its own system when reading data, and converts the internal coding
328 system to other coding systems when writing data. Conversion is
329 possible in reading or writing files, in sending or receiving from the
330 terminal, and in exchanging data with subprocesses.
332 XEmacs assigns a name to each coding system. Most coding systems are
333 used for one language, and the name of the coding system starts with the
334 language name. Some coding systems are used for several languages;
335 their names usually start with @samp{iso}. There are also special
336 coding systems @code{binary} and @code{no-conversion} which do not
337 convert printing characters at all.
339 In addition to converting various representations of non-ASCII
340 characters, a coding system can perform end-of-line conversion. XEmacs
341 handles three different conventions for how to separate lines in a file:
342 newline, carriage-return linefeed, and just carriage-return.
345 @item C-h C @var{coding} @key{RET}
346 Describe coding system @var{coding}.
348 @item C-h C @key{RET}
349 Describe the coding systems currently in use.
351 @item M-x list-coding-systems
352 Display a list of all the supported coding systems.
354 @item C-u M-x list-coding-systems
355 Display comprehensive list of specific details of all supported coding
359 @kindex C-x @key{RET} C
360 @findex describe-coding-system
361 The command @kbd{C-x RET C} (@code{describe-coding-system}) displays
362 information about particular coding systems. You can specify a coding
363 system name as argument; alternatively, with an empty argument, it
364 describes the coding systems currently selected for various purposes,
365 both in the current buffer and as the defaults, and the priority list
366 for recognizing coding systems (@pxref{Recognize Coding}).
368 @findex list-coding-systems
369 To display a list of all the supported coding systems, type @kbd{M-x
370 list-coding-systems}. The list gives information about each coding
371 system, including the letter that stands for it in the mode line
374 Each of the coding systems that appear in this list---except for
375 @code{binary}, which means no conversion of any kind---specifies how and
376 whether to convert printing characters, but leaves the choice of
377 end-of-line conversion to be decided based on the contents of each file.
378 For example, if the file appears to use carriage-return linefeed between
379 lines, that end-of-line conversion will be used.
381 Each of the listed coding systems has three variants which specify
382 exactly what to do for end-of-line conversion:
386 Don't do any end-of-line conversion; assume the file uses
387 newline to separate lines. (This is the convention normally used
388 on Unix and GNU systems.)
391 Assume the file uses carriage-return linefeed to separate lines,
392 and do the appropriate conversion. (This is the convention normally used
393 on Microsoft systems.)
396 Assume the file uses carriage-return to separate lines, and do the
397 appropriate conversion. (This is the convention normally used on the
401 These variant coding systems are omitted from the
402 @code{list-coding-systems} display for brevity, since they are entirely
403 predictable. For example, the coding system @code{iso-8859-1} has
404 variants @code{iso-8859-1-unix}, @code{iso-8859-1-dos} and
405 @code{iso-8859-1-mac}.
407 In contrast, the coding system @code{binary} specifies no character
408 code conversion at all---none for non-Latin-1 byte values and none for
409 end of line. This is useful for reading or writing binary files, tar
410 files, and other files that must be examined verbatim.
412 The easiest way to edit a file with no conversion of any kind is with
413 the @kbd{M-x find-file-literally} command. This uses @code{binary}, and
414 also suppresses other XEmacs features that might convert the file
415 contents before you see them. @xref{Visiting}.
417 The coding system @code{no-conversion} means that the file contains
418 non-Latin-1 characters stored with the internal XEmacs encoding. It
419 handles end-of-line conversion based on the data encountered, and has
420 the usual three variants to specify the kind of end-of-line conversion.
423 @node Recognize Coding, Specify Coding, Coding Systems, Mule
424 @section Recognizing Coding Systems
426 Most of the time, XEmacs can recognize which coding system to use for
427 any given file--once you have specified your preferences.
429 Some coding systems can be recognized or distinguished by which byte
430 sequences appear in the data. However, there are coding systems that
431 cannot be distinguished, not even potentially. For example, there is no
432 way to distinguish between Latin-1 and Latin-2; they use the same byte
433 values with different meanings.
435 XEmacs handles this situation by means of a priority list of coding
436 systems. Whenever XEmacs reads a file, if you do not specify the coding
437 system to use, XEmacs checks the data against each coding system,
438 starting with the first in priority and working down the list, until it
439 finds a coding system that fits the data. Then it converts the file
440 contents assuming that they are represented in this coding system.
442 The priority list of coding systems depends on the selected language
443 environment (@pxref{Language Environments}). For example, if you use
444 French, you probably want XEmacs to prefer Latin-1 to Latin-2; if you
445 use Czech, you probably want Latin-2 to be preferred. This is one of
446 the reasons to specify a language environment.
448 @findex prefer-coding-system
449 However, you can alter the priority list in detail with the command
450 @kbd{M-x prefer-coding-system}. This command reads the name of a coding
451 system from the minibuffer, and adds it to the front of the priority
452 list, so that it is preferred to all others. If you use this command
453 several times, each use adds one element to the front of the priority
456 @vindex file-coding-system-alist
457 Sometimes a file name indicates which coding system to use for the
458 file. The variable @code{file-coding-system-alist} specifies this
459 correspondence. There is a special function
460 @code{modify-coding-system-alist} for adding elements to this list. For
461 example, to read and write all @samp{.txt} using the coding system
462 @code{china-iso-8bit}, you can execute this Lisp expression:
465 (modify-coding-system-alist 'file "\\.txt\\'" 'china-iso-8bit)
469 The first argument should be @code{file}, the second argument should be
470 a regular expression that determines which files this applies to, and
471 the third argument says which coding system to use for these files.
474 You can specify the coding system for a particular file using the
475 @samp{-*-@dots{}-*-} construct at the beginning of a file, or a local
476 variables list at the end (@pxref{File Variables}). You do this by
477 defining a value for the ``variable'' named @code{coding}. XEmacs does
478 not really have a variable @code{coding}; instead of setting a variable,
479 it uses the specified coding system for the file. For example,
480 @samp{-*-mode: C; coding: iso-8859-1;-*-} specifies use of the
481 iso-8859-1 coding system, as well as C mode.
483 @vindex buffer-file-coding-system
484 Once XEmacs has chosen a coding system for a buffer, it stores that
485 coding system in @code{buffer-file-coding-system} and uses that coding
486 system, by default, for operations that write from this buffer into a
487 file. This includes the commands @code{save-buffer} and
488 @code{write-region}. If you want to write files from this buffer using
489 a different coding system, you can specify a different coding system for
490 the buffer using @code{set-buffer-file-coding-system} (@pxref{Specify
494 @node Specify Coding, , Recognize Coding, Mule
495 @section Specifying a Coding System
497 In cases where XEmacs does not automatically choose the right coding
498 system, you can use these commands to specify one:
501 @item C-x @key{RET} f @var{coding} @key{RET}
502 Use coding system @var{coding} for the visited file
503 in the current buffer.
505 @item C-x @key{RET} c @var{coding} @key{RET}
506 Specify coding system @var{coding} for the immediately following
509 @item C-x @key{RET} k @var{coding} @key{RET}
510 Use coding system @var{coding} for keyboard input. (This feature is
511 non-functional and is temporarily disabled.)
513 @item C-x @key{RET} t @var{coding} @key{RET}
514 Use coding system @var{coding} for terminal output.
516 @item C-x @key{RET} p @var{coding} @key{RET}
517 Use coding system @var{coding} for subprocess input and output
518 in the current buffer.
522 @findex set-buffer-file-coding-system
523 The command @kbd{C-x RET f} (@code{set-buffer-file-coding-system})
524 specifies the file coding system for the current buffer---in other
525 words, which coding system to use when saving or rereading the visited
526 file. You specify which coding system using the minibuffer. Since this
527 command applies to a file you have already visited, it affects only the
528 way the file is saved.
531 @findex universal-coding-system-argument
532 Another way to specify the coding system for a file is when you visit
533 the file. First use the command @kbd{C-x @key{RET} c}
534 (@code{universal-coding-system-argument}); this command uses the
535 minibuffer to read a coding system name. After you exit the minibuffer,
536 the specified coding system is used for @emph{the immediately following
539 So if the immediately following command is @kbd{C-x C-f}, for example,
540 it reads the file using that coding system (and records the coding
541 system for when the file is saved). Or if the immediately following
542 command is @kbd{C-x C-w}, it writes the file using that coding system.
543 Other file commands affected by a specified coding system include
544 @kbd{C-x C-i} and @kbd{C-x C-v}, as well as the other-window variants of
547 In addition, if you run some file input commands with the precedent
548 @kbd{C-u}, you can specify coding system to read from minibuffer. So if
549 the immediately following command is @kbd{C-x C-f}, for example, it
550 reads the file using that coding system (and records the coding system
551 for when the file is saved). Other file commands affected by a
552 specified coding system include @kbd{C-x C-i} and @kbd{C-x C-v}, as well
553 as the other-window variants of @kbd{C-x C-f}.
555 @vindex default-buffer-file-coding-system
556 The variable @code{default-buffer-file-coding-system} specifies the
557 choice of coding system to use when you create a new file. It applies
558 when you find a new file, and when you create a buffer and then save it
559 in a file. Selecting a language environment typically sets this
560 variable to a good choice of default coding system for that language
564 @findex set-terminal-coding-system
565 The command @kbd{C-x @key{RET} t} (@code{set-terminal-coding-system})
566 specifies the coding system for terminal output. If you specify a
567 character code for terminal output, all characters output to the
568 terminal are translated into that coding system.
570 This feature is useful for certain character-only terminals built to
571 support specific languages or character sets---for example, European
572 terminals that support one of the ISO Latin character sets.
574 By default, output to the terminal is not translated at all.
577 @findex set-keyboard-coding-system
578 The command @kbd{C-x @key{RET} k} (@code{set-keyboard-coding-system})
579 specifies the coding system for keyboard input. Character-code
580 translation of keyboard input is useful for terminals with keys that
581 send non-ASCII graphic characters---for example, some terminals designed
582 for ISO Latin-1 or subsets of it.
584 By default, keyboard input is not translated at all.
586 There is a similarity between using a coding system translation for
587 keyboard input, and using an input method: both define sequences of
588 keyboard input that translate into single characters. However, input
589 methods are designed to be convenient for interactive use by humans, and
590 the sequences that are translated are typically sequences of ASCII
591 printing characters. Coding systems typically translate sequences of
592 non-graphic characters.
594 (This feature is non-functional and is temporarily disabled.)
597 @findex set-buffer-process-coding-system
598 The command @kbd{C-x @key{RET} p} (@code{set-buffer-process-coding-system})
599 specifies the coding system for input and output to a subprocess. This
600 command applies to the current buffer; normally, each subprocess has its
601 own buffer, and thus you can use this command to specify translation to
602 and from a particular subprocess by giving the command in the
603 corresponding buffer.
605 By default, process input and output are not translated at all.
607 @vindex file-name-coding-system
608 The variable @code{file-name-coding-system} specifies a coding system
609 to use for encoding file names. If you set the variable to a coding
610 system name (as a Lisp symbol or a string), XEmacs encodes file names
611 using that coding system for all file operations. This makes it
612 possible to use non-Latin-1 characters in file names---or, at least,
613 those non-Latin-1 characters which the specified coding system can
614 encode. By default, this variable is @code{nil}, which implies that you
615 cannot use non-Latin-1 characters in file names.