File: mule.texi

package info (click to toggle)
texi2html 1.82%2Bdfsg1-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 32,848 kB
  • sloc: perl: 15,888; xml: 6,075; sh: 3,977; makefile: 543
file content (692 lines) | stat: -rw-r--r-- 31,645 bytes parent folder | download | duplicates (17)
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
@c This is part of the Emacs manual.
@c Copyright (C) 1997 Free Software Foundation, Inc.
@c See file emacs.texi for copying conditions.
@node Mule, Major Modes, Windows, Top
@chapter World Scripts Support
@cindex MULE
@cindex international scripts
@cindex multibyte characters
@cindex encoding of characters

@cindex Chinese
@cindex Greek
@cindex IPA
@cindex Japanese
@cindex Korean
@cindex Cyrillic
@cindex Russian
  If you compile XEmacs with Mule option, it supports a wide variety of
world scripts, including Latin script, as well as Arabic script,
Simplified Chinese script (for mainland of China), Traditional Chinese
script (for Taiwan and Hong-Kong), Greek script, Hebrew script, IPA
symbols, Japanese scripts (Hiragana, Katakana and Kanji), Korean scripts
(Hangul and Hanja) and Cyrillic script (for Byelorussian, Bulgarian,
Russian, Serbian and Ukrainian).  These features have been merged from
the modified version of Emacs known as MULE (for ``MULti-lingual
Enhancement to GNU Emacs'').

@menu
* Mule Intro::              Basic concepts of Mule.
* 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.
* Mule and Fonts::          Additional font-related issues
* Coding Systems::          Character set conversion when you read and
                              write files, and so on.
* Recognize Coding::        How XEmacs figures out which conversion to use.
* Specify Coding::          Various ways to choose which conversion to use.
@end menu

@node Mule Intro, Language Environments, Mule, Mule
@section What is Mule?

Mule is the MUltiLingual Extension to XEmacs.  It provides facilities
not only for handling text written in many different languages, but in
fact multilingual texts containing several languages in the same buffer.
This goes beyond the simple facilities offered by Unicode for
representation of multilingual text.  Mule also supports input methods,
composing display using fonts in various different encodings, changing
character syntax and other editing facilities to correspond to local
language usage, and more.

The most obvious problem is that of the different character coding
systems used by different languages.  ASCII supplies all the characters
needed for most computer programming languages and US English (it lacks
the currency symbol for British English), but other Western European
languages (French, Spanish, German) require more than 96 code positions
for accented characters.  In fact, even with 8 bits to represent 96 more
character (including accented characters and symbols such as currency
symbols), some languages' alphabets remain incomplete (Croatian,
Polish).  (The 64 "missing characters" are reserved for control
characters.)  Furthermore, many European languages have their own
alphabets, which must conflict with the accented characters since the
ASCII characters are needed for computer interaction (error and log
messages are typically in ASCII).

For economy of space, historical practice has been for each language to
establish its own encoding for the characters it needs.  This allows
most European languages to represented with one octet (byte) per
character.  However, many Asian languages have thousands of characters
and require two or more octets per character.  For multilingual
purposes, the ISO 2022 standard establishes escape codes that allow
switching encodings in midstream.  (It's also ISO 2022 that establishes
the standard that code points 0-31 and 128-159 are control codes.)

However, this is error-prone and complex for internal processing.  For
this reason XEmacs uses an internal coding system which can encode all
of the world's scripts.  Unfortunately, for historical reasons, this
code is not Unicode, although we are moving in that direction.

XEmacs translates between the internal character encoding and various
other coding systems when reading and writing files, when exchanging
data with subprocesses, and (in some cases) in the @kbd{C-q} command
(see below).  The internal encoding is never visible to the user in a
production XEmacs, but unfortunately the process cannot be completely
transparent to the user.  This is because the same ranges of octets may
represent 1-octet ISO-8859-1 (which is satisfactory for most Western
European use prior to the introduction of the Euro currency), 1-octet
ISO-8859-15 (which substitutes the Euro for the rarely used "generic
currency" symbol), 1-octet ISO-8859-5 (Cyrillic), or multioctet EUC-JP
(Japanese).  There's no way to tell without being able to read!

A number of heuristics are incorporated in Mule for automatic
recognition, there are facilities for the user to set defaults, and
where necessary (rarely, we hope) to set coding systems directly.

@kindex C-h h
@findex view-hello-file
  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.

  Keyboards, even in the countries where these character sets are used,
generally don't have keys for all the characters in them.  So XEmacs
supports various @dfn{input methods}, typically one for each script or
language, to make it convenient to type them.

@kindex C-x RET
  The prefix key @kbd{C-x @key{RET}} is used for commands that pertain
to world scripts, coding systems, and input methods.


@node Language Environments, Input Methods, Mule Intro, Mule
@section Language Environments
@cindex language environments

  All supported character sets are supported in XEmacs buffers if it is
compiled with Mule; there is no need to select a particular language in
order to display its characters in an XEmacs buffer.  However, it is
important to select a @dfn{language environment} in order to set various
defaults.  The language environment really represents a choice of
preferred script (more or less) rather that 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, netnews, and any other text you read into XEmacs.  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
  The command to select a language environment is @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 XEmacs session.  The supported language environments include:

@quotation
ASCII, Chinese-BIG5, Chinese-GB, Croatian, Cyrillic-ALT, Cyrillic-ISO, 
Cyrillic-KOI8, Cyrillic-Win, Czech, English, Ethiopic, French, German,
Greek, Hebrew, IPA, Japanese, Korean, Latin-1, Latin-2, Latin-3, Latin-4,
Latin-5, Norwegian, Polish, Romanian, Slovenian, Thai-XTIS, Vietnamese.
@end quotation

  Some operating systems let you specify the language you are using by
setting locale environment variables.  XEmacs handles one common special
case of this: if your locale name for character types contains the
string @samp{8859-@var{n}}, XEmacs automatically selects the
corresponding language environment.

@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.  By default, this command describes the chosen language
environment.

@node Input Methods, Select Input Method, Language Environments, Mule
@section Input Methods

@cindex input methods
  An @dfn{input method} is a kind of character conversion designed
specifically for interactive input.  In XEmacs, 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 ASCII letters into
another alphabet.  This is how the Greek and Russian input methods work.

  A more powerful technique is composition: converting sequences of
characters into one letter.  Many European input methods use composition
to produce a single non-ASCII letter from a sequence that consists of a
letter followed by accent characters.  For example, some methods convert
the sequence @kbd{'a} into a single accented letter.

  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).  Since one phonetic spelling typically
corresponds to many different Chinese characters, you must select one of
the alternatives using special XEmacs commands.  Keys such as @kbd{C-f},
@kbd{C-b}, @kbd{C-n}, @kbd{C-p}, and digits have special definitions in
this situation, used for selecting among the alternatives.  @key{TAB}
displays a buffer showing all the possibilities.

   In Japanese input methods, first you input a whole word using
phonetic spelling; then, after the word is in the buffer, XEmacs
converts it into one or more characters using a large dictionary.  One
phonetic spelling corresponds to many differently written Japanese
words, so you must 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; that 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.
@ifinfo
@xref{Select Input Method}.
@end ifinfo

  @kbd{C-\ C-\} is especially useful inside an incremental search,
because stops waiting for more characters to combine, and starts
searching for what you have already entered.

@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.  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, Mule and Fonts, Input Methods, Mule
@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).

@item M-x list-input-methods
Display a list of all the supported input methods.
@end table

@findex select-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{select-input-method}).  This command reads the
input method name with 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 ASCII characters to stand for
non-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.

@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).

@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 list-input-methods
  To display 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 Mule and Fonts, Coding Systems, Select Input Method, Mule
@section Mule and Fonts
@cindex fonts
@cindex font registry
@cindex font encoding
@cindex CCL programs

(This section is X11-specific.)

Text in XEmacs buffers is displayed using various faces.  In addition to
specifying properties of a face, such as font and color, there are some
additional properties of Mule charsets that are used in text.

There is currently two properties of a charset that could be adjusted by
user: font registry and so called @dfn{ccl-program}.

Font registry is a regular expression matching the font registry field
for this character set.  For example, both the @code{ascii} and
@w{@code{latin-iso8859-1}} charsets use the registry @code{"ISO8859-1"}.
This field is used to choose an appropriate font when the user gives a
general font specification such as @w{@samp{-*-courier-medium-r-*-140-*}},
i.e. a 14-point upright medium-weight Courier font.

You can set font registry for a charset using
@samp{set-charset-registry} function in one of your startup files.  This
function takes two arguments: character set (as a symbol) and font
registry (as a string).

E.@w{ }g., for Cyrillic texts Mule uses @w{@code{cyrillic-iso8859-5}}
charset with @samp{"ISO8859-5"} as a default registry, and we want to
use @samp{"koi8-r"} instead, because fonts in that encoding are
installed on our system.  Use:

@example
(set-charset-registry 'cyrillic-iso8859-5 "koi8-r")
@end example

(Please note that you probably also want to set font registry for
@samp{ascii} charset so that mixed English/Cyrillic texts be displayed
using the same font.)

"CCL-programs" are a little special-purpose scripts defined within
XEmacs or in some package.  Those scripts allow XEmacs to use fonts that
are in different encoding from the encoding that is used by Mule for
text in buffer.  Returning to the above example, we need to somehow tell
XEmacs that we have different encodings of fonts and text and so it
needs to convert characters between those encodings when displaying.
That's what @samp{set-charset-ccl-program} function is used for.  There
are quite a few various CCL programs defined within XEmacs, and there is
no comprehensive list of them, so you currently have to consult sources.
@c FIXME: there must be a list of CCL programs

We know that there is a CCL program called @samp{ccl-encode-koi8-r-font}
that is used exactly for needed purpose: to convert characters between
@samp{ISO8859-5} encoding and @samp{koi8-r}.  Use:

@example
(set-charset-ccl-program 'cyrillic-iso8859-5 'ccl-encode-koi8-r-font)
@end example

There are several more uses for CCL programs, not related to fonts, but
those uses are not described here.


@node Coding Systems, Recognize Coding, Mule and Fonts, Mule
@section Coding Systems
@cindex coding systems

  Users of various languages have established many more-or-less standard
coding systems for representing them.  XEmacs 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.

  XEmacs 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 @code{binary} and @code{no-conversion} which do not
convert printing characters at all.

  In addition to converting various representations of non-ASCII
characters, a coding system can perform end-of-line conversion.  XEmacs
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.

@item C-u M-x list-coding-systems
Display comprehensive list of specific details of all supported coding
systems.
@end table

@kindex C-x @key{RET} C
@findex describe-coding-system
  The command @kbd{C-x RET C} (@code{describe-coding-system}) displays
information about particular coding systems.  You can specify a coding
system name as 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}).

  Each of the coding systems that appear in this list---except for
@code{binary}, 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 carriage-return linefeed between
lines, that 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.)

@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-8859-1} has
variants @code{iso-8859-1-unix}, @code{iso-8859-1-dos} and
@code{iso-8859-1-mac}.

  In contrast, the coding system @code{binary} specifies no character
code conversion at all---none for non-Latin-1 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.

  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{binary}, and
also suppresses other XEmacs features that might convert the file
contents before you see them.  @xref{Visiting}.

  The coding system @code{no-conversion} means that the file contains
non-Latin-1 characters stored with the internal XEmacs encoding.  It
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, Specify Coding, Coding Systems, Mule
@section Recognizing Coding Systems

@c #### This section is out of date.  The following set-*-coding-system
@c functions are known:

@c set-buffer-file-coding-system 
@c set-buffer-file-coding-system-for-read
@c set-buffer-process-coding-system
@c set-console-tty-coding-system 
@c set-console-tty-input-coding-system
@c set-console-tty-output-coding-system
@c set-default-buffer-file-coding-system
@c set-default-coding-systems    
@c set-default-file-coding-system
@c set-file-coding-system        
@c set-file-coding-system-for-read
@c set-keyboard-coding-system    
@c set-pathname-coding-system    
@c set-process-coding-system     
@c set-process-input-coding-system
@c set-process-output-coding-system
@c set-terminal-coding-system    

@c Some are marked as broken.  Agenda: (1) Update this section using
@c docstrings.  Note that they may be inaccurate.  (2) Correct the
@c documentation here, updating docstrings at the same time.

@c Document this.

@c set-language-environment-coding-systems

@c What are these?

@c dontusethis-set-value-file-name-coding-system-handler
@c dontusethis-set-value-keyboard-coding-system-handler
@c dontusethis-set-value-terminal-coding-system-handler

  Most of the time, XEmacs can recognize which coding system to use for
any given file--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.

  XEmacs handles this situation by means of a priority list of coding
systems.  Whenever XEmacs reads a file, if you do not specify the coding
system to use, XEmacs 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 XEmacs 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 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.

@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} using the coding system
@code{china-iso-8bit}, you can execute this Lisp expression:

@smallexample
(modify-coding-system-alist 'file "\\.txt\\'" 'china-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 coding
  You can specify the coding system for a particular file using the
@samp{-*-@dots{}-*-} construct at the beginning of a file, or a local
variables list at the end (@pxref{File Variables}).  You do this by
defining a value for the ``variable'' named @code{coding}.  XEmacs does
not really have a variable @code{coding}; instead of setting a variable,
it uses the specified coding system for the file.  For example,
@samp{-*-mode: C; coding: iso-8859-1;-*-} specifies use of the
iso-8859-1 coding system, as well as C mode.

@vindex buffer-file-coding-system
  Once XEmacs has chosen a coding system for a buffer, it stores that
coding system in @code{buffer-file-coding-system} and uses that coding
system, by default, for operations that write from this buffer into a
file.  This includes the commands @code{save-buffer} and
@code{write-region}.  If you want to write files from this buffer using
a different coding system, you can specify a different coding system for
the buffer using @code{set-buffer-file-coding-system} (@pxref{Specify
Coding}).


@node Specify Coding,  , Recognize Coding, Mule
@section Specifying a Coding System

  In cases where XEmacs does not automatically choose the right coding
system, 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 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} k @var{coding} @key{RET}
Use coding system @var{coding} for keyboard input.  (This feature is
non-functional and is temporarily disabled.)

@item C-x @key{RET} t @var{coding} @key{RET}
Use coding system @var{coding} for terminal output.

@item C-x @key{RET} p @var{coding} @key{RET}
Use coding system @var{coding} for subprocess input and output
in the current buffer.
@end table

@kindex C-x RET f
@findex set-buffer-file-coding-system
  The command @kbd{C-x RET f} (@code{set-buffer-file-coding-system})
specifies the file coding system for the current buffer---in other
words, which coding system to use when saving or rereading the visited
file.  You specify which coding system using the minibuffer.  Since this
command applies to a file you have already visited, it affects only the
way the file is saved.

@kindex C-x RET c
@findex universal-coding-system-argument
  Another way to specify the coding system for a file is when you visit
the file.  First use the command @kbd{C-x @key{RET} c}
(@code{universal-coding-system-argument}); this command uses the
minibuffer to read a coding system name.  After you exit the minibuffer,
the specified coding system is used for @emph{the immediately following
command}.

  So if the immediately following command is @kbd{C-x C-f}, for example,
it reads the file using that coding system (and records the coding
system for when the file is saved).  Or if the immediately following
command is @kbd{C-x C-w}, it writes the file using that coding system.
Other file commands affected by a specified coding system include
@kbd{C-x C-i} and @kbd{C-x C-v}, as well as the other-window variants of
@kbd{C-x C-f}.

  In addition, if you run some file input commands with the precedent
@kbd{C-u}, you can specify coding system to read from minibuffer.  So if
the immediately following command is @kbd{C-x C-f}, for example, it
reads the file using that coding system (and records the coding system
for when the file is saved).  Other file commands affected by a
specified coding system include @kbd{C-x C-i} and @kbd{C-x C-v}, as well
as the other-window variants of @kbd{C-x C-f}.

@vindex default-buffer-file-coding-system
  The variable @code{default-buffer-file-coding-system} specifies the
choice of coding system to use when you create a new file.  It applies
when you find a new file, and when you create a buffer and then save it
in a file.  Selecting a language environment typically sets this
variable to a good choice of default coding system for that language
environment.

@kindex C-x RET t
@findex set-terminal-coding-system
  The command @kbd{C-x @key{RET} t} (@code{set-terminal-coding-system})
specifies the coding system for terminal output.  If you specify a
character code for terminal output, all characters output to the
terminal are translated into that coding system.

  This feature is useful for certain character-only terminals built to
support specific languages or character sets---for example, European
terminals that support one of the ISO Latin character sets.

  By default, output to the terminal is not translated at all.

@kindex C-x RET k
@findex set-keyboard-coding-system
  The command @kbd{C-x @key{RET} k} (@code{set-keyboard-coding-system})
specifies the coding system for keyboard input.  Character-code
translation of keyboard input is useful for terminals with keys that
send non-ASCII graphic characters---for example, some terminals designed
for ISO Latin-1 or subsets of it.

  By default, keyboard input is not translated at all.

  There is a similarity between using a coding system translation for
keyboard input, and using an input method: both define sequences of
keyboard input that translate into single characters.  However, input
methods are designed to be convenient for interactive use by humans, and
the sequences that are translated are typically sequences of ASCII
printing characters.  Coding systems typically translate sequences of
non-graphic characters.

(This feature is non-functional and is temporarily disabled.)

@kindex C-x RET p
@findex set-buffer-process-coding-system
  The command @kbd{C-x @key{RET} p} (@code{set-buffer-process-coding-system})
specifies the coding system for input and output to a subprocess.  This
command applies to the current buffer; normally, each subprocess has its
own buffer, and thus you can use this command to specify translation to
and from a particular subprocess by giving the command in the
corresponding buffer.

  By default, process input and output are not translated at all.

@vindex file-name-coding-system
  The variable @code{file-name-coding-system} specifies a coding system
to use for encoding file names.  If you set the variable to a coding
system name (as a Lisp symbol or a string), XEmacs encodes file names
using that coding system for all file operations.  This makes it
possible to use non-Latin-1 characters in file names---or, at least,
those non-Latin-1 characters which the specified coding system can
encode.  By default, this variable is @code{nil}, which implies that you
cannot use non-Latin-1 characters in file names.