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