/
mule.texi
1658 lines (1407 loc) · 73.3 KB
/
mule.texi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@c This is part of the Emacs manual.
@c Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003, 2004,
@c 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
@c See file emacs.texi for copying conditions.
@node International, Major Modes, Frames, Top
@chapter International Character Set Support
@c This node is referenced in the tutorial. When renaming or deleting
@c it, the tutorial needs to be adjusted. (TUTORIAL.de)
@cindex MULE
@cindex international scripts
@cindex multibyte characters
@cindex encoding of characters
@cindex Celtic
@cindex Chinese
@cindex Cyrillic
@cindex Czech
@cindex Devanagari
@cindex Hindi
@cindex Marathi
@cindex Ethiopic
@cindex German
@cindex Greek
@cindex Hebrew
@cindex IPA
@cindex Japanese
@cindex Korean
@cindex Lao
@cindex Latin
@cindex Polish
@cindex Romanian
@cindex Slovak
@cindex Slovenian
@cindex Thai
@cindex Tibetan
@cindex Turkish
@cindex Vietnamese
@cindex Dutch
@cindex Spanish
Emacs supports a wide variety of international character sets,
including European and Vietnamese variants of the Latin alphabet, as
well as Cyrillic, Devanagari (for Hindi and Marathi), Ethiopic, Greek,
Han (for Chinese and Japanese), Hangul (for Korean), Hebrew, IPA,
Kannada, Lao, Malayalam, Tamil, Thai, Tibetan, and Vietnamese scripts.
Emacs also supports various encodings of these characters used by
other internationalized software, such as word processors and mailers.
Emacs allows editing text with international characters by supporting
all the related activities:
@itemize @bullet
@item
You can visit files with non-@acronym{ASCII} characters, save non-@acronym{ASCII} text, and
pass non-@acronym{ASCII} text between Emacs and programs it invokes (such as
compilers, spell-checkers, and mailers). Setting your language
environment (@pxref{Language Environments}) takes care of setting up the
coding systems and other options for a specific language or culture.
Alternatively, you can specify how Emacs should encode or decode text
for each command; see @ref{Text Coding}.
@item
You can display non-@acronym{ASCII} characters encoded by the various
scripts. This works by using appropriate fonts on graphics displays
(@pxref{Defining Fontsets}), and by sending special codes to text-only
displays (@pxref{Terminal Coding}). If some characters are displayed
incorrectly, refer to @ref{Undisplayable Characters}, which describes
possible problems and explains how to solve them.
@item
You can insert non-@acronym{ASCII} characters or search for them. To do that,
you can specify an input method (@pxref{Select Input Method}) suitable
for your language, or use the default input method set up when you set
your language environment. If
your keyboard can produce non-@acronym{ASCII} characters, you can select an
appropriate keyboard coding system (@pxref{Terminal Coding}), and Emacs
will accept those characters. Latin-1 characters can also be input by
using the @kbd{C-x 8} prefix, see @ref{Unibyte Mode}.
On X Window systems, your locale should be set to an appropriate value
to make sure Emacs interprets keyboard input correctly; see
@ref{Language Environments, locales}.
@end itemize
The rest of this chapter describes these issues in detail.
@menu
* International Chars:: Basic concepts of multibyte characters.
* Enabling Multibyte:: Controlling whether to use multibyte characters.
* Language Environments:: Setting things up for the language you use.
* Input Methods:: Entering text characters not on your keyboard.
* Select Input Method:: Specifying your choice of input methods.
* Coding Systems:: Character set conversion when you read and
write files, and so on.
* Recognize Coding:: How Emacs figures out which conversion to use.
* Specify Coding:: Specifying a file's coding system explicitly.
* Output Coding:: Choosing coding systems for output.
* Text Coding:: Choosing conversion to use for file text.
* Communication Coding:: Coding systems for interprocess communication.
* File Name Coding:: Coding systems for file @emph{names}.
* Terminal Coding:: Specifying coding systems for converting
terminal input and output.
* Fontsets:: Fontsets are collections of fonts
that cover the whole spectrum of characters.
* Defining Fontsets:: Defining a new fontset.
* Modifying Fontsets:: Modifying an existing fontset.
* Undisplayable Characters:: When characters don't display.
* Unibyte Mode:: You can pick one European character set
to use without multibyte characters.
* Charsets:: How Emacs groups its internal character codes.
@end menu
@node International Chars
@section Introduction to International Character Sets
The users of international character sets and scripts have
established many more-or-less standard coding systems for storing
files. These coding systems are typically @dfn{multibyte}, meaning
that sequences of two or more bytes are used to represent individual
non-@acronym{ASCII} characters.
@cindex Unicode
Internally, Emacs uses its own multibyte character encoding, which
is a superset of the @dfn{Unicode} standard. This internal encoding
allows characters from almost every known script to be intermixed in a
single buffer or string. Emacs translates between the multibyte
character encoding and various other coding systems when reading and
writing files, and when exchanging data with subprocesses.
@kindex C-h h
@findex view-hello-file
@cindex undisplayable characters
@cindex @samp{?} in display
The command @kbd{C-h h} (@code{view-hello-file}) displays the file
@file{etc/HELLO}, which shows how to say ``hello'' in many languages.
This illustrates various scripts. If some characters can't be
displayed on your terminal, they appear as @samp{?} or as hollow boxes
(@pxref{Undisplayable Characters}).
Keyboards, even in the countries where these character sets are
used, generally don't have keys for all the characters in them. You
can insert characters that your keyboard does not support, using
@kbd{C-q} (@code{quoted-insert}) or @kbd{C-x 8 @key{RET}}
(@code{ucs-insert}). @xref{Inserting Text}. Emacs also supports
various @dfn{input methods}, typically one for each script or
language, which make it easier to type characters in the script.
@xref{Input Methods}.
@kindex C-x RET
The prefix key @kbd{C-x @key{RET}} is used for commands that pertain
to multibyte characters, coding systems, and input methods.
@kindex C-x =
@findex what-cursor-position
The command @kbd{C-x =} (@code{what-cursor-position}) shows
information about the character at point. In addition to the
character position, which was described in @ref{Position Info}, this
command displays how the character is encoded. For instance, it
displays the following line in the echo area for the character
@samp{c}:
@smallexample
Char: c (99, #o143, #x63) point=28062 of 36168 (78%) column=53
@end smallexample
The four values after @samp{Char:} describe the character that
follows point, first by showing it and then by giving its character
code in decimal, octal and hex. For a non-@acronym{ASCII} multibyte
character, these are followed by @samp{file} and the character's
representation, in hex, in the buffer's coding system, if that coding
system encodes the character safely and with a single byte
(@pxref{Coding Systems}). If the character's encoding is longer than
one byte, Emacs shows @samp{file ...}.
As a special case, if the character lies in the range 128 (0200
octal) through 159 (0237 octal), it stands for a ``raw'' byte that
does not correspond to any specific displayable character. Such a
``character'' lies within the @code{eight-bit-control} character set,
and is displayed as an escaped octal character code. In this case,
@kbd{C-x =} shows @samp{part of display ...} instead of @samp{file}.
@cindex character set of character at point
@cindex font of character at point
@cindex text properties at point
@cindex face at point
With a prefix argument (@kbd{C-u C-x =}), this command displays a
detailed description of the character in a window:
@itemize @bullet
@item
The character set name, and the codes that identify the character
within that character set; @acronym{ASCII} characters are identified
as belonging to the @code{ascii} character set.
@item
The character's syntax and categories.
@item
The character's encodings, both internally in the buffer, and externally
if you were to save the file.
@item
What keys to type to input the character in the current input method
(if it supports the character).
@item
If you are running Emacs on a graphical display, the font name and
glyph code for the character. If you are running Emacs on a text-only
terminal, the code(s) sent to the terminal.
@item
The character's text properties (@pxref{Text Properties,,,
elisp, the Emacs Lisp Reference Manual}), including any non-default
faces used to display the character, and any overlays containing it
(@pxref{Overlays,,, elisp, the same manual}).
@end itemize
Here's an example showing the Latin-1 character A with grave accent,
in a buffer whose coding system is @code{utf-8-unix}:
@smallexample
character: @`A (192, #o300, #xc0)
preferred charset: unicode (Unicode (ISO10646))
code point: 0xC0
syntax: w which means: word
category: j:Japanese l:Latin v:Vietnamese
buffer code: #xC3 #x80
file code: not encodable by coding system undecided-unix
display: by this font (glyph code)
xft:-unknown-DejaVu Sans Mono-normal-normal-normal-*-13-*-*-*-m-0-iso10646-1 (#x82)
Character code properties: customize what to show
name: LATIN CAPITAL LETTER A WITH GRAVE
general-category: Lu (Letter, Uppercase)
decomposition: (65 768) ('A' '̀')
old-name: LATIN CAPITAL LETTER A GRAVE
There are text properties here:
auto-composed t
@end smallexample
@node Enabling Multibyte
@section Enabling Multibyte Characters
By default, Emacs starts in multibyte mode: it stores the contents
of buffers and strings using an internal encoding that represents
non-@acronym{ASCII} characters using multi-byte sequences. Multibyte
mode allows you to use all the supported languages and scripts without
limitations.
@cindex turn multibyte support on or off
Under very special circumstances, you may want to disable multibyte
character support, for a specific buffer.
When multibyte characters are disabled in a buffer, we call
that @dfn{unibyte mode}. In unibyte mode, each character in the
buffer has a character code ranging from 0 through 255 (0377 octal); 0
through 127 (0177 octal) represent @acronym{ASCII} characters, and 128
(0200 octal) through 255 (0377 octal) represent non-@acronym{ASCII}
characters.
To edit a particular file in unibyte representation, visit it using
@code{find-file-literally}. @xref{Visiting}. You can convert a
multibyte buffer to unibyte by saving it to a file, killing the
buffer, and visiting the file again with @code{find-file-literally}.
Alternatively, you can use @kbd{C-x @key{RET} c}
(@code{universal-coding-system-argument}) and specify @samp{raw-text}
as the coding system with which to visit or save a file. @xref{Text
Coding}. Unlike @code{find-file-literally}, finding a file as
@samp{raw-text} doesn't disable format conversion, uncompression, or
auto mode selection.
@cindex Lisp files, and multibyte operation
@cindex multibyte operation, and Lisp files
@cindex unibyte operation, and Lisp files
@cindex init file, and non-@acronym{ASCII} characters
Emacs normally loads Lisp files as multibyte.
This includes the Emacs initialization
file, @file{.emacs}, and the initialization files of Emacs packages
such as Gnus. However, you can specify unibyte loading for a
particular Lisp file, by putting @w{@samp{-*-unibyte: t;-*-}} in a
comment on the first line (@pxref{File Variables}). Then that file is
always loaded as unibyte text. The motivation for these conventions
is that it is more reliable to always load any particular Lisp file in
the same way. However, you can load a Lisp file as unibyte, on any
one occasion, by typing @kbd{C-x @key{RET} c raw-text @key{RET}}
immediately before loading it.
The mode line indicates whether multibyte character support is
enabled in the current buffer. If it is, there are two or more
characters (most often two dashes) near the beginning of the mode
line, before the indication of the visited file's end-of-line
convention (colon, backslash, etc.). When multibyte characters
are not enabled, nothing precedes the colon except a single dash.
@xref{Mode Line}, for more details about this.
@findex toggle-enable-multibyte-characters
You can turn on multibyte support in a specific buffer by invoking the
command @code{toggle-enable-multibyte-characters} in that buffer.
@node Language Environments
@section Language Environments
@cindex language environments
All supported character sets are supported in Emacs buffers whenever
multibyte characters are enabled; there is no need to select a
particular language in order to display its characters in an Emacs
buffer. However, it is important to select a @dfn{language
environment} in order to set various defaults. Roughly speaking, the
language environment represents a choice of preferred script rather
than a choice of language.
The language environment controls which coding systems to recognize
when reading text (@pxref{Recognize Coding}). This applies to files,
incoming mail, and any other text you read into Emacs. It may also
specify the default coding system to use when you create a file. Each
language environment also specifies a default input method.
@findex set-language-environment
@vindex current-language-environment
To select a language environment, customize the variable
@code{current-language-environment} or use the command @kbd{M-x
set-language-environment}. It makes no difference which buffer is
current when you use this command, because the effects apply globally
to the Emacs session. The supported language environments include:
@cindex Euro sign
@cindex UTF-8
@quotation
ASCII, Belarusian, Bengali, Brazilian Portuguese, Bulgarian,
Chinese-BIG5, Chinese-CNS, Chinese-EUC-TW, Chinese-GB, Chinese-GBK,
Chinese-GB18030, Croatian, Cyrillic-ALT, Cyrillic-ISO, Cyrillic-KOI8,
Czech, Devanagari, Dutch, English, Esperanto, Ethiopic, French,
Georgian, German, Greek, Gujarati, Hebrew, IPA, Italian, Japanese,
Kannada, Khmer, Korean, Lao, Latin-1, Latin-2, Latin-3, Latin-4,
Latin-5, Latin-6, Latin-7, Latin-8 (Celtic), Latin-9 (updated Latin-1
with the Euro sign), Latvian, Lithuanian, Malayalam, Oriya, Polish,
Punjabi, Romanian, Russian, Sinhala, Slovak, Slovenian, Spanish,
Swedish, TaiViet, Tajik, Tamil, Telugu, Thai, Tibetan, Turkish, UTF-8
(for a setup which prefers Unicode characters and files encoded in
UTF-8), Ukrainian, Vietnamese, Welsh, and Windows-1255 (for a setup
which prefers Cyrillic characters and files encoded in Windows-1255).
@end quotation
@cindex fonts for various scripts
@cindex Intlfonts package, installation
To display the script(s) used by your language environment on a
graphical display, you need to have a suitable font. If some of the
characters appear as empty boxes, you should install the GNU Intlfonts
package, which includes fonts for most supported scripts.@footnote{If
you run Emacs on X, you need to inform the X server about the location
of the newly installed fonts with the following commands:
@example
xset fp+ /usr/local/share/emacs/fonts
xset fp rehash
@end example
}
@xref{Fontsets}, for more details about setting up your fonts.
@findex set-locale-environment
@vindex locale-language-names
@vindex locale-charset-language-names
@cindex locales
Some operating systems let you specify the character-set locale you
are using by setting the locale environment variables @env{LC_ALL},
@env{LC_CTYPE}, or @env{LANG}.@footnote{If more than one of these is
set, the first one that is nonempty specifies your locale for this
purpose.} During startup, Emacs looks up your character-set locale's
name in the system locale alias table, matches its canonical name
against entries in the value of the variables
@code{locale-charset-language-names} and @code{locale-language-names},
and selects the corresponding language environment if a match is found.
(The former variable overrides the latter.) It also adjusts the display
table and terminal coding system, the locale coding system, the
preferred coding system as needed for the locale, and---last but not
least---the way Emacs decodes non-@acronym{ASCII} characters sent by your keyboard.
If you modify the @env{LC_ALL}, @env{LC_CTYPE}, or @env{LANG}
environment variables while running Emacs, you may want to invoke the
@code{set-locale-environment} function afterwards to readjust the
language environment from the new locale.
@vindex locale-preferred-coding-systems
The @code{set-locale-environment} function normally uses the preferred
coding system established by the language environment to decode system
messages. But if your locale matches an entry in the variable
@code{locale-preferred-coding-systems}, Emacs uses the corresponding
coding system instead. For example, if the locale @samp{ja_JP.PCK}
matches @code{japanese-shift-jis} in
@code{locale-preferred-coding-systems}, Emacs uses that encoding even
though it might normally use @code{japanese-iso-8bit}.
You can override the language environment chosen at startup with
explicit use of the command @code{set-language-environment}, or with
customization of @code{current-language-environment} in your init
file.
@kindex C-h L
@findex describe-language-environment
To display information about the effects of a certain language
environment @var{lang-env}, use the command @kbd{C-h L @var{lang-env}
@key{RET}} (@code{describe-language-environment}). This tells you
which languages this language environment is useful for, and lists the
character sets, coding systems, and input methods that go with it. It
also shows some sample text to illustrate scripts used in this
language environment. If you give an empty input for @var{lang-env},
this command describes the chosen language environment.
@anchor{Describe Language Environment}
@vindex set-language-environment-hook
You can customize any language environment with the normal hook
@code{set-language-environment-hook}. The command
@code{set-language-environment} runs that hook after setting up the new
language environment. The hook functions can test for a specific
language environment by checking the variable
@code{current-language-environment}. This hook is where you should
put non-default settings for specific language environment, such as
coding systems for keyboard input and terminal output, the default
input method, etc.
@vindex exit-language-environment-hook
Before it starts to set up the new language environment,
@code{set-language-environment} first runs the hook
@code{exit-language-environment-hook}. This hook is useful for undoing
customizations that were made with @code{set-language-environment-hook}.
For instance, if you set up a special key binding in a specific language
environment using @code{set-language-environment-hook}, you should set
up @code{exit-language-environment-hook} to restore the normal binding
for that key.
@node Input Methods
@section Input Methods
@cindex input methods
An @dfn{input method} is a kind of character conversion designed
specifically for interactive input. In Emacs, typically each language
has its own input method; sometimes several languages which use the same
characters can share one input method. A few languages support several
input methods.
The simplest kind of input method works by mapping @acronym{ASCII} letters
into another alphabet; this allows you to use one other alphabet
instead of @acronym{ASCII}. The Greek and Russian input methods
work this way.
A more powerful technique is composition: converting sequences of
characters into one letter. Many European input methods use composition
to produce a single non-@acronym{ASCII} letter from a sequence that consists of a
letter followed by accent characters (or vice versa). For example, some
methods convert the sequence @kbd{a'} into a single accented letter.
These input methods have no special commands of their own; all they do
is compose sequences of printing characters.
The input methods for syllabic scripts typically use mapping followed
by composition. The input methods for Thai and Korean work this way.
First, letters are mapped into symbols for particular sounds or tone
marks; then, sequences of these which make up a whole syllable are
mapped into one syllable sign.
Chinese and Japanese require more complex methods. In Chinese input
methods, first you enter the phonetic spelling of a Chinese word (in
input method @code{chinese-py}, among others), or a sequence of
portions of the character (input methods @code{chinese-4corner} and
@code{chinese-sw}, and others). One input sequence typically
corresponds to many possible Chinese characters. You select the one
you mean using keys such as @kbd{C-f}, @kbd{C-b}, @kbd{C-n},
@kbd{C-p}, and digits, which have special meanings in this situation.
The possible characters are conceptually arranged in several rows,
with each row holding up to 10 alternatives. Normally, Emacs displays
just one row at a time, in the echo area; @code{(@var{i}/@var{j})}
appears at the beginning, to indicate that this is the @var{i}th row
out of a total of @var{j} rows. Type @kbd{C-n} or @kbd{C-p} to
display the next row or the previous row.
Type @kbd{C-f} and @kbd{C-b} to move forward and backward among
the alternatives in the current row. As you do this, Emacs highlights
the current alternative with a special color; type @code{C-@key{SPC}}
to select the current alternative and use it as input. The
alternatives in the row are also numbered; the number appears before
the alternative. Typing a digit @var{n} selects the @var{n}th
alternative of the current row and uses it as input.
@key{TAB} in these Chinese input methods displays a buffer showing
all the possible characters at once; then clicking @kbd{Mouse-2} on
one of them selects that alternative. The keys @kbd{C-f}, @kbd{C-b},
@kbd{C-n}, @kbd{C-p}, and digits continue to work as usual, but they
do the highlighting in the buffer showing the possible characters,
rather than in the echo area.
In Japanese input methods, first you input a whole word using
phonetic spelling; then, after the word is in the buffer, Emacs
converts it into one or more characters using a large dictionary. One
phonetic spelling corresponds to a number of different Japanese words;
to select one of them, use @kbd{C-n} and @kbd{C-p} to cycle through
the alternatives.
Sometimes it is useful to cut off input method processing so that the
characters you have just entered will not combine with subsequent
characters. For example, in input method @code{latin-1-postfix}, the
sequence @kbd{e '} combines to form an @samp{e} with an accent. What if
you want to enter them as separate characters?
One way is to type the accent twice; this is a special feature for
entering the separate letter and accent. For example, @kbd{e ' '} gives
you the two characters @samp{e'}. Another way is to type another letter
after the @kbd{e}---something that won't combine with that---and
immediately delete it. For example, you could type @kbd{e e @key{DEL}
'} to get separate @samp{e} and @samp{'}.
Another method, more general but not quite as easy to type, is to use
@kbd{C-\ C-\} between two characters to stop them from combining. This
is the command @kbd{C-\} (@code{toggle-input-method}) used twice.
@ifnottex
@xref{Select Input Method}.
@end ifnottex
@cindex incremental search, input method interference
@kbd{C-\ C-\} is especially useful inside an incremental search,
because it stops waiting for more characters to combine, and starts
searching for what you have already entered.
To find out how to input the character after point using the current
input method, type @kbd{C-u C-x =}. @xref{Position Info}.
@vindex input-method-verbose-flag
@vindex input-method-highlight-flag
The variables @code{input-method-highlight-flag} and
@code{input-method-verbose-flag} control how input methods explain
what is happening. If @code{input-method-highlight-flag} is
non-@code{nil}, the partial sequence is highlighted in the buffer (for
most input methods---some disable this feature). If
@code{input-method-verbose-flag} is non-@code{nil}, the list of
possible characters to type next is displayed in the echo area (but
not when you are in the minibuffer).
@node Select Input Method
@section Selecting an Input Method
@table @kbd
@item C-\
Enable or disable use of the selected input method.
@item C-x @key{RET} C-\ @var{method} @key{RET}
Select a new input method for the current buffer.
@item C-h I @var{method} @key{RET}
@itemx C-h C-\ @var{method} @key{RET}
@findex describe-input-method
@kindex C-h I
@kindex C-h C-\
Describe the input method @var{method} (@code{describe-input-method}).
By default, it describes the current input method (if any). This
description should give you the full details of how to use any
particular input method.
@item M-x list-input-methods
Display a list of all the supported input methods.
@end table
@findex set-input-method
@vindex current-input-method
@kindex C-x RET C-\
To choose an input method for the current buffer, use @kbd{C-x
@key{RET} C-\} (@code{set-input-method}). This command reads the
input method name from the minibuffer; the name normally starts with the
language environment that it is meant to be used with. The variable
@code{current-input-method} records which input method is selected.
@findex toggle-input-method
@kindex C-\
Input methods use various sequences of @acronym{ASCII} characters to
stand for non-@acronym{ASCII} characters. Sometimes it is useful to
turn off the input method temporarily. To do this, type @kbd{C-\}
(@code{toggle-input-method}). To reenable the input method, type
@kbd{C-\} again.
If you type @kbd{C-\} and you have not yet selected an input method,
it prompts for you to specify one. This has the same effect as using
@kbd{C-x @key{RET} C-\} to specify an input method.
When invoked with a numeric argument, as in @kbd{C-u C-\},
@code{toggle-input-method} always prompts you for an input method,
suggesting the most recently selected one as the default.
@vindex default-input-method
Selecting a language environment specifies a default input method for
use in various buffers. When you have a default input method, you can
select it in the current buffer by typing @kbd{C-\}. The variable
@code{default-input-method} specifies the default input method
(@code{nil} means there is none).
In some language environments, which support several different input
methods, you might want to use an input method different from the
default chosen by @code{set-language-environment}. You can instruct
Emacs to select a different default input method for a certain
language environment, if you wish, by using
@code{set-language-environment-hook} (@pxref{Language Environments,
set-language-environment-hook}). For example:
@lisp
(defun my-chinese-setup ()
"Set up my private Chinese environment."
(if (equal current-language-environment "Chinese-GB")
(setq default-input-method "chinese-tonepy")))
(add-hook 'set-language-environment-hook 'my-chinese-setup)
@end lisp
@noindent
This sets the default input method to be @code{chinese-tonepy}
whenever you choose a Chinese-GB language environment.
You can instruct Emacs to activate a certain input method
automatically. For example:
@lisp
(add-hook 'text-mode-hook
(lambda () (set-input-method "german-prefix")))
@end lisp
@noindent
This activates the input method ``german-prefix'' automatically in the
Text mode.
@findex quail-set-keyboard-layout
Some input methods for alphabetic scripts work by (in effect)
remapping the keyboard to emulate various keyboard layouts commonly used
for those scripts. How to do this remapping properly depends on your
actual keyboard layout. To specify which layout your keyboard has, use
the command @kbd{M-x quail-set-keyboard-layout}.
@findex quail-show-key
You can use the command @kbd{M-x quail-show-key} to show what key (or
key sequence) to type in order to input the character following point,
using the selected keyboard layout. The command @kbd{C-u C-x =} also
shows that information in addition to the other information about the
character.
@findex list-input-methods
To see a list of all the supported input methods, type @kbd{M-x
list-input-methods}. The list gives information about each input
method, including the string that stands for it in the mode line.
@node Coding Systems
@section Coding Systems
@cindex coding systems
Users of various languages have established many more-or-less standard
coding systems for representing them. Emacs does not use these coding
systems internally; instead, it converts from various coding systems to
its own system when reading data, and converts the internal coding
system to other coding systems when writing data. Conversion is
possible in reading or writing files, in sending or receiving from the
terminal, and in exchanging data with subprocesses.
Emacs assigns a name to each coding system. Most coding systems are
used for one language, and the name of the coding system starts with
the language name. Some coding systems are used for several
languages; their names usually start with @samp{iso}. There are also
special coding systems, such as @code{no-conversion}, @code{raw-text},
and @code{emacs-internal}.
@cindex international files from DOS/Windows systems
A special class of coding systems, collectively known as
@dfn{codepages}, is designed to support text encoded by MS-Windows and
MS-DOS software. The names of these coding systems are
@code{cp@var{nnnn}}, where @var{nnnn} is a 3- or 4-digit number of the
codepage. You can use these encodings just like any other coding
system; for example, to visit a file encoded in codepage 850, type
@kbd{C-x @key{RET} c cp850 @key{RET} C-x C-f @var{filename}
@key{RET}}.
In addition to converting various representations of non-@acronym{ASCII}
characters, a coding system can perform end-of-line conversion. Emacs
handles three different conventions for how to separate lines in a file:
newline, carriage-return linefeed, and just carriage-return.
@table @kbd
@item C-h C @var{coding} @key{RET}
Describe coding system @var{coding}.
@item C-h C @key{RET}
Describe the coding systems currently in use.
@item M-x list-coding-systems
Display a list of all the supported coding systems.
@end table
@kindex C-h C
@findex describe-coding-system
The command @kbd{C-h C} (@code{describe-coding-system}) displays
information about particular coding systems, including the end-of-line
conversion specified by those coding systems. You can specify a coding
system name as the argument; alternatively, with an empty argument, it
describes the coding systems currently selected for various purposes,
both in the current buffer and as the defaults, and the priority list
for recognizing coding systems (@pxref{Recognize Coding}).
@findex list-coding-systems
To display a list of all the supported coding systems, type @kbd{M-x
list-coding-systems}. The list gives information about each coding
system, including the letter that stands for it in the mode line
(@pxref{Mode Line}).
@cindex end-of-line conversion
@cindex line endings
@cindex MS-DOS end-of-line conversion
@cindex Macintosh end-of-line conversion
Each of the coding systems that appear in this list---except for
@code{no-conversion}, which means no conversion of any kind---specifies
how and whether to convert printing characters, but leaves the choice of
end-of-line conversion to be decided based on the contents of each file.
For example, if the file appears to use the sequence carriage-return
linefeed to separate lines, DOS end-of-line conversion will be used.
Each of the listed coding systems has three variants which specify
exactly what to do for end-of-line conversion:
@table @code
@item @dots{}-unix
Don't do any end-of-line conversion; assume the file uses
newline to separate lines. (This is the convention normally used
on Unix and GNU systems.)
@item @dots{}-dos
Assume the file uses carriage-return linefeed to separate lines, and do
the appropriate conversion. (This is the convention normally used on
Microsoft systems.@footnote{It is also specified for MIME @samp{text/*}
bodies and in other network transport contexts. It is different
from the SGML reference syntax record-start/record-end format which
Emacs doesn't support directly.})
@item @dots{}-mac
Assume the file uses carriage-return to separate lines, and do the
appropriate conversion. (This is the convention normally used on the
Macintosh system.)
@end table
These variant coding systems are omitted from the
@code{list-coding-systems} display for brevity, since they are entirely
predictable. For example, the coding system @code{iso-latin-1} has
variants @code{iso-latin-1-unix}, @code{iso-latin-1-dos} and
@code{iso-latin-1-mac}.
@cindex @code{undecided}, coding system
The coding systems @code{unix}, @code{dos}, and @code{mac} are
aliases for @code{undecided-unix}, @code{undecided-dos}, and
@code{undecided-mac}, respectively. These coding systems specify only
the end-of-line conversion, and leave the character code conversion to
be deduced from the text itself.
The coding system @code{raw-text} is good for a file which is mainly
@acronym{ASCII} text, but may contain byte values above 127 which are
not meant to encode non-@acronym{ASCII} characters. With
@code{raw-text}, Emacs copies those byte values unchanged, and sets
@code{enable-multibyte-characters} to @code{nil} in the current buffer
so that they will be interpreted properly. @code{raw-text} handles
end-of-line conversion in the usual way, based on the data
encountered, and has the usual three variants to specify the kind of
end-of-line conversion to use.
In contrast, the coding system @code{no-conversion} specifies no
character code conversion at all---none for non-@acronym{ASCII} byte values and
none for end of line. This is useful for reading or writing binary
files, tar files, and other files that must be examined verbatim. It,
too, sets @code{enable-multibyte-characters} to @code{nil}.
The easiest way to edit a file with no conversion of any kind is with
the @kbd{M-x find-file-literally} command. This uses
@code{no-conversion}, and also suppresses other Emacs features that
might convert the file contents before you see them. @xref{Visiting}.
The coding system @code{emacs-internal} (or @code{utf-8-emacs},
which is equivalent) means that the file contains non-@acronym{ASCII}
characters stored with the internal Emacs encoding. This coding
system handles end-of-line conversion based on the data encountered,
and has the usual three variants to specify the kind of end-of-line
conversion.
@node Recognize Coding
@section Recognizing Coding Systems
Whenever Emacs reads a given piece of text, it tries to recognize
which coding system to use. This applies to files being read, output
from subprocesses, text from X selections, etc. Emacs can select the
right coding system automatically most of the time---once you have
specified your preferences.
Some coding systems can be recognized or distinguished by which byte
sequences appear in the data. However, there are coding systems that
cannot be distinguished, not even potentially. For example, there is no
way to distinguish between Latin-1 and Latin-2; they use the same byte
values with different meanings.
Emacs handles this situation by means of a priority list of coding
systems. Whenever Emacs reads a file, if you do not specify the coding
system to use, Emacs checks the data against each coding system,
starting with the first in priority and working down the list, until it
finds a coding system that fits the data. Then it converts the file
contents assuming that they are represented in this coding system.
The priority list of coding systems depends on the selected language
environment (@pxref{Language Environments}). For example, if you use
French, you probably want Emacs to prefer Latin-1 to Latin-2; if you use
Czech, you probably want Latin-2 to be preferred. This is one of the
reasons to specify a language environment.
@findex prefer-coding-system
However, you can alter the coding system priority list in detail
with the command @kbd{M-x prefer-coding-system}. This command reads
the name of a coding system from the minibuffer, and adds it to the
front of the priority list, so that it is preferred to all others. If
you use this command several times, each use adds one element to the
front of the priority list.
If you use a coding system that specifies the end-of-line conversion
type, such as @code{iso-8859-1-dos}, what this means is that Emacs
should attempt to recognize @code{iso-8859-1} with priority, and should
use DOS end-of-line conversion when it does recognize @code{iso-8859-1}.
@vindex file-coding-system-alist
Sometimes a file name indicates which coding system to use for the
file. The variable @code{file-coding-system-alist} specifies this
correspondence. There is a special function
@code{modify-coding-system-alist} for adding elements to this list. For
example, to read and write all @samp{.txt} files using the coding system
@code{chinese-iso-8bit}, you can execute this Lisp expression:
@smallexample
(modify-coding-system-alist 'file "\\.txt\\'" 'chinese-iso-8bit)
@end smallexample
@noindent
The first argument should be @code{file}, the second argument should be
a regular expression that determines which files this applies to, and
the third argument says which coding system to use for these files.
@vindex inhibit-eol-conversion
@cindex DOS-style end-of-line display
Emacs recognizes which kind of end-of-line conversion to use based on
the contents of the file: if it sees only carriage-returns, or only
carriage-return linefeed sequences, then it chooses the end-of-line
conversion accordingly. You can inhibit the automatic use of
end-of-line conversion by setting the variable @code{inhibit-eol-conversion}
to non-@code{nil}. If you do that, DOS-style files will be displayed
with the @samp{^M} characters visible in the buffer; some people
prefer this to the more subtle @samp{(DOS)} end-of-line type
indication near the left edge of the mode line (@pxref{Mode Line,
eol-mnemonic}).
@vindex inhibit-iso-escape-detection
@cindex escape sequences in files
By default, the automatic detection of coding system is sensitive to
escape sequences. If Emacs sees a sequence of characters that begin
with an escape character, and the sequence is valid as an ISO-2022
code, that tells Emacs to use one of the ISO-2022 encodings to decode
the file.
However, there may be cases that you want to read escape sequences
in a file as is. In such a case, you can set the variable
@code{inhibit-iso-escape-detection} to non-@code{nil}. Then the code
detection ignores any escape sequences, and never uses an ISO-2022
encoding. The result is that all escape sequences become visible in
the buffer.
The default value of @code{inhibit-iso-escape-detection} is
@code{nil}. We recommend that you not change it permanently, only for
one specific operation. That's because many Emacs Lisp source files
in the Emacs distribution contain non-@acronym{ASCII} characters encoded in the
coding system @code{iso-2022-7bit}, and they won't be
decoded correctly when you visit those files if you suppress the
escape sequence detection.
@vindex auto-coding-alist
@vindex auto-coding-regexp-alist
@vindex auto-coding-functions
The variables @code{auto-coding-alist},
@code{auto-coding-regexp-alist} and @code{auto-coding-functions} are
the strongest way to specify the coding system for certain patterns of
file names, or for files containing certain patterns; these variables
even override @samp{-*-coding:-*-} tags in the file itself. Emacs
uses @code{auto-coding-alist} for tar and archive files, to prevent it
from being confused by a @samp{-*-coding:-*-} tag in a member of the
archive and thinking it applies to the archive file as a whole.
Likewise, Emacs uses @code{auto-coding-regexp-alist} to ensure that
RMAIL files, whose names in general don't match any particular
pattern, are decoded correctly. One of the builtin
@code{auto-coding-functions} detects the encoding for XML files.
@vindex rmail-decode-mime-charset
@vindex rmail-file-coding-system
When you get new mail in Rmail, each message is translated
automatically from the coding system it is written in, as if it were a
separate file. This uses the priority list of coding systems that you
have specified. If a MIME message specifies a character set, Rmail
obeys that specification, unless @code{rmail-decode-mime-charset} is
@code{nil}. For reading and saving Rmail files themselves, Emacs uses
the coding system specified by the variable
@code{rmail-file-coding-system}. The default value is @code{nil},
which means that Rmail files are not translated (they are read and
written in the Emacs internal character code).
@node Specify Coding
@section Specifying a File's Coding System
If Emacs recognizes the encoding of a file incorrectly, you can
reread the file using the correct coding system by typing @kbd{C-x
@key{RET} r @var{coding-system} @key{RET}}. To see what coding system
Emacs actually used to decode the file, look at the coding system
mnemonic letter near the left edge of the mode line (@pxref{Mode
Line}), or type @kbd{C-h C @key{RET}}.
@vindex coding
You can specify the coding system for a particular file in the file
itself, using the @w{@samp{-*-@dots{}-*-}} construct at the beginning,
or a local variables list at the end (@pxref{File Variables}). You do
this by defining a value for the ``variable'' named @code{coding}.
Emacs does not really have a variable @code{coding}; instead of
setting a variable, this uses the specified coding system for the
file. For example, @samp{-*-mode: C; coding: latin-1;-*-} specifies
use of the Latin-1 coding system, as well as C mode. When you specify
the coding explicitly in the file, that overrides
@code{file-coding-system-alist}.
@node Output Coding
@section Choosing Coding Systems for Output
@vindex buffer-file-coding-system
Once Emacs has chosen a coding system for a buffer, it stores that
coding system in @code{buffer-file-coding-system}. That makes it the
default for operations that write from this buffer into a file, such
as @code{save-buffer} and @code{write-region}. You can specify a
different coding system for further file output from the buffer using
@code{set-buffer-file-coding-system} (@pxref{Text Coding}).
You can insert any character Emacs supports into any Emacs buffer,
but most coding systems can only handle a subset of these characters.
Therefore, it's possible that the characters you insert cannot be
encoded with the coding system that will be used to save the buffer.
For example, you could visit a text file in Polish, encoded in
@code{iso-8859-2}, and add some Russian words to it. When you save
that buffer, Emacs cannot use the current value of
@code{buffer-file-coding-system}, because the characters you added
cannot be encoded by that coding system.
When that happens, Emacs tries the most-preferred coding system (set
by @kbd{M-x prefer-coding-system} or @kbd{M-x
set-language-environment}). If that coding system can safely encode
all of the characters in the buffer, Emacs uses it, and stores its
value in @code{buffer-file-coding-system}. Otherwise, Emacs displays
a list of coding systems suitable for encoding the buffer's contents,
and asks you to choose one of those coding systems.
If you insert the unsuitable characters in a mail message, Emacs
behaves a bit differently. It additionally checks whether the
most-preferred coding system is recommended for use in MIME messages;
if not, Emacs tells you that the most-preferred coding system is not
recommended and prompts you for another coding system. This is so you
won't inadvertently send a message encoded in a way that your
recipient's mail software will have difficulty decoding. (You can
still use an unsuitable coding system if you type its name in response
to the question.)
@vindex sendmail-coding-system
When you send a message with Mail mode (@pxref{Sending Mail}), Emacs has
four different ways to determine the coding system to use for encoding
the message text. It tries the buffer's own value of
@code{buffer-file-coding-system}, if that is non-@code{nil}. Otherwise,
it uses the value of @code{sendmail-coding-system}, if that is
non-@code{nil}. The third way is to use the default coding system for
new files, which is controlled by your choice of language environment,
if that is non-@code{nil}. If all of these three values are @code{nil},
Emacs encodes outgoing mail using the Latin-1 coding system.
@node Text Coding
@section Specifying a Coding System for File Text
In cases where Emacs does not automatically choose the right coding
system for a file's contents, you can use these commands to specify
one:
@table @kbd
@item C-x @key{RET} f @var{coding} @key{RET}
Use coding system @var{coding} for saving or revisiting the visited
file in the current buffer.
@item C-x @key{RET} c @var{coding} @key{RET}
Specify coding system @var{coding} for the immediately following
command.
@item C-x @key{RET} r @var{coding} @key{RET}
Revisit the current file using the coding system @var{coding}.
@item M-x recode-region @key{RET} @var{right} @key{RET} @var{wrong} @key{RET}
Convert a region that was decoded using coding system @var{wrong},
decoding it using coding system @var{right} instead.
@end table
@kindex C-x RET f
@findex set-buffer-file-coding-system
The command @kbd{C-x @key{RET} f}