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