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