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