]> code.delx.au - gnu-emacs/blob - doc/emacs/mule.texi
88bbccd5b1107cddd925746980838a3a98d70729
[gnu-emacs] / doc / emacs / mule.texi
1 @c -*- coding: utf-8 -*-
2 @c This is part of the Emacs manual.
3 @c Copyright (C) 1997, 1999-2015 Free Software Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node International
6 @chapter International Character Set Support
7 @c This node is referenced in the tutorial. When renaming or deleting
8 @c it, the tutorial needs to be adjusted. (TUTORIAL.de)
9 @cindex international scripts
10 @cindex multibyte characters
11 @cindex encoding of characters
12
13 @cindex Arabic
14 @cindex Bengali
15 @cindex Chinese
16 @cindex Cyrillic
17 @cindex Han
18 @cindex Hindi
19 @cindex Ethiopic
20 @cindex Georgian
21 @cindex Greek
22 @cindex Hangul
23 @cindex Hebrew
24 @cindex Hindi
25 @cindex IPA
26 @cindex Japanese
27 @cindex Korean
28 @cindex Latin
29 @cindex Thai
30 @cindex Vietnamese
31 Emacs supports a wide variety of international character sets,
32 including European and Vietnamese variants of the Latin alphabet, as
33 well as Arabic scripts, Brahmic scripts (for languages such as
34 Bengali, Hindi, and Thai), Cyrillic, Ethiopic, Georgian, Greek, Han
35 (for Chinese and Japanese), Hangul (for Korean), Hebrew and IPA@.
36 Emacs also supports various encodings of these characters that are used by
37 other internationalized software, such as word processors and mailers.
38
39 Emacs allows editing text with international characters by supporting
40 all the related activities:
41
42 @itemize @bullet
43 @item
44 You can visit files with non-@acronym{ASCII} characters, save non-@acronym{ASCII} text, and
45 pass non-@acronym{ASCII} text between Emacs and programs it invokes (such as
46 compilers, spell-checkers, and mailers). Setting your language
47 environment (@pxref{Language Environments}) takes care of setting up the
48 coding systems and other options for a specific language or culture.
49 Alternatively, you can specify how Emacs should encode or decode text
50 for each command; see @ref{Text Coding}.
51
52 @item
53 You can display non-@acronym{ASCII} characters encoded by the various
54 scripts. This works by using appropriate fonts on graphics displays
55 (@pxref{Defining Fontsets}), and by sending special codes to text
56 displays (@pxref{Terminal Coding}). If some characters are displayed
57 incorrectly, refer to @ref{Undisplayable Characters}, which describes
58 possible problems and explains how to solve them.
59
60 @item
61 Characters from scripts whose natural ordering of text is from right
62 to left are reordered for display (@pxref{Bidirectional Editing}).
63 These scripts include Arabic, Hebrew, Syriac, Thaana, and a few
64 others.
65
66 @item
67 You can insert non-@acronym{ASCII} characters or search for them. To do that,
68 you can specify an input method (@pxref{Select Input Method}) suitable
69 for your language, or use the default input method set up when you chose
70 your language environment. If
71 your keyboard can produce non-@acronym{ASCII} characters, you can select an
72 appropriate keyboard coding system (@pxref{Terminal Coding}), and Emacs
73 will accept those characters. Latin-1 characters can also be input by
74 using the @kbd{C-x 8} prefix, see @ref{Unibyte Mode}.
75
76 With the X Window System, your locale should be set to an appropriate
77 value to make sure Emacs interprets keyboard input correctly; see
78 @ref{Language Environments, locales}.
79 @end itemize
80
81 The rest of this chapter describes these issues in detail.
82
83 @menu
84 * International Chars:: Basic concepts of multibyte characters.
85 * Language Environments:: Setting things up for the language you use.
86 * Input Methods:: Entering text characters not on your keyboard.
87 * Select Input Method:: Specifying your choice of input methods.
88 * Coding Systems:: Character set conversion when you read and
89 write files, and so on.
90 * Recognize Coding:: How Emacs figures out which conversion to use.
91 * Specify Coding:: Specifying a file's coding system explicitly.
92 * Output Coding:: Choosing coding systems for output.
93 * Text Coding:: Choosing conversion to use for file text.
94 * Communication Coding:: Coding systems for interprocess communication.
95 * File Name Coding:: Coding systems for file @emph{names}.
96 * Terminal Coding:: Specifying coding systems for converting
97 terminal input and output.
98 * Fontsets:: Fontsets are collections of fonts
99 that cover the whole spectrum of characters.
100 * Defining Fontsets:: Defining a new fontset.
101 * Modifying Fontsets:: Modifying an existing fontset.
102 * Undisplayable Characters:: When characters don't display.
103 * Unibyte Mode:: You can pick one European character set
104 to use without multibyte characters.
105 * Charsets:: How Emacs groups its internal character codes.
106 * Bidirectional Editing:: Support for right-to-left scripts.
107 @end menu
108
109 @node International Chars
110 @section Introduction to International Character Sets
111
112 The users of international character sets and scripts have
113 established many more-or-less standard coding systems for storing
114 files. These coding systems are typically @dfn{multibyte}, meaning
115 that sequences of two or more bytes are used to represent individual
116 non-@acronym{ASCII} characters.
117
118 @cindex Unicode
119 Internally, Emacs uses its own multibyte character encoding, which
120 is a superset of the @dfn{Unicode} standard. This internal encoding
121 allows characters from almost every known script to be intermixed in a
122 single buffer or string. Emacs translates between the multibyte
123 character encoding and various other coding systems when reading and
124 writing files, and when exchanging data with subprocesses.
125
126 @kindex C-h h
127 @findex view-hello-file
128 @cindex undisplayable characters
129 @cindex @samp{?} in display
130 The command @kbd{C-h h} (@code{view-hello-file}) displays the file
131 @file{etc/HELLO}, which illustrates various scripts by showing
132 how to say ``hello'' in many languages. If some characters can't be
133 displayed on your terminal, they appear as @samp{?} or as hollow boxes
134 (@pxref{Undisplayable Characters}).
135
136 Keyboards, even in the countries where these character sets are
137 used, generally don't have keys for all the characters in them. You
138 can insert characters that your keyboard does not support, using
139 @kbd{C-x 8 @key{RET}} (@code{insert-char}). @xref{Inserting Text}.
140 Shorthands are available for some common characters; for example, you
141 can insert a left single quotation mark @t{‘} by typing @kbd{C-x 8
142 [}, or in Electric Quote mode often by simply typing @kbd{`}.
143 @xref{Quotation Marks}. Emacs also supports
144 various @dfn{input methods}, typically one for each script or
145 language, which make it easier to type characters in the script.
146 @xref{Input Methods}.
147
148 @kindex C-x RET
149 The prefix key @kbd{C-x @key{RET}} is used for commands that pertain
150 to multibyte characters, coding systems, and input methods.
151
152 @kindex C-x =
153 @findex what-cursor-position
154 The command @kbd{C-x =} (@code{what-cursor-position}) shows
155 information about the character at point. In addition to the
156 character position, which was described in @ref{Position Info}, this
157 command displays how the character is encoded. For instance, it
158 displays the following line in the echo area for the character
159 @samp{c}:
160
161 @smallexample
162 Char: c (99, #o143, #x63) point=28062 of 36168 (78%) column=53
163 @end smallexample
164
165 The four values after @samp{Char:} describe the character that
166 follows point, first by showing it and then by giving its character
167 code in decimal, octal and hex. For a non-@acronym{ASCII} multibyte
168 character, these are followed by @samp{file} and the character's
169 representation, in hex, in the buffer's coding system, if that coding
170 system encodes the character safely and with a single byte
171 (@pxref{Coding Systems}). If the character's encoding is longer than
172 one byte, Emacs shows @samp{file ...}.
173
174 As a special case, if the character lies in the range 128 (0200
175 octal) through 159 (0237 octal), it stands for a raw byte that
176 does not correspond to any specific displayable character. Such a
177 character lies within the @code{eight-bit-control} character set,
178 and is displayed as an escaped octal character code. In this case,
179 @kbd{C-x =} shows @samp{part of display ...} instead of @samp{file}.
180
181 @cindex character set of character at point
182 @cindex font of character at point
183 @cindex text properties at point
184 @cindex face at point
185 With a prefix argument (@kbd{C-u C-x =}), this command displays a
186 detailed description of the character in a window:
187
188 @itemize @bullet
189 @item
190 The character set name, and the codes that identify the character
191 within that character set; @acronym{ASCII} characters are identified
192 as belonging to the @code{ascii} character set.
193
194 @item
195 The character's script, syntax and categories.
196
197 @item
198 What keys to type to input the character in the current input method
199 (if it supports the character).
200
201 @item
202 The character's encodings, both internally in the buffer, and externally
203 if you were to save the file.
204
205 @item
206 If you are running Emacs on a graphical display, the font name and
207 glyph code for the character. If you are running Emacs on a text
208 terminal, the code(s) sent to the terminal.
209
210 @item
211 The character's text properties (@pxref{Text Properties,,,
212 elisp, the Emacs Lisp Reference Manual}), including any non-default
213 faces used to display the character, and any overlays containing it
214 (@pxref{Overlays,,, elisp, the same manual}).
215 @end itemize
216
217 Here's an example, with some lines folded to fit into this manual:
218
219 @smallexample
220 position: 1 of 1 (0%), column: 0
221 character: ê (displayed as ê) (codepoint 234, #o352, #xea)
222 preferred charset: unicode (Unicode (ISO10646))
223 code point in charset: 0xEA
224 script: latin
225 syntax: w which means: word
226 category: .:Base, L:Left-to-right (strong), c:Chinese,
227 j:Japanese, l:Latin, v:Viet
228 to input: type "C-x 8 RET HEX-CODEPOINT" or "C-x 8 RET NAME"
229 buffer code: #xC3 #xAA
230 file code: #xC3 #xAA (encoded by coding system utf-8-unix)
231 display: by this font (glyph code)
232 xft:-unknown-DejaVu Sans Mono-normal-normal-
233 normal-*-15-*-*-*-m-0-iso10646-1 (#xAC)
234
235 Character code properties: customize what to show
236 name: LATIN SMALL LETTER E WITH CIRCUMFLEX
237 old-name: LATIN SMALL LETTER E CIRCUMFLEX
238 general-category: Ll (Letter, Lowercase)
239 decomposition: (101 770) ('e' '^')
240 @end smallexample
241
242 @node Language Environments
243 @section Language Environments
244 @cindex language environments
245
246 All supported character sets are supported in Emacs buffers whenever
247 multibyte characters are enabled; there is no need to select a
248 particular language in order to display its characters.
249 However, it is important to select a @dfn{language
250 environment} in order to set various defaults. Roughly speaking, the
251 language environment represents a choice of preferred script rather
252 than a choice of language.
253
254 The language environment controls which coding systems to recognize
255 when reading text (@pxref{Recognize Coding}). This applies to files,
256 incoming mail, and any other text you read into Emacs. It may also
257 specify the default coding system to use when you create a file. Each
258 language environment also specifies a default input method.
259
260 @findex set-language-environment
261 @vindex current-language-environment
262 To select a language environment, customize
263 @code{current-language-environment} or use the command @kbd{M-x
264 set-language-environment}. It makes no difference which buffer is
265 current when you use this command, because the effects apply globally
266 to the Emacs session. See the variable @code{language-info-alist} for
267 the list of supported language environments, and use the command
268 @kbd{C-h L @var{lang-env} @key{RET}} (@code{describe-language-environment})
269 for more information about the language environment @var{lang-env}.
270 Supported language environments include:
271
272 @c @cindex entries below are split between portions of the list to
273 @c make them more accurate, i.e., land on the line that mentions the
274 @c language. However, makeinfo 4.x doesn't fill inside @quotation
275 @c lines that follow a @cindex entry and whose text has no whitespace.
276 @c To work around, we group the language environments together, so
277 @c that the blank that separates them triggers refill.
278 @quotation
279 @cindex ASCII
280 @cindex Arabic
281 ASCII, Arabic,
282 @cindex Belarusian
283 @cindex Bengali
284 Belarusian, Bengali,
285 @cindex Brazilian Portuguese
286 @cindex Bulgarian
287 Brazilian Portuguese, Bulgarian,
288 @cindex Burmese
289 @cindex Cham
290 Burmese, Cham,
291 @cindex Chinese
292 Chinese-BIG5, Chinese-CNS, Chinese-EUC-TW, Chinese-GB,
293 Chinese-GB18030, Chinese-GBK,
294 @cindex Croatian
295 @cindex Cyrillic
296 Croatian, Cyrillic-ALT, Cyrillic-ISO, Cyrillic-KOI8,
297 @cindex Czech
298 @cindex Devanagari
299 Czech, Devanagari,
300 @cindex Dutch
301 @cindex English
302 Dutch, English,
303 @cindex Esperanto
304 @cindex Ethiopic
305 Esperanto, Ethiopic,
306 @cindex French
307 @cindex Georgian
308 French, Georgian,
309 @cindex German
310 @cindex Greek
311 @cindex Gujarati
312 German, Greek, Gujarati,
313 @cindex Hebrew
314 @cindex IPA
315 Hebrew, IPA,
316 @cindex Italian
317 Italian,
318 @cindex Japanese
319 @cindex Kannada
320 Japanese, Kannada,
321 @cindex Khmer
322 @cindex Korean
323 @cindex Lao
324 Khmer, Korean, Lao,
325 @cindex Latin
326 Latin-1, Latin-2, Latin-3, Latin-4, Latin-5, Latin-6, Latin-7,
327 Latin-8, Latin-9,
328 @cindex Latvian
329 @cindex Lithuanian
330 Latvian, Lithuanian,
331 @cindex Malayalam
332 @cindex Oriya
333 Malayalam, Oriya,
334 @cindex Persian
335 @cindex Polish
336 Persian, Polish,
337 @cindex Punjabi
338 @cindex Romanian
339 Punjabi, Romanian,
340 @cindex Russian
341 @cindex Sinhala
342 Russian, Sinhala,
343 @cindex Slovak
344 @cindex Slovenian
345 @cindex Spanish
346 Slovak, Slovenian, Spanish,
347 @cindex Swedish
348 @cindex TaiViet
349 Swedish, TaiViet,
350 @cindex Tajik
351 @cindex Tamil
352 Tajik, Tamil,
353 @cindex Telugu
354 @cindex Thai
355 Telugu, Thai,
356 @cindex Tibetan
357 @cindex Turkish
358 Tibetan, Turkish,
359 @cindex UTF-8
360 @cindex Ukrainian
361 UTF-8, Ukrainian,
362 @cindex Vietnamese
363 @cindex Welsh
364 Vietnamese, Welsh,
365 @cindex Windows-1255
366 and Windows-1255.
367 @end quotation
368
369 To display the script(s) used by your language environment on a
370 graphical display, you need to have suitable fonts.
371 @xref{Fontsets}, for more details about setting up your fonts.
372
373 @findex set-locale-environment
374 @vindex locale-language-names
375 @vindex locale-charset-language-names
376 @cindex locales
377 Some operating systems let you specify the character-set locale you
378 are using by setting the locale environment variables @env{LC_ALL},
379 @env{LC_CTYPE}, or @env{LANG}. (If more than one of these is
380 set, the first one that is nonempty specifies your locale for this
381 purpose.) During startup, Emacs looks up your character-set locale's
382 name in the system locale alias table, matches its canonical name
383 against entries in the value of the variables
384 @code{locale-charset-language-names} and @code{locale-language-names}
385 (the former overrides the latter),
386 and selects the corresponding language environment if a match is found.
387 It also adjusts the display
388 table and terminal coding system, the locale coding system, the
389 preferred coding system as needed for the locale, and---last but not
390 least---the way Emacs decodes non-@acronym{ASCII} characters sent by your keyboard.
391
392 @c This seems unlikely, doesn't it?
393 If you modify the @env{LC_ALL}, @env{LC_CTYPE}, or @env{LANG}
394 environment variables while running Emacs (by using @kbd{M-x setenv}),
395 you may want to invoke the @code{set-locale-environment}
396 function afterwards to readjust the language environment from the new
397 locale.
398
399 @vindex locale-preferred-coding-systems
400 The @code{set-locale-environment} function normally uses the preferred
401 coding system established by the language environment to decode system
402 messages. But if your locale matches an entry in the variable
403 @code{locale-preferred-coding-systems}, Emacs uses the corresponding
404 coding system instead. For example, if the locale @samp{ja_JP.PCK}
405 matches @code{japanese-shift-jis} in
406 @code{locale-preferred-coding-systems}, Emacs uses that encoding even
407 though it might normally use @code{japanese-iso-8bit}.
408
409 You can override the language environment chosen at startup with
410 explicit use of the command @code{set-language-environment}, or with
411 customization of @code{current-language-environment} in your init
412 file.
413
414 @kindex C-h L
415 @findex describe-language-environment
416 To display information about the effects of a certain language
417 environment @var{lang-env}, use the command @kbd{C-h L @var{lang-env}
418 @key{RET}} (@code{describe-language-environment}). This tells you
419 which languages this language environment is useful for, and lists the
420 character sets, coding systems, and input methods that go with it. It
421 also shows some sample text to illustrate scripts used in this
422 language environment. If you give an empty input for @var{lang-env},
423 this command describes the chosen language environment.
424
425 @vindex set-language-environment-hook
426 You can customize any language environment with the normal hook
427 @code{set-language-environment-hook}. The command
428 @code{set-language-environment} runs that hook after setting up the new
429 language environment. The hook functions can test for a specific
430 language environment by checking the variable
431 @code{current-language-environment}. This hook is where you should
432 put non-default settings for specific language environments, such as
433 coding systems for keyboard input and terminal output, the default
434 input method, etc.
435
436 @vindex exit-language-environment-hook
437 Before it starts to set up the new language environment,
438 @code{set-language-environment} first runs the hook
439 @code{exit-language-environment-hook}. This hook is useful for undoing
440 customizations that were made with @code{set-language-environment-hook}.
441 For instance, if you set up a special key binding in a specific language
442 environment using @code{set-language-environment-hook}, you should set
443 up @code{exit-language-environment-hook} to restore the normal binding
444 for that key.
445
446 @node Input Methods
447 @section Input Methods
448
449 @cindex input methods
450 An @dfn{input method} is a kind of character conversion designed
451 specifically for interactive input. In Emacs, typically each language
452 has its own input method; sometimes several languages that use the same
453 characters can share one input method. A few languages support several
454 input methods.
455
456 The simplest kind of input method works by mapping @acronym{ASCII} letters
457 into another alphabet; this allows you to use one other alphabet
458 instead of @acronym{ASCII}. The Greek and Russian input methods
459 work this way.
460
461 A more powerful technique is composition: converting sequences of
462 characters into one letter. Many European input methods use composition
463 to produce a single non-@acronym{ASCII} letter from a sequence that consists of a
464 letter followed by accent characters (or vice versa). For example, some
465 methods convert the sequence @kbd{o ^} into a single accented letter.
466 These input methods have no special commands of their own; all they do
467 is compose sequences of printing characters.
468
469 The input methods for syllabic scripts typically use mapping followed
470 by composition. The input methods for Thai and Korean work this way.
471 First, letters are mapped into symbols for particular sounds or tone
472 marks; then, sequences of these that make up a whole syllable are
473 mapped into one syllable sign.
474
475 Chinese and Japanese require more complex methods. In Chinese input
476 methods, first you enter the phonetic spelling of a Chinese word (in
477 input method @code{chinese-py}, among others), or a sequence of
478 portions of the character (input methods @code{chinese-4corner} and
479 @code{chinese-sw}, and others). One input sequence typically
480 corresponds to many possible Chinese characters. You select the one
481 you mean using keys such as @kbd{C-f}, @kbd{C-b}, @kbd{C-n},
482 @kbd{C-p} (or the arrow keys), and digits, which have special meanings
483 in this situation.
484
485 The possible characters are conceptually arranged in several rows,
486 with each row holding up to 10 alternatives. Normally, Emacs displays
487 just one row at a time, in the echo area; @code{(@var{i}/@var{j})}
488 appears at the beginning, to indicate that this is the @var{i}th row
489 out of a total of @var{j} rows. Type @kbd{C-n} or @kbd{C-p} to
490 display the next row or the previous row.
491
492 Type @kbd{C-f} and @kbd{C-b} to move forward and backward among
493 the alternatives in the current row. As you do this, Emacs highlights
494 the current alternative with a special color; type @code{C-@key{SPC}}
495 to select the current alternative and use it as input. The
496 alternatives in the row are also numbered; the number appears before
497 the alternative. Typing a number selects the associated alternative
498 of the current row and uses it as input.
499
500 @key{TAB} in these Chinese input methods displays a buffer showing
501 all the possible characters at once; then clicking @kbd{Mouse-2} on
502 one of them selects that alternative. The keys @kbd{C-f}, @kbd{C-b},
503 @kbd{C-n}, @kbd{C-p}, and digits continue to work as usual, but they
504 do the highlighting in the buffer showing the possible characters,
505 rather than in the echo area.
506
507 In Japanese input methods, first you input a whole word using
508 phonetic spelling; then, after the word is in the buffer, Emacs
509 converts it into one or more characters using a large dictionary. One
510 phonetic spelling corresponds to a number of different Japanese words;
511 to select one of them, use @kbd{C-n} and @kbd{C-p} to cycle through
512 the alternatives.
513
514 Sometimes it is useful to cut off input method processing so that the
515 characters you have just entered will not combine with subsequent
516 characters. For example, in input method @code{latin-1-postfix}, the
517 sequence @kbd{o ^} combines to form an @samp{o} with an accent. What if
518 you want to enter them as separate characters?
519
520 One way is to type the accent twice; this is a special feature for
521 entering the separate letter and accent. For example, @kbd{o ^ ^} gives
522 you the two characters @samp{o^}. Another way is to type another letter
523 after the @kbd{o}---something that won't combine with that---and
524 immediately delete it. For example, you could type @kbd{o o @key{DEL}
525 ^} to get separate @samp{o} and @samp{^}.
526
527 Another method, more general but not quite as easy to type, is to use
528 @kbd{C-\ C-\} between two characters to stop them from combining. This
529 is the command @kbd{C-\} (@code{toggle-input-method}) used twice.
530 @ifnottex
531 @xref{Select Input Method}.
532 @end ifnottex
533
534 @cindex incremental search, input method interference
535 @kbd{C-\ C-\} is especially useful inside an incremental search,
536 because it stops waiting for more characters to combine, and starts
537 searching for what you have already entered.
538
539 To find out how to input the character after point using the current
540 input method, type @kbd{C-u C-x =}. @xref{Position Info}.
541
542 @c TODO: document complex-only/default/t of
543 @c @code{input-method-verbose-flag}
544 @vindex input-method-verbose-flag
545 @vindex input-method-highlight-flag
546 The variables @code{input-method-highlight-flag} and
547 @code{input-method-verbose-flag} control how input methods explain
548 what is happening. If @code{input-method-highlight-flag} is
549 non-@code{nil}, the partial sequence is highlighted in the buffer (for
550 most input methods---some disable this feature). If
551 @code{input-method-verbose-flag} is non-@code{nil}, the list of
552 possible characters to type next is displayed in the echo area (but
553 not when you are in the minibuffer).
554
555 Another facility for typing characters not on your keyboard is by
556 using @kbd{C-x 8 @key{RET}} (@code{insert-char}) to insert a single
557 character based on its Unicode name or code-point; see @ref{Inserting
558 Text}.
559
560 @node Select Input Method
561 @section Selecting an Input Method
562
563 @table @kbd
564 @item C-\
565 Enable or disable use of the selected input method (@code{toggle-input-method}).
566
567 @item C-x @key{RET} C-\ @var{method} @key{RET}
568 Select a new input method for the current buffer (@code{set-input-method}).
569
570 @item C-h I @var{method} @key{RET}
571 @itemx C-h C-\ @var{method} @key{RET}
572 @findex describe-input-method
573 @kindex C-h I
574 @kindex C-h C-\
575 Describe the input method @var{method} (@code{describe-input-method}).
576 By default, it describes the current input method (if any). This
577 description should give you the full details of how to use any
578 particular input method.
579
580 @item M-x list-input-methods
581 Display a list of all the supported input methods.
582 @end table
583
584 @findex set-input-method
585 @vindex current-input-method
586 @kindex C-x RET C-\
587 To choose an input method for the current buffer, use @kbd{C-x
588 @key{RET} C-\} (@code{set-input-method}). This command reads the
589 input method name from the minibuffer; the name normally starts with the
590 language environment that it is meant to be used with. The variable
591 @code{current-input-method} records which input method is selected.
592
593 @findex toggle-input-method
594 @kindex C-\
595 Input methods use various sequences of @acronym{ASCII} characters to
596 stand for non-@acronym{ASCII} characters. Sometimes it is useful to
597 turn off the input method temporarily. To do this, type @kbd{C-\}
598 (@code{toggle-input-method}). To reenable the input method, type
599 @kbd{C-\} again.
600
601 If you type @kbd{C-\} and you have not yet selected an input method,
602 it prompts you to specify one. This has the same effect as using
603 @kbd{C-x @key{RET} C-\} to specify an input method.
604
605 When invoked with a numeric argument, as in @kbd{C-u C-\},
606 @code{toggle-input-method} always prompts you for an input method,
607 suggesting the most recently selected one as the default.
608
609 @vindex default-input-method
610 Selecting a language environment specifies a default input method for
611 use in various buffers. When you have a default input method, you can
612 select it in the current buffer by typing @kbd{C-\}. The variable
613 @code{default-input-method} specifies the default input method
614 (@code{nil} means there is none).
615
616 In some language environments, which support several different input
617 methods, you might want to use an input method different from the
618 default chosen by @code{set-language-environment}. You can instruct
619 Emacs to select a different default input method for a certain
620 language environment, if you wish, by using
621 @code{set-language-environment-hook} (@pxref{Language Environments,
622 set-language-environment-hook}). For example:
623
624 @lisp
625 (defun my-chinese-setup ()
626 "Set up my private Chinese environment."
627 (if (equal current-language-environment "Chinese-GB")
628 (setq default-input-method "chinese-tonepy")))
629 (add-hook 'set-language-environment-hook 'my-chinese-setup)
630 @end lisp
631
632 @noindent
633 This sets the default input method to be @code{chinese-tonepy}
634 whenever you choose a Chinese-GB language environment.
635
636 You can instruct Emacs to activate a certain input method
637 automatically. For example:
638
639 @lisp
640 (add-hook 'text-mode-hook
641 (lambda () (set-input-method "german-prefix")))
642 @end lisp
643
644 @noindent
645 This automatically activates the input method @code{german-prefix} in
646 Text mode.
647
648 @findex quail-set-keyboard-layout
649 Some input methods for alphabetic scripts work by (in effect)
650 remapping the keyboard to emulate various keyboard layouts commonly used
651 for those scripts. How to do this remapping properly depends on your
652 actual keyboard layout. To specify which layout your keyboard has, use
653 the command @kbd{M-x quail-set-keyboard-layout}.
654
655 @findex quail-show-key
656 You can use the command @kbd{M-x quail-show-key} to show what key (or
657 key sequence) to type in order to input the character following point,
658 using the selected keyboard layout. The command @kbd{C-u C-x =} also
659 shows that information, in addition to other information about the
660 character.
661
662 @findex list-input-methods
663 @kbd{M-x list-input-methods} displays a list of all the supported
664 input methods. The list gives information about each input method,
665 including the string that stands for it in the mode line.
666
667 @node Coding Systems
668 @section Coding Systems
669 @cindex coding systems
670
671 Users of various languages have established many more-or-less standard
672 coding systems for representing them. Emacs does not use these coding
673 systems internally; instead, it converts from various coding systems to
674 its own system when reading data, and converts the internal coding
675 system to other coding systems when writing data. Conversion is
676 possible in reading or writing files, in sending or receiving from the
677 terminal, and in exchanging data with subprocesses.
678
679 Emacs assigns a name to each coding system. Most coding systems are
680 used for one language, and the name of the coding system starts with
681 the language name. Some coding systems are used for several
682 languages; their names usually start with @samp{iso}. There are also
683 special coding systems, such as @code{no-conversion}, @code{raw-text},
684 and @code{emacs-internal}.
685
686 @cindex international files from DOS/Windows systems
687 A special class of coding systems, collectively known as
688 @dfn{codepages}, is designed to support text encoded by MS-Windows and
689 MS-DOS software. The names of these coding systems are
690 @code{cp@var{nnnn}}, where @var{nnnn} is a 3- or 4-digit number of the
691 codepage. You can use these encodings just like any other coding
692 system; for example, to visit a file encoded in codepage 850, type
693 @kbd{C-x @key{RET} c cp850 @key{RET} C-x C-f @var{filename}
694 @key{RET}}.
695
696 In addition to converting various representations of non-@acronym{ASCII}
697 characters, a coding system can perform end-of-line conversion. Emacs
698 handles three different conventions for how to separate lines in a file:
699 newline (Unix), carriage-return linefeed (DOS), and just
700 carriage-return (Mac).
701
702 @table @kbd
703 @item C-h C @var{coding} @key{RET}
704 Describe coding system @var{coding} (@code{describe-coding-system}).
705
706 @item C-h C @key{RET}
707 Describe the coding systems currently in use.
708
709 @item M-x list-coding-systems
710 Display a list of all the supported coding systems.
711 @end table
712
713 @kindex C-h C
714 @findex describe-coding-system
715 The command @kbd{C-h C} (@code{describe-coding-system}) displays
716 information about particular coding systems, including the end-of-line
717 conversion specified by those coding systems. You can specify a coding
718 system name as the argument; alternatively, with an empty argument, it
719 describes the coding systems currently selected for various purposes,
720 both in the current buffer and as the defaults, and the priority list
721 for recognizing coding systems (@pxref{Recognize Coding}).
722
723 @findex list-coding-systems
724 To display a list of all the supported coding systems, type @kbd{M-x
725 list-coding-systems}. The list gives information about each coding
726 system, including the letter that stands for it in the mode line
727 (@pxref{Mode Line}).
728
729 @cindex end-of-line conversion
730 @cindex line endings
731 @cindex MS-DOS end-of-line conversion
732 @cindex Macintosh end-of-line conversion
733 Each of the coding systems that appear in this list---except for
734 @code{no-conversion}, which means no conversion of any kind---specifies
735 how and whether to convert printing characters, but leaves the choice of
736 end-of-line conversion to be decided based on the contents of each file.
737 For example, if the file appears to use the sequence carriage-return
738 linefeed to separate lines, DOS end-of-line conversion will be used.
739
740 Each of the listed coding systems has three variants, which specify
741 exactly what to do for end-of-line conversion:
742
743 @table @code
744 @item @dots{}-unix
745 Don't do any end-of-line conversion; assume the file uses
746 newline to separate lines. (This is the convention normally used
747 on Unix and GNU systems, and Mac OS X.)
748
749 @item @dots{}-dos
750 Assume the file uses carriage-return linefeed to separate lines, and do
751 the appropriate conversion. (This is the convention normally used on
752 Microsoft systems.@footnote{It is also specified for MIME @samp{text/*}
753 bodies and in other network transport contexts. It is different
754 from the SGML reference syntax record-start/record-end format, which
755 Emacs doesn't support directly.})
756
757 @item @dots{}-mac
758 Assume the file uses carriage-return to separate lines, and do the
759 appropriate conversion. (This was the convention used on the
760 Macintosh system prior to OS X.)
761 @end table
762
763 These variant coding systems are omitted from the
764 @code{list-coding-systems} display for brevity, since they are entirely
765 predictable. For example, the coding system @code{iso-latin-1} has
766 variants @code{iso-latin-1-unix}, @code{iso-latin-1-dos} and
767 @code{iso-latin-1-mac}.
768
769 @cindex @code{undecided}, coding system
770 The coding systems @code{unix}, @code{dos}, and @code{mac} are
771 aliases for @code{undecided-unix}, @code{undecided-dos}, and
772 @code{undecided-mac}, respectively. These coding systems specify only
773 the end-of-line conversion, and leave the character code conversion to
774 be deduced from the text itself.
775
776 @cindex @code{raw-text}, coding system
777 The coding system @code{raw-text} is good for a file which is mainly
778 @acronym{ASCII} text, but may contain byte values above 127 that are
779 not meant to encode non-@acronym{ASCII} characters. With
780 @code{raw-text}, Emacs copies those byte values unchanged, and sets
781 @code{enable-multibyte-characters} to @code{nil} in the current buffer
782 so that they will be interpreted properly. @code{raw-text} handles
783 end-of-line conversion in the usual way, based on the data
784 encountered, and has the usual three variants to specify the kind of
785 end-of-line conversion to use.
786
787 @cindex @code{no-conversion}, coding system
788 In contrast, the coding system @code{no-conversion} specifies no
789 character code conversion at all---none for non-@acronym{ASCII} byte values and
790 none for end of line. This is useful for reading or writing binary
791 files, tar files, and other files that must be examined verbatim. It,
792 too, sets @code{enable-multibyte-characters} to @code{nil}.
793
794 The easiest way to edit a file with no conversion of any kind is with
795 the @kbd{M-x find-file-literally} command. This uses
796 @code{no-conversion}, and also suppresses other Emacs features that
797 might convert the file contents before you see them. @xref{Visiting}.
798
799 @cindex @code{emacs-internal}, coding system
800 The coding system @code{emacs-internal} (or @code{utf-8-emacs},
801 which is equivalent) means that the file contains non-@acronym{ASCII}
802 characters stored with the internal Emacs encoding. This coding
803 system handles end-of-line conversion based on the data encountered,
804 and has the usual three variants to specify the kind of end-of-line
805 conversion.
806
807 @node Recognize Coding
808 @section Recognizing Coding Systems
809
810 Whenever Emacs reads a given piece of text, it tries to recognize
811 which coding system to use. This applies to files being read, output
812 from subprocesses, text from X selections, etc. Emacs can select the
813 right coding system automatically most of the time---once you have
814 specified your preferences.
815
816 Some coding systems can be recognized or distinguished by which byte
817 sequences appear in the data. However, there are coding systems that
818 cannot be distinguished, not even potentially. For example, there is no
819 way to distinguish between Latin-1 and Latin-2; they use the same byte
820 values with different meanings.
821
822 Emacs handles this situation by means of a priority list of coding
823 systems. Whenever Emacs reads a file, if you do not specify the coding
824 system to use, Emacs checks the data against each coding system,
825 starting with the first in priority and working down the list, until it
826 finds a coding system that fits the data. Then it converts the file
827 contents assuming that they are represented in this coding system.
828
829 The priority list of coding systems depends on the selected language
830 environment (@pxref{Language Environments}). For example, if you use
831 French, you probably want Emacs to prefer Latin-1 to Latin-2; if you use
832 Czech, you probably want Latin-2 to be preferred. This is one of the
833 reasons to specify a language environment.
834
835 @findex prefer-coding-system
836 However, you can alter the coding system priority list in detail
837 with the command @kbd{M-x prefer-coding-system}. This command reads
838 the name of a coding system from the minibuffer, and adds it to the
839 front of the priority list, so that it is preferred to all others. If
840 you use this command several times, each use adds one element to the
841 front of the priority list.
842
843 If you use a coding system that specifies the end-of-line conversion
844 type, such as @code{iso-8859-1-dos}, what this means is that Emacs
845 should attempt to recognize @code{iso-8859-1} with priority, and should
846 use DOS end-of-line conversion when it does recognize @code{iso-8859-1}.
847
848 @vindex file-coding-system-alist
849 Sometimes a file name indicates which coding system to use for the
850 file. The variable @code{file-coding-system-alist} specifies this
851 correspondence. There is a special function
852 @code{modify-coding-system-alist} for adding elements to this list. For
853 example, to read and write all @samp{.txt} files using the coding system
854 @code{chinese-iso-8bit}, you can execute this Lisp expression:
855
856 @smallexample
857 (modify-coding-system-alist 'file "\\.txt\\'" 'chinese-iso-8bit)
858 @end smallexample
859
860 @noindent
861 The first argument should be @code{file}, the second argument should be
862 a regular expression that determines which files this applies to, and
863 the third argument says which coding system to use for these files.
864
865 @vindex inhibit-eol-conversion
866 @cindex DOS-style end-of-line display
867 Emacs recognizes which kind of end-of-line conversion to use based on
868 the contents of the file: if it sees only carriage-returns, or only
869 carriage-return linefeed sequences, then it chooses the end-of-line
870 conversion accordingly. You can inhibit the automatic use of
871 end-of-line conversion by setting the variable @code{inhibit-eol-conversion}
872 to non-@code{nil}. If you do that, DOS-style files will be displayed
873 with the @samp{^M} characters visible in the buffer; some people
874 prefer this to the more subtle @samp{(DOS)} end-of-line type
875 indication near the left edge of the mode line (@pxref{Mode Line,
876 eol-mnemonic}).
877
878 @vindex inhibit-iso-escape-detection
879 @cindex escape sequences in files
880 By default, the automatic detection of coding system is sensitive to
881 escape sequences. If Emacs sees a sequence of characters that begin
882 with an escape character, and the sequence is valid as an ISO-2022
883 code, that tells Emacs to use one of the ISO-2022 encodings to decode
884 the file.
885
886 However, there may be cases that you want to read escape sequences
887 in a file as is. In such a case, you can set the variable
888 @code{inhibit-iso-escape-detection} to non-@code{nil}. Then the code
889 detection ignores any escape sequences, and never uses an ISO-2022
890 encoding. The result is that all escape sequences become visible in
891 the buffer.
892
893 The default value of @code{inhibit-iso-escape-detection} is
894 @code{nil}. We recommend that you not change it permanently, only for
895 one specific operation. That's because some Emacs Lisp source files
896 in the Emacs distribution contain non-@acronym{ASCII} characters encoded in the
897 coding system @code{iso-2022-7bit}, and they won't be
898 decoded correctly when you visit those files if you suppress the
899 escape sequence detection.
900 @c I count a grand total of 3 such files, so is the above really true?
901
902 @vindex auto-coding-alist
903 @vindex auto-coding-regexp-alist
904 The variables @code{auto-coding-alist} and
905 @code{auto-coding-regexp-alist} are
906 the strongest way to specify the coding system for certain patterns of
907 file names, or for files containing certain patterns, respectively.
908 These variables even override @samp{-*-coding:-*-} tags in the file
909 itself (@pxref{Specify Coding}). For example, Emacs
910 uses @code{auto-coding-alist} for tar and archive files, to prevent it
911 from being confused by a @samp{-*-coding:-*-} tag in a member of the
912 archive and thinking it applies to the archive file as a whole.
913 @ignore
914 @c This describes old-style BABYL files, which are no longer relevant.
915 Likewise, Emacs uses @code{auto-coding-regexp-alist} to ensure that
916 RMAIL files, whose names in general don't match any particular
917 pattern, are decoded correctly.
918 @end ignore
919
920 @vindex auto-coding-functions
921 Another way to specify a coding system is with the variable
922 @code{auto-coding-functions}. For example, one of the builtin
923 @code{auto-coding-functions} detects the encoding for XML files.
924 Unlike the previous two, this variable does not override any
925 @samp{-*-coding:-*-} tag.
926
927 @node Specify Coding
928 @section Specifying a File's Coding System
929
930 If Emacs recognizes the encoding of a file incorrectly, you can
931 reread the file using the correct coding system with @kbd{C-x
932 @key{RET} r} (@code{revert-buffer-with-coding-system}). This command
933 prompts for the coding system to use. To see what coding system Emacs
934 actually used to decode the file, look at the coding system mnemonic
935 letter near the left edge of the mode line (@pxref{Mode Line}), or
936 type @kbd{C-h C} (@code{describe-coding-system}).
937
938 @vindex coding
939 You can specify the coding system for a particular file in the file
940 itself, using the @w{@samp{-*-@dots{}-*-}} construct at the beginning,
941 or a local variables list at the end (@pxref{File Variables}). You do
942 this by defining a value for the ``variable'' named @code{coding}.
943 Emacs does not really have a variable @code{coding}; instead of
944 setting a variable, this uses the specified coding system for the
945 file. For example, @samp{-*-mode: C; coding: latin-1;-*-} specifies
946 use of the Latin-1 coding system, as well as C mode. When you specify
947 the coding explicitly in the file, that overrides
948 @code{file-coding-system-alist}.
949
950 @node Output Coding
951 @section Choosing Coding Systems for Output
952
953 @vindex buffer-file-coding-system
954 Once Emacs has chosen a coding system for a buffer, it stores that
955 coding system in @code{buffer-file-coding-system}. That makes it the
956 default for operations that write from this buffer into a file, such
957 as @code{save-buffer} and @code{write-region}. You can specify a
958 different coding system for further file output from the buffer using
959 @code{set-buffer-file-coding-system} (@pxref{Text Coding}).
960
961 You can insert any character Emacs supports into any Emacs buffer,
962 but most coding systems can only handle a subset of these characters.
963 Therefore, it's possible that the characters you insert cannot be
964 encoded with the coding system that will be used to save the buffer.
965 For example, you could visit a text file in Polish, encoded in
966 @code{iso-8859-2}, and add some Russian words to it. When you save
967 that buffer, Emacs cannot use the current value of
968 @code{buffer-file-coding-system}, because the characters you added
969 cannot be encoded by that coding system.
970
971 When that happens, Emacs tries the most-preferred coding system (set
972 by @kbd{M-x prefer-coding-system} or @kbd{M-x
973 set-language-environment}). If that coding system can safely encode
974 all of the characters in the buffer, Emacs uses it, and stores its
975 value in @code{buffer-file-coding-system}. Otherwise, Emacs displays
976 a list of coding systems suitable for encoding the buffer's contents,
977 and asks you to choose one of those coding systems.
978
979 If you insert the unsuitable characters in a mail message, Emacs
980 behaves a bit differently. It additionally checks whether the
981 @c What determines this?
982 most-preferred coding system is recommended for use in MIME messages;
983 if not, it informs you of this fact and prompts you for another coding
984 system. This is so you won't inadvertently send a message encoded in
985 a way that your recipient's mail software will have difficulty
986 decoding. (You can still use an unsuitable coding system if you enter
987 its name at the prompt.)
988
989 @c It seems that select-message-coding-system does this.
990 @c Both sendmail.el and smptmail.el call it; i.e., smtpmail.el still
991 @c obeys sendmail-coding-system.
992 @vindex sendmail-coding-system
993 When you send a mail message (@pxref{Sending Mail}),
994 Emacs has four different ways to determine the coding system to use
995 for encoding the message text. It tries the buffer's own value of
996 @code{buffer-file-coding-system}, if that is non-@code{nil}.
997 Otherwise, it uses the value of @code{sendmail-coding-system}, if that
998 is non-@code{nil}. The third way is to use the default coding system
999 for new files, which is controlled by your choice of language
1000 @c i.e., default-sendmail-coding-system
1001 environment, if that is non-@code{nil}. If all of these three values
1002 are @code{nil}, Emacs encodes outgoing mail using the Latin-1 coding
1003 system.
1004 @c FIXME? Where does the Latin-1 default come in?
1005
1006 @node Text Coding
1007 @section Specifying a Coding System for File Text
1008
1009 In cases where Emacs does not automatically choose the right coding
1010 system for a file's contents, you can use these commands to specify
1011 one:
1012
1013 @table @kbd
1014 @item C-x @key{RET} f @var{coding} @key{RET}
1015 Use coding system @var{coding} to save or revisit the file in
1016 the current buffer (@code{set-buffer-file-coding-system}).
1017
1018 @item C-x @key{RET} c @var{coding} @key{RET}
1019 Specify coding system @var{coding} for the immediately following
1020 command (@code{universal-coding-system-argument}).
1021
1022 @item C-x @key{RET} r @var{coding} @key{RET}
1023 Revisit the current file using the coding system @var{coding}
1024 (@code{revert-buffer-with-coding-system}).
1025
1026 @item M-x recode-region @key{RET} @var{right} @key{RET} @var{wrong} @key{RET}
1027 Convert a region that was decoded using coding system @var{wrong},
1028 decoding it using coding system @var{right} instead.
1029 @end table
1030
1031 @kindex C-x RET f
1032 @findex set-buffer-file-coding-system
1033 The command @kbd{C-x @key{RET} f}
1034 (@code{set-buffer-file-coding-system}) sets the file coding system for
1035 the current buffer (i.e., the coding system to use when saving or
1036 reverting the file). You specify which coding system using the
1037 minibuffer. You can also invoke this command by clicking with
1038 @kbd{Mouse-3} on the coding system indicator in the mode line
1039 (@pxref{Mode Line}).
1040
1041 If you specify a coding system that cannot handle all the characters
1042 in the buffer, Emacs will warn you about the troublesome characters,
1043 and ask you to choose another coding system, when you try to save the
1044 buffer (@pxref{Output Coding}).
1045
1046 @cindex specify end-of-line conversion
1047 You can also use this command to specify the end-of-line conversion
1048 (@pxref{Coding Systems, end-of-line conversion}) for encoding the
1049 current buffer. For example, @kbd{C-x @key{RET} f dos @key{RET}} will
1050 cause Emacs to save the current buffer's text with DOS-style
1051 carriage-return linefeed line endings.
1052
1053 @kindex C-x RET c
1054 @findex universal-coding-system-argument
1055 Another way to specify the coding system for a file is when you visit
1056 the file. First use the command @kbd{C-x @key{RET} c}
1057 (@code{universal-coding-system-argument}); this command uses the
1058 minibuffer to read a coding system name. After you exit the minibuffer,
1059 the specified coding system is used for @emph{the immediately following
1060 command}.
1061
1062 So if the immediately following command is @kbd{C-x C-f}, for example,
1063 it reads the file using that coding system (and records the coding
1064 system for when you later save the file). Or if the immediately following
1065 command is @kbd{C-x C-w}, it writes the file using that coding system.
1066 When you specify the coding system for saving in this way, instead
1067 of with @kbd{C-x @key{RET} f}, there is no warning if the buffer
1068 contains characters that the coding system cannot handle.
1069
1070 Other file commands affected by a specified coding system include
1071 @kbd{C-x i} and @kbd{C-x C-v}, as well as the other-window variants
1072 of @kbd{C-x C-f}. @kbd{C-x @key{RET} c} also affects commands that
1073 start subprocesses, including @kbd{M-x shell} (@pxref{Shell}). If the
1074 immediately following command does not use the coding system, then
1075 @kbd{C-x @key{RET} c} ultimately has no effect.
1076
1077 An easy way to visit a file with no conversion is with the @kbd{M-x
1078 find-file-literally} command. @xref{Visiting}.
1079
1080 The default value of the variable @code{buffer-file-coding-system}
1081 specifies the choice of coding system to use when you create a new file.
1082 It applies when you find a new file, and when you create a buffer and
1083 then save it in a file. Selecting a language environment typically sets
1084 this variable to a good choice of default coding system for that language
1085 environment.
1086
1087 @kindex C-x RET r
1088 @findex revert-buffer-with-coding-system
1089 If you visit a file with a wrong coding system, you can correct this
1090 with @kbd{C-x @key{RET} r} (@code{revert-buffer-with-coding-system}).
1091 This visits the current file again, using a coding system you specify.
1092
1093 @findex recode-region
1094 If a piece of text has already been inserted into a buffer using the
1095 wrong coding system, you can redo the decoding of it using @kbd{M-x
1096 recode-region}. This prompts you for the proper coding system, then
1097 for the wrong coding system that was actually used, and does the
1098 conversion. It first encodes the region using the wrong coding system,
1099 then decodes it again using the proper coding system.
1100
1101 @node Communication Coding
1102 @section Coding Systems for Interprocess Communication
1103
1104 This section explains how to specify coding systems for use
1105 in communication with other processes.
1106
1107 @table @kbd
1108 @item C-x @key{RET} x @var{coding} @key{RET}
1109 Use coding system @var{coding} for transferring selections to and from
1110 other graphical applications (@code{set-selection-coding-system}).
1111
1112 @item C-x @key{RET} X @var{coding} @key{RET}
1113 Use coding system @var{coding} for transferring @emph{one}
1114 selection---the next one---to or from another graphical application
1115 (@code{set-next-selection-coding-system}).
1116
1117 @item C-x @key{RET} p @var{input-coding} @key{RET} @var{output-coding} @key{RET}
1118 Use coding systems @var{input-coding} and @var{output-coding} for
1119 subprocess input and output in the current buffer
1120 (@code{set-buffer-process-coding-system}).
1121 @end table
1122
1123 @kindex C-x RET x
1124 @kindex C-x RET X
1125 @findex set-selection-coding-system
1126 @findex set-next-selection-coding-system
1127 The command @kbd{C-x @key{RET} x} (@code{set-selection-coding-system})
1128 specifies the coding system for sending selected text to other windowing
1129 applications, and for receiving the text of selections made in other
1130 applications. This command applies to all subsequent selections, until
1131 you override it by using the command again. The command @kbd{C-x
1132 @key{RET} X} (@code{set-next-selection-coding-system}) specifies the
1133 coding system for the next selection made in Emacs or read by Emacs.
1134
1135 @vindex x-select-request-type
1136 The variable @code{x-select-request-type} specifies the data type to
1137 request from the X Window System for receiving text selections from
1138 other applications. If the value is @code{nil} (the default), Emacs
1139 tries @code{UTF8_STRING} and @code{COMPOUND_TEXT}, in this order, and
1140 uses various heuristics to choose the more appropriate of the two
1141 results; if none of these succeed, Emacs falls back on @code{STRING}.
1142 If the value of @code{x-select-request-type} is one of the symbols
1143 @code{COMPOUND_TEXT}, @code{UTF8_STRING}, @code{STRING}, or
1144 @code{TEXT}, Emacs uses only that request type. If the value is a
1145 list of some of these symbols, Emacs tries only the request types in
1146 the list, in order, until one of them succeeds, or until the list is
1147 exhausted.
1148
1149 @kindex C-x RET p
1150 @findex set-buffer-process-coding-system
1151 The command @kbd{C-x @key{RET} p} (@code{set-buffer-process-coding-system})
1152 specifies the coding system for input and output to a subprocess. This
1153 command applies to the current buffer; normally, each subprocess has its
1154 own buffer, and thus you can use this command to specify translation to
1155 and from a particular subprocess by giving the command in the
1156 corresponding buffer.
1157
1158 You can also use @kbd{C-x @key{RET} c}
1159 (@code{universal-coding-system-argument}) just before the command that
1160 runs or starts a subprocess, to specify the coding system for
1161 communicating with that subprocess. @xref{Text Coding}.
1162
1163 The default for translation of process input and output depends on the
1164 current language environment.
1165
1166 @vindex locale-coding-system
1167 @cindex decoding non-@acronym{ASCII} keyboard input on X
1168 The variable @code{locale-coding-system} specifies a coding system
1169 to use when encoding and decoding system strings such as system error
1170 messages and @code{format-time-string} formats and time stamps. That
1171 coding system is also used for decoding non-@acronym{ASCII} keyboard
1172 input on the X Window System and for encoding text sent to the
1173 standard output and error streams when in batch mode. You should
1174 choose a coding system that is compatible
1175 with the underlying system's text representation, which is normally
1176 specified by one of the environment variables @env{LC_ALL},
1177 @env{LC_CTYPE}, and @env{LANG}. (The first one, in the order
1178 specified above, whose value is nonempty is the one that determines
1179 the text representation.)
1180
1181 @node File Name Coding
1182 @section Coding Systems for File Names
1183
1184 @table @kbd
1185 @item C-x @key{RET} F @var{coding} @key{RET}
1186 Use coding system @var{coding} for encoding and decoding file
1187 names (@code{set-file-name-coding-system}).
1188 @end table
1189
1190 @findex set-file-name-coding-system
1191 @kindex C-x @key{RET} F
1192 @cindex file names with non-@acronym{ASCII} characters
1193 The command @kbd{C-x @key{RET} F} (@code{set-file-name-coding-system})
1194 specifies a coding system to use for encoding file @emph{names}. It
1195 has no effect on reading and writing the @emph{contents} of files.
1196
1197 @vindex file-name-coding-system
1198 In fact, all this command does is set the value of the variable
1199 @code{file-name-coding-system}. If you set the variable to a coding
1200 system name (as a Lisp symbol or a string), Emacs encodes file names
1201 using that coding system for all file operations. This makes it
1202 possible to use non-@acronym{ASCII} characters in file names---or, at
1203 least, those non-@acronym{ASCII} characters that the specified coding
1204 system can encode.
1205
1206 If @code{file-name-coding-system} is @code{nil}, Emacs uses a
1207 default coding system determined by the selected language environment,
1208 and stored in the @code{default-file-name-coding-system} variable.
1209 @c FIXME? Is this correct? What is the "default language environment"?
1210 In the default language environment, non-@acronym{ASCII} characters in
1211 file names are not encoded specially; they appear in the file system
1212 using the internal Emacs representation.
1213
1214 @cindex file-name encoding, MS-Windows
1215 @vindex w32-unicode-filenames
1216 When Emacs runs on MS-Windows versions that are descendants of the
1217 NT family (Windows 2000, XP, Vista, Windows 7, and Windows 8), the
1218 value of @code{file-name-coding-system} is largely ignored, as Emacs
1219 by default uses APIs that allow to pass Unicode file names directly.
1220 By contrast, on Windows 9X, file names are encoded using
1221 @code{file-name-coding-system}, which should be set to the codepage
1222 (@pxref{Coding Systems, codepage}) pertinent for the current system
1223 locale. The value of the variable @code{w32-unicode-filenames}
1224 controls whether Emacs uses the Unicode APIs when it calls OS
1225 functions that accept file names. This variable is set by the startup
1226 code to @code{nil} on Windows 9X, and to @code{t} on newer versions of
1227 MS-Windows.
1228
1229 @strong{Warning:} if you change @code{file-name-coding-system} (or the
1230 language environment) in the middle of an Emacs session, problems can
1231 result if you have already visited files whose names were encoded using
1232 the earlier coding system and cannot be encoded (or are encoded
1233 differently) under the new coding system. If you try to save one of
1234 these buffers under the visited file name, saving may use the wrong file
1235 name, or it may encounter an error. If such a problem happens, use @kbd{C-x
1236 C-w} to specify a new file name for that buffer.
1237
1238 @findex recode-file-name
1239 If a mistake occurs when encoding a file name, use the command
1240 @kbd{M-x recode-file-name} to change the file name's coding
1241 system. This prompts for an existing file name, its old coding
1242 system, and the coding system to which you wish to convert.
1243
1244 @node Terminal Coding
1245 @section Coding Systems for Terminal I/O
1246
1247 @table @kbd
1248 @item C-x @key{RET} t @var{coding} @key{RET}
1249 Use coding system @var{coding} for terminal output
1250 (@code{set-terminal-coding-system}).
1251
1252 @item C-x @key{RET} k @var{coding} @key{RET}
1253 Use coding system @var{coding} for keyboard input
1254 (@code{set-keyboard-coding-system}).
1255 @end table
1256
1257 @kindex C-x RET t
1258 @findex set-terminal-coding-system
1259 The command @kbd{C-x @key{RET} t} (@code{set-terminal-coding-system})
1260 specifies the coding system for terminal output. If you specify a
1261 character code for terminal output, all characters output to the
1262 terminal are translated into that coding system.
1263
1264 This feature is useful for certain character-only terminals built to
1265 support specific languages or character sets---for example, European
1266 terminals that support one of the ISO Latin character sets. You need to
1267 specify the terminal coding system when using multibyte text, so that
1268 Emacs knows which characters the terminal can actually handle.
1269
1270 By default, output to the terminal is not translated at all, unless
1271 Emacs can deduce the proper coding system from your terminal type or
1272 your locale specification (@pxref{Language Environments}).
1273
1274 @kindex C-x RET k
1275 @findex set-keyboard-coding-system
1276 @vindex keyboard-coding-system
1277 The command @kbd{C-x @key{RET} k} (@code{set-keyboard-coding-system}),
1278 or the variable @code{keyboard-coding-system}, specifies the coding
1279 system for keyboard input. Character-code translation of keyboard
1280 input is useful for terminals with keys that send non-@acronym{ASCII}
1281 graphic characters---for example, some terminals designed for ISO
1282 Latin-1 or subsets of it.
1283
1284 By default, keyboard input is translated based on your system locale
1285 setting. If your terminal does not really support the encoding
1286 implied by your locale (for example, if you find it inserts a
1287 non-@acronym{ASCII} character if you type @kbd{M-i}), you will need to set
1288 @code{keyboard-coding-system} to @code{nil} to turn off encoding.
1289 You can do this by putting
1290
1291 @lisp
1292 (set-keyboard-coding-system nil)
1293 @end lisp
1294
1295 @noindent
1296 in your init file.
1297
1298 There is a similarity between using a coding system translation for
1299 keyboard input, and using an input method: both define sequences of
1300 keyboard input that translate into single characters. However, input
1301 methods are designed to be convenient for interactive use by humans, and
1302 the sequences that are translated are typically sequences of @acronym{ASCII}
1303 printing characters. Coding systems typically translate sequences of
1304 non-graphic characters.
1305
1306 @node Fontsets
1307 @section Fontsets
1308 @cindex fontsets
1309
1310 A font typically defines shapes for a single alphabet or script.
1311 Therefore, displaying the entire range of scripts that Emacs supports
1312 requires a collection of many fonts. In Emacs, such a collection is
1313 called a @dfn{fontset}. A fontset is defined by a list of font specifications,
1314 each assigned to handle a range of character codes, and may fall back
1315 on another fontset for characters that are not covered by the fonts
1316 it specifies.
1317
1318 @cindex fonts for various scripts
1319 @cindex Intlfonts package, installation
1320 Each fontset has a name, like a font. However, while fonts are
1321 stored in the system and the available font names are defined by the
1322 system, fontsets are defined within Emacs itself. Once you have
1323 defined a fontset, you can use it within Emacs by specifying its name,
1324 anywhere that you could use a single font. Of course, Emacs fontsets
1325 can use only the fonts that the system supports. If some characters
1326 appear on the screen as empty boxes or hex codes, this means that the
1327 fontset in use for them has no font for those characters. In this
1328 case, or if the characters are shown, but not as well as you would
1329 like, you may need to install extra fonts. Your operating system may
1330 have optional fonts that you can install; or you can install the GNU
1331 Intlfonts package, which includes fonts for most supported
1332 scripts.@footnote{If you run Emacs on X, you may need to inform the X
1333 server about the location of the newly installed fonts with commands
1334 such as:
1335 @c FIXME? I feel like this may be out of date.
1336 @c E.g., the intlfonts tarfile is ~ 10 years old.
1337
1338 @example
1339 xset fp+ /usr/local/share/emacs/fonts
1340 xset fp rehash
1341 @end example
1342 }
1343
1344 Emacs creates three fontsets automatically: the @dfn{standard
1345 fontset}, the @dfn{startup fontset} and the @dfn{default fontset}.
1346 @c FIXME? The doc of *standard*-fontset-spec says:
1347 @c "You have the biggest chance to display international characters
1348 @c with correct glyphs by using the *standard* fontset." (my emphasis)
1349 @c See http://lists.gnu.org/archive/html/emacs-devel/2012-04/msg00430.html
1350 The default fontset is most likely to have fonts for a wide variety of
1351 non-@acronym{ASCII} characters, and is the default fallback for the
1352 other two fontsets, and if you set a default font rather than fontset.
1353 However, it does not specify font family names, so results can be
1354 somewhat random if you use it directly. You can specify use of a
1355 particular fontset by starting Emacs with the @samp{-fn} option.
1356 For example,
1357
1358 @example
1359 emacs -fn fontset-standard
1360 @end example
1361
1362 @noindent
1363 You can also specify a fontset with the @samp{Font} resource (@pxref{X
1364 Resources}).
1365
1366 If no fontset is specified for use, then Emacs uses an
1367 @acronym{ASCII} font, with @samp{fontset-default} as a fallback for
1368 characters the font does not cover. The standard fontset is only used if
1369 explicitly requested, despite its name.
1370
1371 A fontset does not necessarily specify a font for every character
1372 code. If a fontset specifies no font for a certain character, or if
1373 it specifies a font that does not exist on your system, then it cannot
1374 display that character properly. It will display that character as a
1375 hex code or thin space or an empty box instead. (@xref{Text Display, ,
1376 glyphless characters}, for details.)
1377
1378 @node Defining Fontsets
1379 @section Defining fontsets
1380
1381 @vindex standard-fontset-spec
1382 @vindex w32-standard-fontset-spec
1383 @vindex ns-standard-fontset-spec
1384 @cindex standard fontset
1385 When running on X, Emacs creates a standard fontset automatically according to the value
1386 of @code{standard-fontset-spec}. This fontset's name is
1387
1388 @example
1389 -*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard
1390 @end example
1391
1392 @noindent
1393 or just @samp{fontset-standard} for short.
1394
1395 On GNUstep and Mac OS X, the standard fontset is created using the value of
1396 @code{ns-standard-fontset-spec}, and on MS Windows it is
1397 created using the value of @code{w32-standard-fontset-spec}.
1398
1399 @c FIXME? How does one access these, or do anything with them?
1400 @c Does it matter?
1401 Bold, italic, and bold-italic variants of the standard fontset are
1402 created automatically. Their names have @samp{bold} instead of
1403 @samp{medium}, or @samp{i} instead of @samp{r}, or both.
1404
1405 @cindex startup fontset
1406 Emacs generates a fontset automatically, based on any default
1407 @acronym{ASCII} font that you specify with the @samp{Font} resource or
1408 the @samp{-fn} argument, or the default font that Emacs found when it
1409 started. This is the @dfn{startup fontset} and its name is
1410 @code{fontset-startup}. It does this by replacing the
1411 @var{charset_registry} field with @samp{fontset}, and replacing
1412 @var{charset_encoding} field with @samp{startup}, then using the
1413 resulting string to specify a fontset.
1414
1415 For instance, if you start Emacs with a font of this form,
1416
1417 @c FIXME? I think this is a little misleading, because you cannot (?)
1418 @c actually specify a font with wildcards, it has to be a complete spec.
1419 @c Also, an X font specification of this form hasn't (?) been
1420 @c mentioned before now, and is somewhat obsolete these days.
1421 @c People are more likely to use a form like
1422 @c emacs -fn "DejaVu Sans Mono-12"
1423 @c How does any of this apply in that case?
1424 @example
1425 emacs -fn "*courier-medium-r-normal--14-140-*-iso8859-1"
1426 @end example
1427
1428 @noindent
1429 Emacs generates the following fontset and uses it for the initial X
1430 window frame:
1431
1432 @example
1433 -*-courier-medium-r-normal-*-14-140-*-*-*-*-fontset-startup
1434 @end example
1435
1436 The startup fontset will use the font that you specify, or a variant
1437 with a different registry and encoding, for all the characters that
1438 are supported by that font, and fallback on @samp{fontset-default} for
1439 other characters.
1440
1441 With the X resource @samp{Emacs.Font}, you can specify a fontset name
1442 just like an actual font name. But be careful not to specify a fontset
1443 name in a wildcard resource like @samp{Emacs*Font}---that wildcard
1444 specification matches various other resources, such as for menus, and
1445 @c FIXME is this still true?
1446 menus cannot handle fontsets. @xref{X Resources}.
1447
1448 You can specify additional fontsets using X resources named
1449 @samp{Fontset-@var{n}}, where @var{n} is an integer starting from 0.
1450 The resource value should have this form:
1451
1452 @smallexample
1453 @var{fontpattern}, @r{[}@var{charset}:@var{font}@r{]@dots{}}
1454 @end smallexample
1455
1456 @noindent
1457 @var{fontpattern} should have the form of a standard X font name (see
1458 the previous fontset-startup example), except
1459 for the last two fields. They should have the form
1460 @samp{fontset-@var{alias}}.
1461
1462 The fontset has two names, one long and one short. The long name is
1463 @var{fontpattern}. The short name is @samp{fontset-@var{alias}}. You
1464 can refer to the fontset by either name.
1465
1466 The construct @samp{@var{charset}:@var{font}} specifies which font to
1467 use (in this fontset) for one particular character set. Here,
1468 @var{charset} is the name of a character set, and @var{font} is the
1469 font to use for that character set. You can use this construct any
1470 number of times in defining one fontset.
1471
1472 For the other character sets, Emacs chooses a font based on
1473 @var{fontpattern}. It replaces @samp{fontset-@var{alias}} with values
1474 that describe the character set. For the @acronym{ASCII} character font,
1475 @samp{fontset-@var{alias}} is replaced with @samp{ISO8859-1}.
1476
1477 In addition, when several consecutive fields are wildcards, Emacs
1478 collapses them into a single wildcard. This is to prevent use of
1479 auto-scaled fonts. Fonts made by scaling larger fonts are not usable
1480 for editing, and scaling a smaller font is not also useful, because it is
1481 better to use the smaller font in its own size, which is what Emacs
1482 does.
1483
1484 Thus if @var{fontpattern} is this,
1485
1486 @example
1487 -*-fixed-medium-r-normal-*-24-*-*-*-*-*-fontset-24
1488 @end example
1489
1490 @noindent
1491 the font specification for @acronym{ASCII} characters would be this:
1492
1493 @example
1494 -*-fixed-medium-r-normal-*-24-*-ISO8859-1
1495 @end example
1496
1497 @noindent
1498 and the font specification for Chinese GB2312 characters would be this:
1499
1500 @example
1501 -*-fixed-medium-r-normal-*-24-*-gb2312*-*
1502 @end example
1503
1504 You may not have any Chinese font matching the above font
1505 specification. Most X distributions include only Chinese fonts that
1506 have @samp{song ti} or @samp{fangsong ti} in the @var{family} field. In
1507 such a case, @samp{Fontset-@var{n}} can be specified as:
1508
1509 @smallexample
1510 Emacs.Fontset-0: -*-fixed-medium-r-normal-*-24-*-*-*-*-*-fontset-24,\
1511 chinese-gb2312:-*-*-medium-r-normal-*-24-*-gb2312*-*
1512 @end smallexample
1513
1514 @noindent
1515 Then, the font specifications for all but Chinese GB2312 characters have
1516 @samp{fixed} in the @var{family} field, and the font specification for
1517 Chinese GB2312 characters has a wild card @samp{*} in the @var{family}
1518 field.
1519
1520 @findex create-fontset-from-fontset-spec
1521 The function that processes the fontset resource value to create the
1522 fontset is called @code{create-fontset-from-fontset-spec}. You can also
1523 call this function explicitly to create a fontset.
1524
1525 @xref{Fonts}, for more information about font naming.
1526
1527 @node Modifying Fontsets
1528 @section Modifying Fontsets
1529 @cindex fontsets, modifying
1530 @findex set-fontset-font
1531
1532 Fontsets do not always have to be created from scratch. If only
1533 minor changes are required it may be easier to modify an existing
1534 fontset. Modifying @samp{fontset-default} will also affect other
1535 fontsets that use it as a fallback, so can be an effective way of
1536 fixing problems with the fonts that Emacs chooses for a particular
1537 script.
1538
1539 Fontsets can be modified using the function @code{set-fontset-font},
1540 specifying a character, a charset, a script, or a range of characters
1541 to modify the font for, and a font specification for the font to be
1542 used. Some examples are:
1543
1544 @example
1545 ;; Use Liberation Mono for latin-3 charset.
1546 (set-fontset-font "fontset-default" 'iso-8859-3
1547 "Liberation Mono")
1548
1549 ;; Prefer a big5 font for han characters
1550 (set-fontset-font "fontset-default"
1551 'han (font-spec :registry "big5")
1552 nil 'prepend)
1553
1554 ;; Use DejaVu Sans Mono as a fallback in fontset-startup
1555 ;; before resorting to fontset-default.
1556 (set-fontset-font "fontset-startup" nil "DejaVu Sans Mono"
1557 nil 'append)
1558
1559 ;; Use MyPrivateFont for the Unicode private use area.
1560 (set-fontset-font "fontset-default" '(#xe000 . #xf8ff)
1561 "MyPrivateFont")
1562
1563 @end example
1564
1565 @cindex ignore font
1566 @cindex fonts, how to ignore
1567 @vindex face-ignored-fonts
1568 Some fonts installed on your system might be broken, or produce
1569 unpleasant results for characters for which they are used, and you may
1570 wish to instruct Emacs to completely ignore them while searching for a
1571 suitable font required to display a character. You can do that by
1572 adding the offending fonts to the value of @code{face-ignored-fonts}
1573 variable, which is a list. Here's an example to put in your
1574 @file{~/.emacs}:
1575
1576 @example
1577 (add-to-list 'face-ignored-fonts "Some Bad Font")
1578 @end example
1579
1580 @node Undisplayable Characters
1581 @section Undisplayable Characters
1582
1583 There may be some non-@acronym{ASCII} characters that your
1584 terminal cannot display. Most text terminals support just a single
1585 character set (use the variable @code{default-terminal-coding-system}
1586 to tell Emacs which one, @ref{Terminal Coding}); characters that
1587 can't be encoded in that coding system are displayed as @samp{?} by
1588 default.
1589
1590 Graphical displays can display a broader range of characters, but
1591 you may not have fonts installed for all of them; characters that have
1592 no font appear as a hollow box.
1593
1594 If you use Latin-1 characters but your terminal can't display
1595 Latin-1, you can arrange to display mnemonic @acronym{ASCII} sequences
1596 instead, e.g., @samp{"o} for o-umlaut. Load the library
1597 @file{iso-ascii} to do this.
1598
1599 @vindex latin1-display
1600 If your terminal can display Latin-1, you can display characters
1601 from other European character sets using a mixture of equivalent
1602 Latin-1 characters and @acronym{ASCII} mnemonics. Customize the variable
1603 @code{latin1-display} to enable this. The mnemonic @acronym{ASCII}
1604 sequences mostly correspond to those of the prefix input methods.
1605
1606 @node Unibyte Mode
1607 @section Unibyte Editing Mode
1608
1609 @cindex European character sets
1610 @cindex accented characters
1611 @cindex ISO Latin character sets
1612 @cindex Unibyte operation
1613 The ISO 8859 Latin-@var{n} character sets define character codes in
1614 the range 0240 to 0377 octal (160 to 255 decimal) to handle the
1615 accented letters and punctuation needed by various European languages
1616 (and some non-European ones). Note that Emacs considers bytes with
1617 codes in this range as raw bytes, not as characters, even in a unibyte
1618 buffer, i.e., if you disable multibyte characters. However, Emacs can
1619 still handle these character codes as if they belonged to @emph{one}
1620 of the single-byte character sets at a time. To specify @emph{which}
1621 of these codes to use, invoke @kbd{M-x set-language-environment} and
1622 specify a suitable language environment such as @samp{Latin-@var{n}}.
1623 @xref{Disabling Multibyte, , Disabling Multibyte Characters, elisp,
1624 GNU Emacs Lisp Reference Manual}.
1625
1626 @vindex unibyte-display-via-language-environment
1627 Emacs can also display bytes in the range 160 to 255 as readable
1628 characters, provided the terminal or font in use supports them. This
1629 works automatically. On a graphical display, Emacs can also display
1630 single-byte characters through fontsets, in effect by displaying the
1631 equivalent multibyte characters according to the current language
1632 environment. To request this, set the variable
1633 @code{unibyte-display-via-language-environment} to a non-@code{nil}
1634 value. Note that setting this only affects how these bytes are
1635 displayed, but does not change the fundamental fact that Emacs treats
1636 them as raw bytes, not as characters.
1637
1638 @cindex @code{iso-ascii} library
1639 If your terminal does not support display of the Latin-1 character
1640 set, Emacs can display these characters as @acronym{ASCII} sequences which at
1641 least give you a clear idea of what the characters are. To do this,
1642 load the library @code{iso-ascii}. Similar libraries for other
1643 Latin-@var{n} character sets could be implemented, but have not been
1644 so far.
1645
1646 @findex standard-display-8bit
1647 @cindex 8-bit display
1648 Normally non-ISO-8859 characters (decimal codes between 128 and 159
1649 inclusive) are displayed as octal escapes. You can change this for
1650 non-standard extended versions of ISO-8859 character sets by using the
1651 function @code{standard-display-8bit} in the @code{disp-table} library.
1652
1653 There are two ways to input single-byte non-@acronym{ASCII}
1654 characters:
1655
1656 @itemize @bullet
1657 @cindex 8-bit input
1658 @item
1659 You can use an input method for the selected language environment.
1660 @xref{Input Methods}. When you use an input method in a unibyte buffer,
1661 the non-@acronym{ASCII} character you specify with it is converted to unibyte.
1662
1663 @item
1664 If your keyboard can generate character codes 128 (decimal) and up,
1665 representing non-@acronym{ASCII} characters, you can type those character codes
1666 directly.
1667
1668 On a graphical display, you should not need to do anything special to
1669 use these keys; they should simply work. On a text terminal, you
1670 should use the command @code{M-x set-keyboard-coding-system} or customize the
1671 variable @code{keyboard-coding-system} to specify which coding system
1672 your keyboard uses (@pxref{Terminal Coding}). Enabling this feature
1673 will probably require you to use @key{ESC} to type Meta characters;
1674 however, on a console terminal or in @code{xterm}, you can arrange for
1675 Meta to be converted to @key{ESC} and still be able type 8-bit
1676 characters present directly on the keyboard or using @key{Compose} or
1677 @key{AltGr} keys. @xref{User Input}.
1678
1679 @kindex C-x 8
1680 @cindex @code{iso-transl} library
1681 @cindex compose character
1682 @cindex dead character
1683 @item
1684 You can use the key @kbd{C-x 8} as a compose-character prefix for
1685 entry of non-@acronym{ASCII} Latin-1 and a few other printing
1686 characters. @kbd{C-x 8} is good for insertion (in the minibuffer as
1687 well as other buffers), for searching, and in any other context where
1688 a key sequence is allowed.
1689
1690 @kbd{C-x 8} works by loading the @code{iso-transl} library. Once that
1691 library is loaded, the @key{Alt} modifier key, if the keyboard has
1692 one, serves the same purpose as @kbd{C-x 8}: use @key{Alt} together
1693 with an accent character to modify the following letter. In addition,
1694 if the keyboard has keys for the Latin-1 dead accent characters,
1695 they too are defined to compose with the following character, once
1696 @code{iso-transl} is loaded.
1697
1698 Use @kbd{C-x 8 C-h} to list all the available @kbd{C-x 8} translations.
1699 @end itemize
1700
1701 @node Charsets
1702 @section Charsets
1703 @cindex charsets
1704
1705 In Emacs, @dfn{charset} is short for ``character set''. Emacs
1706 supports most popular charsets (such as @code{ascii},
1707 @code{iso-8859-1}, @code{cp1250}, @code{big5}, and @code{unicode}), in
1708 addition to some charsets of its own (such as @code{emacs},
1709 @code{unicode-bmp}, and @code{eight-bit}). All supported characters
1710 belong to one or more charsets.
1711
1712 Emacs normally does the right thing with respect to charsets, so
1713 that you don't have to worry about them. However, it is sometimes
1714 helpful to know some of the underlying details about charsets.
1715
1716 One example is font selection (@pxref{Fonts}). Each language
1717 environment (@pxref{Language Environments}) defines a priority
1718 list for the various charsets. When searching for a font, Emacs
1719 initially attempts to find one that can display the highest-priority
1720 charsets. For instance, in the Japanese language environment, the
1721 charset @code{japanese-jisx0208} has the highest priority, so Emacs
1722 tries to use a font whose @code{registry} property is
1723 @samp{JISX0208.1983-0}.
1724
1725 @findex list-charset-chars
1726 @cindex characters in a certain charset
1727 @findex describe-character-set
1728 There are two commands that can be used to obtain information about
1729 charsets. The command @kbd{M-x list-charset-chars} prompts for a
1730 charset name, and displays all the characters in that character set.
1731 The command @kbd{M-x describe-character-set} prompts for a charset
1732 name, and displays information about that charset, including its
1733 internal representation within Emacs.
1734
1735 @findex list-character-sets
1736 @kbd{M-x list-character-sets} displays a list of all supported
1737 charsets. The list gives the names of charsets and additional
1738 information to identity each charset; for more details, see the
1739 @url{https://www.itscj.ipsj.or.jp/itscj_english/iso-ir/ISO-IR.pdf,
1740 ISO International Register of Coded Character Sets to be Used with
1741 Escape Sequences (ISO-IR)} maintained by
1742 the @url{https://www.itscj.ipsj.or.jp/itscj_english/,
1743 Information Processing Society of Japan/Information Technology
1744 Standards Commission of Japan (IPSJ/ITSCJ)}. In this list,
1745 charsets are divided into two categories: @dfn{normal charsets} are
1746 listed first, followed by @dfn{supplementary charsets}. A
1747 supplementary charset is one that is used to define another charset
1748 (as a parent or a subset), or to provide backward-compatibility for
1749 older Emacs versions.
1750
1751 To find out which charset a character in the buffer belongs to, put
1752 point before it and type @kbd{C-u C-x =} (@pxref{International
1753 Chars}).
1754
1755 @node Bidirectional Editing
1756 @section Bidirectional Editing
1757 @cindex bidirectional editing
1758 @cindex right-to-left text
1759
1760 Emacs supports editing text written in scripts, such as Arabic and
1761 Hebrew, whose natural ordering of horizontal text for display is from
1762 right to left. However, digits and Latin text embedded in these
1763 scripts are still displayed left to right. It is also not uncommon to
1764 have small portions of text in Arabic or Hebrew embedded in an otherwise
1765 Latin document; e.g., as comments and strings in a program source
1766 file. For these reasons, text that uses these scripts is actually
1767 @dfn{bidirectional}: a mixture of runs of left-to-right and
1768 right-to-left characters.
1769
1770 This section describes the facilities and options provided by Emacs
1771 for editing bidirectional text.
1772
1773 @cindex logical order
1774 @cindex visual order
1775 Emacs stores right-to-left and bidirectional text in the so-called
1776 @dfn{logical} (or @dfn{reading}) order: the buffer or string position
1777 of the first character you read precedes that of the next character.
1778 Reordering of bidirectional text into the @dfn{visual} order happens
1779 at display time. As result, character positions no longer increase
1780 monotonically with their positions on display. Emacs implements the
1781 Unicode Bidirectional Algorithm described in the Unicode Standard
1782 Annex #9, for reordering of bidirectional text for display.
1783
1784 @vindex bidi-display-reordering
1785 The buffer-local variable @code{bidi-display-reordering} controls
1786 whether text in the buffer is reordered for display. If its value is
1787 non-@code{nil}, Emacs reorders characters that have right-to-left
1788 directionality when they are displayed. The default value is
1789 @code{t}.
1790
1791 @cindex base direction of paragraphs
1792 @cindex paragraph, base direction
1793 Each paragraph of bidirectional text can have its own @dfn{base
1794 direction}, either right-to-left or left-to-right. (Paragraph
1795 @c paragraph-separate etc have no influence on this?
1796 boundaries are empty lines, i.e., lines consisting entirely of
1797 whitespace characters.) Text in left-to-right paragraphs begins on
1798 the screen at the left margin of the window and is truncated or
1799 continued when it reaches the right margin. By contrast, text in
1800 right-to-left paragraphs is displayed starting at the right margin and
1801 is continued or truncated at the left margin.
1802
1803 @vindex bidi-paragraph-direction
1804 Emacs determines the base direction of each paragraph dynamically,
1805 based on the text at the beginning of the paragraph. However,
1806 sometimes a buffer may need to force a certain base direction for its
1807 paragraphs. The variable @code{bidi-paragraph-direction}, if
1808 non-@code{nil}, disables the dynamic determination of the base
1809 direction, and instead forces all paragraphs in the buffer to have the
1810 direction specified by its buffer-local value. The value can be either
1811 @code{right-to-left} or @code{left-to-right}. Any other value is
1812 interpreted as @code{nil}.
1813
1814 @cindex LRM
1815 @cindex RLM
1816 Alternatively, you can control the base direction of a paragraph by
1817 inserting special formatting characters in front of the paragraph.
1818 The special character @code{RIGHT-TO-LEFT MARK}, or @sc{rlm}, forces
1819 the right-to-left direction on the following paragraph, while
1820 @code{LEFT-TO-RIGHT MARK}, or @sc{lrm} forces the left-to-right
1821 direction. (You can use @kbd{C-x 8 @key{RET}} to insert these characters.)
1822 In a GUI session, the @sc{lrm} and @sc{rlm} characters display as very
1823 thin blank characters; on text terminals they display as blanks.
1824
1825 Because characters are reordered for display, Emacs commands that
1826 operate in the logical order or on stretches of buffer positions may
1827 produce unusual effects. For example, @kbd{C-f} and @kbd{C-b}
1828 commands move point in the logical order, so the cursor will sometimes
1829 jump when point traverses reordered bidirectional text. Similarly, a
1830 highlighted region covering a contiguous range of character positions
1831 may look discontinuous if the region spans reordered text. This is
1832 normal and similar to the behavior of other programs that support
1833 bidirectional text. If you set @code{visual-order-cursor-movement} to
1834 a non-@code{nil} value, cursor motion by the arrow keys follows the
1835 visual order on screen (@pxref{Moving Point, visual-order movement}).