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