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