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