mule.texi 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  1. @c This is part of the Emacs manual.
  2. @c Copyright (C) 1997, 1999, 2000, 2001 Free Software Foundation, Inc.
  3. @c See file emacs.texi for copying conditions.
  4. @node International, Major Modes, Frames, Top
  5. @chapter International Character Set Support
  6. @cindex MULE
  7. @cindex international scripts
  8. @cindex multibyte characters
  9. @cindex encoding of characters
  10. @cindex Celtic
  11. @cindex Chinese
  12. @cindex Cyrillic
  13. @cindex Czech
  14. @cindex Devanagari
  15. @cindex Hindi
  16. @cindex Marathi
  17. @cindex Ethiopic
  18. @cindex German
  19. @cindex Greek
  20. @cindex Hebrew
  21. @cindex IPA
  22. @cindex Japanese
  23. @cindex Korean
  24. @cindex Lao
  25. @cindex Latin
  26. @cindex Polish
  27. @cindex Romanian
  28. @cindex Slovak
  29. @cindex Slovenian
  30. @cindex Thai
  31. @cindex Tibetan
  32. @cindex Turkish
  33. @cindex Vietnamese
  34. @cindex Dutch
  35. @cindex Spanish
  36. Emacs supports a wide variety of international character sets,
  37. including European variants of the Latin alphabet, as well as Chinese,
  38. Cyrillic, Devanagari (Hindi and Marathi), Ethiopic, Greek, Hebrew, IPA,
  39. Japanese, Korean, Lao, Thai, Tibetan, and Vietnamese scripts. These features
  40. have been merged from the modified version of Emacs known as MULE (for
  41. ``MULti-lingual Enhancement to GNU Emacs'')
  42. Emacs also supports various encodings of these characters used by
  43. other internationalized software, such as word processors and mailers.
  44. Emacs allows editing text with international characters by supporting
  45. all the related activities:
  46. @itemize @bullet
  47. @item
  48. You can visit files with non-ASCII characters, save non-ASCII text, and
  49. pass non-ASCII text between Emacs and programs it invokes (such as
  50. compilers, spell-checkers, and mailers). Setting your language
  51. environment (@pxref{Language Environments}) takes care of setting up the
  52. coding systems and other options for a specific language or culture.
  53. Alternatively, you can specify how Emacs should encode or decode text
  54. for each command; see @ref{Specify Coding}.
  55. @item
  56. You can display non-ASCII characters encoded by the various scripts.
  57. This works by using appropriate fonts on X and similar graphics
  58. displays (@pxref{Defining Fontsets}), and by sending special codes to
  59. text-only displays (@pxref{Specify Coding}). If some characters are
  60. displayed incorrectly, refer to @ref{Undisplayable Characters}, which
  61. describes possible problems and explains how to solve them.
  62. @item
  63. You can insert non-ASCII characters or search for them. To do that,
  64. you can specify an input method (@pxref{Select Input Method}) suitable
  65. for your language, or use the default input method set up when you set
  66. your language environment. (Emacs input methods are part of the Leim
  67. package, which must be installed for you to be able to use them.) If
  68. your keyboard can produce non-ASCII characters, you can select an
  69. appropriate keyboard coding system (@pxref{Specify Coding}), and Emacs
  70. will accept those characters. Latin-1 characters can also be input by
  71. using the @kbd{C-x 8} prefix, see @ref{Single-Byte Character Support,
  72. C-x 8}.
  73. @end itemize
  74. The rest of this chapter describes these issues in detail.
  75. @menu
  76. * International Chars:: Basic concepts of multibyte characters.
  77. * Enabling Multibyte:: Controlling whether to use multibyte characters.
  78. * Language Environments:: Setting things up for the language you use.
  79. * Input Methods:: Entering text characters not on your keyboard.
  80. * Select Input Method:: Specifying your choice of input methods.
  81. * Multibyte Conversion:: How single-byte characters convert to multibyte.
  82. * Coding Systems:: Character set conversion when you read and
  83. write files, and so on.
  84. * Recognize Coding:: How Emacs figures out which conversion to use.
  85. * Specify Coding:: Various ways to choose which conversion to use.
  86. * Fontsets:: Fontsets are collections of fonts
  87. that cover the whole spectrum of characters.
  88. * Defining Fontsets:: Defining a new fontset.
  89. * Undisplayable Characters:: When characters don't display.
  90. * Single-Byte Character Support::
  91. You can pick one European character set
  92. to use without multibyte characters.
  93. * Charsets:: How Emacs groups its internal character codes.
  94. @end menu
  95. @node International Chars
  96. @section Introduction to International Character Sets
  97. The users of international character sets and scripts have established
  98. many more-or-less standard coding systems for storing files. Emacs
  99. internally uses a single multibyte character encoding, so that it can
  100. intermix characters from all these scripts in a single buffer or string.
  101. This encoding represents each non-ASCII character as a sequence of bytes
  102. in the range 0200 through 0377. Emacs translates between the multibyte
  103. character encoding and various other coding systems when reading and
  104. writing files, when exchanging data with subprocesses, and (in some
  105. cases) in the @kbd{C-q} command (@pxref{Multibyte Conversion}).
  106. @kindex C-h h
  107. @findex view-hello-file
  108. @cindex undisplayable characters
  109. @cindex @samp{?} in display
  110. The command @kbd{C-h h} (@code{view-hello-file}) displays the file
  111. @file{etc/HELLO}, which shows how to say ``hello'' in many languages.
  112. This illustrates various scripts. If some characters can't be
  113. displayed on your terminal, they appear as @samp{?} or as hollow boxes
  114. (@pxref{Undisplayable Characters}).
  115. Keyboards, even in the countries where these character sets are used,
  116. generally don't have keys for all the characters in them. So Emacs
  117. supports various @dfn{input methods}, typically one for each script or
  118. language, to make it convenient to type them.
  119. @kindex C-x RET
  120. The prefix key @kbd{C-x @key{RET}} is used for commands that pertain
  121. to multibyte characters, coding systems, and input methods.
  122. @node Enabling Multibyte
  123. @section Enabling Multibyte Characters
  124. @cindex turn multibyte support on or off
  125. You can enable or disable multibyte character support, either for
  126. Emacs as a whole, or for a single buffer. When multibyte characters are
  127. disabled in a buffer, then each byte in that buffer represents a
  128. character, even codes 0200 through 0377. The old features for
  129. supporting the European character sets, ISO Latin-1 and ISO Latin-2,
  130. work as they did in Emacs 19 and also work for the other ISO 8859
  131. character sets.
  132. However, there is no need to turn off multibyte character support to
  133. use ISO Latin; the Emacs multibyte character set includes all the
  134. characters in these character sets, and Emacs can translate
  135. automatically to and from the ISO codes.
  136. By default, Emacs starts in multibyte mode, because that allows you to
  137. use all the supported languages and scripts without limitations.
  138. To edit a particular file in unibyte representation, visit it using
  139. @code{find-file-literally}. @xref{Visiting}. To convert a buffer in
  140. multibyte representation into a single-byte representation of the same
  141. characters, the easiest way is to save the contents in a file, kill the
  142. buffer, and find the file again with @code{find-file-literally}. You
  143. can also use @kbd{C-x @key{RET} c}
  144. (@code{universal-coding-system-argument}) and specify @samp{raw-text} as
  145. the coding system with which to find or save a file. @xref{Specify
  146. Coding}. Finding a file as @samp{raw-text} doesn't disable format
  147. conversion, uncompression and auto mode selection as
  148. @code{find-file-literally} does.
  149. @vindex enable-multibyte-characters
  150. @vindex default-enable-multibyte-characters
  151. To turn off multibyte character support by default, start Emacs with
  152. the @samp{--unibyte} option (@pxref{Initial Options}), or set the
  153. environment variable @env{EMACS_UNIBYTE}. You can also customize
  154. @code{enable-multibyte-characters} or, equivalently, directly set the
  155. variable @code{default-enable-multibyte-characters} to @code{nil} in
  156. your init file to have basically the same effect as @samp{--unibyte}.
  157. @findex toggle-enable-multibyte-characters
  158. To convert a unibyte session to a multibyte session, set
  159. @code{default-enable-multibyte-characters} to @code{t}. Buffers which
  160. were created in the unibyte session before you turn on multibyte support
  161. will stay unibyte. You can turn on multibyte support in a specific
  162. buffer by invoking the command @code{toggle-enable-multibyte-characters}
  163. in that buffer.
  164. @cindex Lisp files, and multibyte operation
  165. @cindex multibyte operation, and Lisp files
  166. @cindex unibyte operation, and Lisp files
  167. @cindex init file, and non-ASCII characters
  168. @cindex environment variables, and non-ASCII characters
  169. With @samp{--unibyte}, multibyte strings are not created during
  170. initialization from the values of environment variables,
  171. @file{/etc/passwd} entries etc.@: that contain non-ASCII 8-bit
  172. characters.
  173. Emacs normally loads Lisp files as multibyte, regardless of whether
  174. you used @samp{--unibyte}. This includes the Emacs initialization
  175. file, @file{.emacs}, and the initialization files of Emacs packages
  176. such as Gnus. However, you can specify unibyte loading for a
  177. particular Lisp file, by putting @w{@samp{-*-unibyte: t;-*-}} in a
  178. comment on the first line. Then that file is always loaded as unibyte
  179. text, even if you did not start Emacs with @samp{--unibyte}. The
  180. motivation for these conventions is that it is more reliable to always
  181. load any particular Lisp file in the same way. However, you can load
  182. a Lisp file as unibyte, on any one occasion, by typing @kbd{C-x
  183. @key{RET} c raw-text @key{RET}} immediately before loading it.
  184. The mode line indicates whether multibyte character support is enabled
  185. in the current buffer. If it is, there are two or more characters (most
  186. often two dashes) before the colon near the beginning of the mode line.
  187. When multibyte characters are not enabled, just one dash precedes the
  188. colon.
  189. @node Language Environments
  190. @section Language Environments
  191. @cindex language environments
  192. All supported character sets are supported in Emacs buffers whenever
  193. multibyte characters are enabled; there is no need to select a
  194. particular language in order to display its characters in an Emacs
  195. buffer. However, it is important to select a @dfn{language environment}
  196. in order to set various defaults. The language environment really
  197. represents a choice of preferred script (more or less) rather than a
  198. choice of language.
  199. The language environment controls which coding systems to recognize
  200. when reading text (@pxref{Recognize Coding}). This applies to files,
  201. incoming mail, netnews, and any other text you read into Emacs. It may
  202. also specify the default coding system to use when you create a file.
  203. Each language environment also specifies a default input method.
  204. @findex set-language-environment
  205. @vindex current-language-environment
  206. To select a language environment, customize the option
  207. @code{current-language-environment} or use the command @kbd{M-x
  208. set-language-environment}. It makes no difference which buffer is
  209. current when you use this command, because the effects apply globally to
  210. the Emacs session. The supported language environments include:
  211. @cindex Euro sign
  212. @cindex UTF-8
  213. @quotation
  214. Chinese-BIG5, Chinese-CNS, Chinese-GB, Cyrillic-ALT, Cyrillic-ISO,
  215. Cyrillic-KOI8, Czech, Devanagari, Dutch, English, Ethiopic, German,
  216. Greek, Hebrew, IPA, Japanese, Korean, Lao, Latin-1, Latin-2, Latin-3,
  217. Latin-4, Latin-5, Latin-8 (Celtic), Latin-9 (updated Latin-1, with the
  218. Euro sign), Polish, Romanian, Slovak, Slovenian, Spanish, Thai, Tibetan,
  219. Turkish, UTF-8 (for a setup which prefers Unicode characters and files
  220. encoded in UTF-8), and Vietnamese.
  221. @end quotation
  222. @cindex fonts for various scripts
  223. @cindex Intlfonts package, installation
  224. To display the script(s) used by your language environment on a
  225. graphical display, you need to have a suitable font. If some of the
  226. characters appear as empty boxes, you should install the GNU Intlfonts
  227. package, which includes fonts for all supported scripts.@footnote{If
  228. you run Emacs on X, you need to inform the X server about the location
  229. of the newly installed fonts with the following commands:
  230. @example
  231. xset fp+ /usr/local/share/emacs/fonts
  232. xset fp rehash
  233. @end example
  234. }
  235. @xref{Fontsets}, for more details about setting up your fonts.
  236. @findex set-locale-environment
  237. @vindex locale-language-names
  238. @vindex locale-charset-language-names
  239. @cindex locales
  240. Some operating systems let you specify the character-set locale you
  241. are using by setting the locale environment variables @env{LC_ALL},
  242. @env{LC_CTYPE}, or @env{LANG}.@footnote{If more than one of these is
  243. set, the first one that is nonempty specifies your locale for this
  244. purpose.} During startup, Emacs looks up your character-set locale's
  245. name in the system locale alias table, matches its canonical name
  246. against entries in the value of the variables
  247. @code{locale-charset-language-names} and @code{locale-language-names},
  248. and selects the corresponding language environment if a match is found.
  249. (The former variable overrides the latter.) It also adjusts the display
  250. table and terminal coding system, the locale coding system, and the
  251. preferred coding system as needed for the locale.
  252. If you modify the @env{LC_ALL}, @env{LC_CTYPE}, or @env{LANG}
  253. environment variables while running Emacs, you may want to invoke the
  254. @code{set-locale-environment} function afterwards to readjust the
  255. language environment from the new locale.
  256. @vindex locale-preferred-coding-systems
  257. The @code{set-locale-environment} function normally uses the preferred
  258. coding system established by the language environment to decode system
  259. messages. But if your locale matches an entry in the variable
  260. @code{locale-preferred-coding-systems}, Emacs uses the corresponding
  261. coding system instead. For example, if the locale @samp{ja_JP.PCK}
  262. matches @code{japanese-shift-jis} in
  263. @code{locale-preferred-coding-systems}, Emacs uses that encoding even
  264. though it might normally use @code{japanese-iso-8bit}.
  265. You can override the language environment chosen at startup with
  266. explicit use of the command @code{set-language-environment}, or with
  267. customization of @code{current-language-environment} in your init
  268. file.
  269. @kindex C-h L
  270. @findex describe-language-environment
  271. To display information about the effects of a certain language
  272. environment @var{lang-env}, use the command @kbd{C-h L @var{lang-env}
  273. @key{RET}} (@code{describe-language-environment}). This tells you which
  274. languages this language environment is useful for, and lists the
  275. character sets, coding systems, and input methods that go with it. It
  276. also shows some sample text to illustrate scripts used in this language
  277. environment. By default, this command describes the chosen language
  278. environment.
  279. @vindex set-language-environment-hook
  280. You can customize any language environment with the normal hook
  281. @code{set-language-environment-hook}. The command
  282. @code{set-language-environment} runs that hook after setting up the new
  283. language environment. The hook functions can test for a specific
  284. language environment by checking the variable
  285. @code{current-language-environment}. This hook is where you should
  286. put non-default settings for specific language environment, such as
  287. coding systems for keyboard input and terminal output, the default
  288. input method, etc.
  289. @vindex exit-language-environment-hook
  290. Before it starts to set up the new language environment,
  291. @code{set-language-environment} first runs the hook
  292. @code{exit-language-environment-hook}. This hook is useful for undoing
  293. customizations that were made with @code{set-language-environment-hook}.
  294. For instance, if you set up a special key binding in a specific language
  295. environment using @code{set-language-environment-hook}, you should set
  296. up @code{exit-language-environment-hook} to restore the normal binding
  297. for that key.
  298. @node Input Methods
  299. @section Input Methods
  300. @cindex input methods
  301. An @dfn{input method} is a kind of character conversion designed
  302. specifically for interactive input. In Emacs, typically each language
  303. has its own input method; sometimes several languages which use the same
  304. characters can share one input method. A few languages support several
  305. input methods.
  306. The simplest kind of input method works by mapping ASCII letters
  307. into another alphabet; this allows you to use one other alphabet
  308. instead of ASCII. The Greek and Russian input methods
  309. work this way.
  310. A more powerful technique is composition: converting sequences of
  311. characters into one letter. Many European input methods use composition
  312. to produce a single non-ASCII letter from a sequence that consists of a
  313. letter followed by accent characters (or vice versa). For example, some
  314. methods convert the sequence @kbd{a'} into a single accented letter.
  315. These input methods have no special commands of their own; all they do
  316. is compose sequences of printing characters.
  317. The input methods for syllabic scripts typically use mapping followed
  318. by composition. The input methods for Thai and Korean work this way.
  319. First, letters are mapped into symbols for particular sounds or tone
  320. marks; then, sequences of these which make up a whole syllable are
  321. mapped into one syllable sign.
  322. Chinese and Japanese require more complex methods. In Chinese input
  323. methods, first you enter the phonetic spelling of a Chinese word (in
  324. input method @code{chinese-py}, among others), or a sequence of
  325. portions of the character (input methods @code{chinese-4corner} and
  326. @code{chinese-sw}, and others). One input sequence typically
  327. corresponds to many possible Chinese characters. You select the one
  328. you mean using keys such as @kbd{C-f}, @kbd{C-b}, @kbd{C-n},
  329. @kbd{C-p}, and digits, which have special meanings in this situation.
  330. The possible characters are conceptually arranged in several rows,
  331. with each row holding up to 10 alternatives. Normally, Emacs displays
  332. just one row at a time, in the echo area; @code{(@var{i}/@var{j})}
  333. appears at the beginning, to indicate that this is the @var{i}th row
  334. out of a total of @var{j} rows. Type @kbd{C-n} or @kbd{C-p} to
  335. display the next row or the previous row.
  336. Type @kbd{C-f} and @kbd{C-b} to move forward and backward among
  337. the alternatives in the current row. As you do this, Emacs highlights
  338. the current alternative with a special color; type @code{C-@key{SPC}}
  339. to select the current alternative and use it as input. The
  340. alternatives in the row are also numbered; the number appears before
  341. the alternative. Typing a digit @var{n} selects the @var{n}th
  342. alternative of the current row and uses it as input.
  343. @key{TAB} in these Chinese input methods displays a buffer showing
  344. all the possible characters at once; then clicking @kbd{Mouse-2} on
  345. one of them selects that alternative. The keys @kbd{C-f}, @kbd{C-b},
  346. @kbd{C-n}, @kbd{C-p}, and digits continue to work as usual, but they
  347. do the highlighting in the buffer showing the possible characters,
  348. rather than in the echo area.
  349. In Japanese input methods, first you input a whole word using
  350. phonetic spelling; then, after the word is in the buffer, Emacs
  351. converts it into one or more characters using a large dictionary. One
  352. phonetic spelling corresponds to a number of different Japanese words;
  353. to select one of them, use @kbd{C-n} and @kbd{C-p} to cycle through
  354. the alternatives.
  355. Sometimes it is useful to cut off input method processing so that the
  356. characters you have just entered will not combine with subsequent
  357. characters. For example, in input method @code{latin-1-postfix}, the
  358. sequence @kbd{e '} combines to form an @samp{e} with an accent. What if
  359. you want to enter them as separate characters?
  360. One way is to type the accent twice; this is a special feature for
  361. entering the separate letter and accent. For example, @kbd{e ' '} gives
  362. you the two characters @samp{e'}. Another way is to type another letter
  363. after the @kbd{e}---something that won't combine with that---and
  364. immediately delete it. For example, you could type @kbd{e e @key{DEL}
  365. '} to get separate @samp{e} and @samp{'}.
  366. Another method, more general but not quite as easy to type, is to use
  367. @kbd{C-\ C-\} between two characters to stop them from combining. This
  368. is the command @kbd{C-\} (@code{toggle-input-method}) used twice.
  369. @ifinfo
  370. @xref{Select Input Method}.
  371. @end ifinfo
  372. @cindex incremental search, input method interference
  373. @kbd{C-\ C-\} is especially useful inside an incremental search,
  374. because it stops waiting for more characters to combine, and starts
  375. searching for what you have already entered.
  376. @vindex input-method-verbose-flag
  377. @vindex input-method-highlight-flag
  378. The variables @code{input-method-highlight-flag} and
  379. @code{input-method-verbose-flag} control how input methods explain
  380. what is happening. If @code{input-method-highlight-flag} is
  381. non-@code{nil}, the partial sequence is highlighted in the buffer (for
  382. most input methods---some disable this feature). If
  383. @code{input-method-verbose-flag} is non-@code{nil}, the list of
  384. possible characters to type next is displayed in the echo area (but
  385. not when you are in the minibuffer).
  386. @cindex Leim package
  387. Input methods are implemented in the separate Leim package: they are
  388. available only if the system administrator used Leim when building
  389. Emacs. If Emacs was built without Leim, you will find that no input
  390. methods are defined.
  391. @node Select Input Method
  392. @section Selecting an Input Method
  393. @table @kbd
  394. @item C-\
  395. Enable or disable use of the selected input method.
  396. @item C-x @key{RET} C-\ @var{method} @key{RET}
  397. Select a new input method for the current buffer.
  398. @item C-h I @var{method} @key{RET}
  399. @itemx C-h C-\ @var{method} @key{RET}
  400. @findex describe-input-method
  401. @kindex C-h I
  402. @kindex C-h C-\
  403. Describe the input method @var{method} (@code{describe-input-method}).
  404. By default, it describes the current input method (if any). This
  405. description should give you the full details of how to use any
  406. particular input method.
  407. @item M-x list-input-methods
  408. Display a list of all the supported input methods.
  409. @end table
  410. @findex set-input-method
  411. @vindex current-input-method
  412. @kindex C-x RET C-\
  413. To choose an input method for the current buffer, use @kbd{C-x
  414. @key{RET} C-\} (@code{set-input-method}). This command reads the
  415. input method name from the minibuffer; the name normally starts with the
  416. language environment that it is meant to be used with. The variable
  417. @code{current-input-method} records which input method is selected.
  418. @findex toggle-input-method
  419. @kindex C-\
  420. Input methods use various sequences of ASCII characters to stand for
  421. non-ASCII characters. Sometimes it is useful to turn off the input
  422. method temporarily. To do this, type @kbd{C-\}
  423. (@code{toggle-input-method}). To reenable the input method, type
  424. @kbd{C-\} again.
  425. If you type @kbd{C-\} and you have not yet selected an input method,
  426. it prompts for you to specify one. This has the same effect as using
  427. @kbd{C-x @key{RET} C-\} to specify an input method.
  428. When invoked with a numeric argument, as in @kbd{C-u C-\},
  429. @code{toggle-input-method} always prompts you for an input method,
  430. suggesting the most recently selected one as the default.
  431. @vindex default-input-method
  432. Selecting a language environment specifies a default input method for
  433. use in various buffers. When you have a default input method, you can
  434. select it in the current buffer by typing @kbd{C-\}. The variable
  435. @code{default-input-method} specifies the default input method
  436. (@code{nil} means there is none).
  437. In some language environments, which support several different input
  438. methods, you might want to use an input method different from the
  439. default chosen by @code{set-language-environment}. You can instruct
  440. Emacs to select a different default input method for a certain
  441. language environment, if you wish, by using
  442. @code{set-language-environment-hook} (@pxref{Language Environments,
  443. set-language-environment-hook}). For example:
  444. @lisp
  445. (defun my-chinese-setup ()
  446. "Set up my private Chinese environment."
  447. (if (equal current-language-environment "Chinese-GB")
  448. (setq default-input-method "chinese-tonepy")))
  449. (add-hook 'set-language-environment-hook 'my-chinese-setup)
  450. @end lisp
  451. @noindent
  452. This sets the default input method to be @code{chinese-tonepy}
  453. whenever you choose a Chinese-GB language environment.
  454. @findex quail-set-keyboard-layout
  455. Some input methods for alphabetic scripts work by (in effect)
  456. remapping the keyboard to emulate various keyboard layouts commonly used
  457. for those scripts. How to do this remapping properly depends on your
  458. actual keyboard layout. To specify which layout your keyboard has, use
  459. the command @kbd{M-x quail-set-keyboard-layout}.
  460. @findex list-input-methods
  461. To display a list of all the supported input methods, type @kbd{M-x
  462. list-input-methods}. The list gives information about each input
  463. method, including the string that stands for it in the mode line.
  464. @node Multibyte Conversion
  465. @section Unibyte and Multibyte Non-ASCII characters
  466. When multibyte characters are enabled, character codes 0240 (octal)
  467. through 0377 (octal) are not really legitimate in the buffer. The valid
  468. non-ASCII printing characters have codes that start from 0400.
  469. If you type a self-inserting character in the range 0240 through
  470. 0377, or if you use @kbd{C-q} to insert one, Emacs assumes you
  471. intended to use one of the ISO Latin-@var{n} character sets, and
  472. converts it to the Emacs code representing that Latin-@var{n}
  473. character. You select @emph{which} ISO Latin character set to use
  474. through your choice of language environment
  475. @iftex
  476. (see above).
  477. @end iftex
  478. @ifinfo
  479. (@pxref{Language Environments}).
  480. @end ifinfo
  481. If you do not specify a choice, the default is Latin-1.
  482. If you insert a character in the range 0200 through 0237, which
  483. forms the @code{eight-bit-control} character set, it is inserted
  484. literally. You should normally avoid doing this since buffers
  485. containing such characters have to be written out in either the
  486. @code{emacs-mule} or @code{raw-text} coding system, which is usually
  487. not what you want.
  488. @node Coding Systems
  489. @section Coding Systems
  490. @cindex coding systems
  491. Users of various languages have established many more-or-less standard
  492. coding systems for representing them. Emacs does not use these coding
  493. systems internally; instead, it converts from various coding systems to
  494. its own system when reading data, and converts the internal coding
  495. system to other coding systems when writing data. Conversion is
  496. possible in reading or writing files, in sending or receiving from the
  497. terminal, and in exchanging data with subprocesses.
  498. Emacs assigns a name to each coding system. Most coding systems are
  499. used for one language, and the name of the coding system starts with the
  500. language name. Some coding systems are used for several languages;
  501. their names usually start with @samp{iso}. There are also special
  502. coding systems @code{no-conversion}, @code{raw-text} and
  503. @code{emacs-mule} which do not convert printing characters at all.
  504. @cindex international files from DOS/Windows systems
  505. A special class of coding systems, collectively known as
  506. @dfn{codepages}, is designed to support text encoded by MS-Windows and
  507. MS-DOS software. To use any of these systems, you need to create it
  508. with @kbd{M-x codepage-setup}. @xref{MS-DOS and MULE}. After
  509. creating the coding system for the codepage, you can use it as any
  510. other coding system. For example, to visit a file encoded in codepage
  511. 850, type @kbd{C-x @key{RET} c cp850 @key{RET} C-x C-f @var{filename}
  512. @key{RET}}.
  513. In addition to converting various representations of non-ASCII
  514. characters, a coding system can perform end-of-line conversion. Emacs
  515. handles three different conventions for how to separate lines in a file:
  516. newline, carriage-return linefeed, and just carriage-return.
  517. @table @kbd
  518. @item C-h C @var{coding} @key{RET}
  519. Describe coding system @var{coding}.
  520. @item C-h C @key{RET}
  521. Describe the coding systems currently in use.
  522. @item M-x list-coding-systems
  523. Display a list of all the supported coding systems.
  524. @end table
  525. @kindex C-h C
  526. @findex describe-coding-system
  527. The command @kbd{C-h C} (@code{describe-coding-system}) displays
  528. information about particular coding systems. You can specify a coding
  529. system name as the argument; alternatively, with an empty argument, it
  530. describes the coding systems currently selected for various purposes,
  531. both in the current buffer and as the defaults, and the priority list
  532. for recognizing coding systems (@pxref{Recognize Coding}).
  533. @findex list-coding-systems
  534. To display a list of all the supported coding systems, type @kbd{M-x
  535. list-coding-systems}. The list gives information about each coding
  536. system, including the letter that stands for it in the mode line
  537. (@pxref{Mode Line}).
  538. @cindex end-of-line conversion
  539. @cindex MS-DOS end-of-line conversion
  540. @cindex Macintosh end-of-line conversion
  541. Each of the coding systems that appear in this list---except for
  542. @code{no-conversion}, which means no conversion of any kind---specifies
  543. how and whether to convert printing characters, but leaves the choice of
  544. end-of-line conversion to be decided based on the contents of each file.
  545. For example, if the file appears to use the sequence carriage-return
  546. linefeed to separate lines, DOS end-of-line conversion will be used.
  547. Each of the listed coding systems has three variants which specify
  548. exactly what to do for end-of-line conversion:
  549. @table @code
  550. @item @dots{}-unix
  551. Don't do any end-of-line conversion; assume the file uses
  552. newline to separate lines. (This is the convention normally used
  553. on Unix and GNU systems.)
  554. @item @dots{}-dos
  555. Assume the file uses carriage-return linefeed to separate lines, and do
  556. the appropriate conversion. (This is the convention normally used on
  557. Microsoft systems.@footnote{It is also specified for MIME @samp{text/*}
  558. bodies and in other network transport contexts. It is different
  559. from the SGML reference syntax record-start/record-end format which
  560. Emacs doesn't support directly.})
  561. @item @dots{}-mac
  562. Assume the file uses carriage-return to separate lines, and do the
  563. appropriate conversion. (This is the convention normally used on the
  564. Macintosh system.)
  565. @end table
  566. These variant coding systems are omitted from the
  567. @code{list-coding-systems} display for brevity, since they are entirely
  568. predictable. For example, the coding system @code{iso-latin-1} has
  569. variants @code{iso-latin-1-unix}, @code{iso-latin-1-dos} and
  570. @code{iso-latin-1-mac}.
  571. The coding system @code{raw-text} is good for a file which is mainly
  572. ASCII text, but may contain byte values above 127 which are not meant to
  573. encode non-ASCII characters. With @code{raw-text}, Emacs copies those
  574. byte values unchanged, and sets @code{enable-multibyte-characters} to
  575. @code{nil} in the current buffer so that they will be interpreted
  576. properly. @code{raw-text} handles end-of-line conversion in the usual
  577. way, based on the data encountered, and has the usual three variants to
  578. specify the kind of end-of-line conversion to use.
  579. In contrast, the coding system @code{no-conversion} specifies no
  580. character code conversion at all---none for non-ASCII byte values and
  581. none for end of line. This is useful for reading or writing binary
  582. files, tar files, and other files that must be examined verbatim. It,
  583. too, sets @code{enable-multibyte-characters} to @code{nil}.
  584. The easiest way to edit a file with no conversion of any kind is with
  585. the @kbd{M-x find-file-literally} command. This uses
  586. @code{no-conversion}, and also suppresses other Emacs features that
  587. might convert the file contents before you see them. @xref{Visiting}.
  588. The coding system @code{emacs-mule} means that the file contains
  589. non-ASCII characters stored with the internal Emacs encoding. It
  590. handles end-of-line conversion based on the data encountered, and has
  591. the usual three variants to specify the kind of end-of-line conversion.
  592. @node Recognize Coding
  593. @section Recognizing Coding Systems
  594. Emacs tries to recognize which coding system to use for a given text
  595. as an integral part of reading that text. (This applies to files
  596. being read, output from subprocesses, text from X selections, etc.)
  597. Emacs can select the right coding system automatically most of the
  598. time---once you have specified your preferences.
  599. Some coding systems can be recognized or distinguished by which byte
  600. sequences appear in the data. However, there are coding systems that
  601. cannot be distinguished, not even potentially. For example, there is no
  602. way to distinguish between Latin-1 and Latin-2; they use the same byte
  603. values with different meanings.
  604. Emacs handles this situation by means of a priority list of coding
  605. systems. Whenever Emacs reads a file, if you do not specify the coding
  606. system to use, Emacs checks the data against each coding system,
  607. starting with the first in priority and working down the list, until it
  608. finds a coding system that fits the data. Then it converts the file
  609. contents assuming that they are represented in this coding system.
  610. The priority list of coding systems depends on the selected language
  611. environment (@pxref{Language Environments}). For example, if you use
  612. French, you probably want Emacs to prefer Latin-1 to Latin-2; if you use
  613. Czech, you probably want Latin-2 to be preferred. This is one of the
  614. reasons to specify a language environment.
  615. @findex prefer-coding-system
  616. However, you can alter the priority list in detail with the command
  617. @kbd{M-x prefer-coding-system}. This command reads the name of a coding
  618. system from the minibuffer, and adds it to the front of the priority
  619. list, so that it is preferred to all others. If you use this command
  620. several times, each use adds one element to the front of the priority
  621. list.
  622. If you use a coding system that specifies the end-of-line conversion
  623. type, such as @code{iso-8859-1-dos}, what this means is that Emacs
  624. should attempt to recognize @code{iso-8859-1} with priority, and should
  625. use DOS end-of-line conversion when it does recognize @code{iso-8859-1}.
  626. @vindex file-coding-system-alist
  627. Sometimes a file name indicates which coding system to use for the
  628. file. The variable @code{file-coding-system-alist} specifies this
  629. correspondence. There is a special function
  630. @code{modify-coding-system-alist} for adding elements to this list. For
  631. example, to read and write all @samp{.txt} files using the coding system
  632. @code{china-iso-8bit}, you can execute this Lisp expression:
  633. @smallexample
  634. (modify-coding-system-alist 'file "\\.txt\\'" 'china-iso-8bit)
  635. @end smallexample
  636. @noindent
  637. The first argument should be @code{file}, the second argument should be
  638. a regular expression that determines which files this applies to, and
  639. the third argument says which coding system to use for these files.
  640. @vindex inhibit-eol-conversion
  641. @cindex DOS-style end-of-line display
  642. Emacs recognizes which kind of end-of-line conversion to use based on
  643. the contents of the file: if it sees only carriage-returns, or only
  644. carriage-return linefeed sequences, then it chooses the end-of-line
  645. conversion accordingly. You can inhibit the automatic use of
  646. end-of-line conversion by setting the variable @code{inhibit-eol-conversion}
  647. to non-@code{nil}. If you do that, DOS-style files will be displayed
  648. with the @samp{^M} characters visible in the buffer; some people
  649. prefer this to the more subtle @samp{(DOS)} end-of-line type
  650. indication near the left edge of the mode line (@pxref{Mode Line,
  651. eol-mnemonic}).
  652. @vindex inhibit-iso-escape-detection
  653. @cindex escape sequences in files
  654. By default, the automatic detection of coding system is sensitive to
  655. escape sequences. If Emacs sees a sequence of characters that begin
  656. with an escape character, and the sequence is valid as an ISO-2022
  657. code, that tells Emacs to use one of the ISO-2022 encodings to decode
  658. the file.
  659. However, there may be cases that you want to read escape sequences
  660. in a file as is. In such a case, you can set the variable
  661. @code{inhibit-iso-escape-detection} to non-@code{nil}. Then the code
  662. detection ignores any escape sequences, and never uses an ISO-2022
  663. encoding. The result is that all escape sequences become visible in
  664. the buffer.
  665. The default value of @code{inhibit-iso-escape-detection} is
  666. @code{nil}. We recommend that you not change it permanently, only for
  667. one specific operation. That's because many Emacs Lisp source files
  668. in the Emacs distribution contain non-ASCII characters encoded in the
  669. coding system @code{iso-2022-7bit}, and they won't be
  670. decoded correctly when you visit those files if you suppress the
  671. escape sequence detection.
  672. @vindex coding
  673. You can specify the coding system for a particular file using the
  674. @w{@samp{-*-@dots{}-*-}} construct at the beginning of a file, or a
  675. local variables list at the end (@pxref{File Variables}). You do this
  676. by defining a value for the ``variable'' named @code{coding}. Emacs
  677. does not really have a variable @code{coding}; instead of setting a
  678. variable, this uses the specified coding system for the file. For
  679. example, @samp{-*-mode: C; coding: latin-1;-*-} specifies use of the
  680. Latin-1 coding system, as well as C mode. When you specify the coding
  681. explicitly in the file, that overrides
  682. @code{file-coding-system-alist}.
  683. @vindex auto-coding-alist
  684. @vindex auto-coding-regexp-alist
  685. The variables @code{auto-coding-alist} and
  686. @code{auto-coding-regexp-alist} are the strongest way to specify the
  687. coding system for certain patterns of file names, or for files
  688. containing certain patterns; these variables even override
  689. @samp{-*-coding:-*-} tags in the file itself. Emacs uses
  690. @code{auto-coding-alist} for tar and archive files, to prevent it
  691. from being confused by a @samp{-*-coding:-*-} tag in a member of the
  692. archive and thinking it applies to the archive file as a whole.
  693. Likewise, Emacs uses @code{auto-coding-regexp-alist} to ensure that
  694. RMAIL files, whose names in general don't match any particular pattern,
  695. are decoded correctly.
  696. If Emacs recognizes the encoding of a file incorrectly, you can
  697. reread the file using the correct coding system by typing @kbd{C-x
  698. @key{RET} c @var{coding-system} @key{RET} M-x revert-buffer
  699. @key{RET}}. To see what coding system Emacs actually used to decode
  700. the file, look at the coding system mnemonic letter near the left edge
  701. of the mode line (@pxref{Mode Line}), or type @kbd{C-h C @key{RET}}.
  702. @vindex buffer-file-coding-system
  703. Once Emacs has chosen a coding system for a buffer, it stores that
  704. coding system in @code{buffer-file-coding-system} and uses that coding
  705. system, by default, for operations that write from this buffer into a
  706. file. This includes the commands @code{save-buffer} and
  707. @code{write-region}. If you want to write files from this buffer using
  708. a different coding system, you can specify a different coding system for
  709. the buffer using @code{set-buffer-file-coding-system} (@pxref{Specify
  710. Coding}).
  711. You can insert any possible character into any Emacs buffer, but
  712. most coding systems can only handle some of the possible characters.
  713. This means that it is possible for you to insert characters that
  714. cannot be encoded with the coding system that will be used to save the
  715. buffer. For example, you could start with an ASCII file and insert a
  716. few Latin-1 characters into it, or you could edit a text file in
  717. Polish encoded in @code{iso-8859-2} and add some Russian words to it.
  718. When you save the buffer, Emacs cannot use the current value of
  719. @code{buffer-file-coding-system}, because the characters you added
  720. cannot be encoded by that coding system.
  721. When that happens, Emacs tries the most-preferred coding system (set
  722. by @kbd{M-x prefer-coding-system} or @kbd{M-x
  723. set-language-environment}), and if that coding system can safely
  724. encode all of the characters in the buffer, Emacs uses it, and stores
  725. its value in @code{buffer-file-coding-system}. Otherwise, Emacs
  726. displays a list of coding systems suitable for encoding the buffer's
  727. contents, and asks you to choose one of those coding systems.
  728. If you insert the unsuitable characters in a mail message, Emacs
  729. behaves a bit differently. It additionally checks whether the
  730. most-preferred coding system is recommended for use in MIME messages;
  731. if not, Emacs tells you that the most-preferred coding system is
  732. not recommended and prompts you for another coding system. This is so
  733. you won't inadvertently send a message encoded in a way that your
  734. recipient's mail software will have difficulty decoding. (If you do
  735. want to use the most-preferred coding system, you can still type its
  736. name in response to the question.)
  737. @vindex sendmail-coding-system
  738. When you send a message with Mail mode (@pxref{Sending Mail}), Emacs has
  739. four different ways to determine the coding system to use for encoding
  740. the message text. It tries the buffer's own value of
  741. @code{buffer-file-coding-system}, if that is non-@code{nil}. Otherwise,
  742. it uses the value of @code{sendmail-coding-system}, if that is
  743. non-@code{nil}. The third way is to use the default coding system for
  744. new files, which is controlled by your choice of language environment,
  745. if that is non-@code{nil}. If all of these three values are @code{nil},
  746. Emacs encodes outgoing mail using the Latin-1 coding system.
  747. @vindex rmail-decode-mime-charset
  748. When you get new mail in Rmail, each message is translated
  749. automatically from the coding system it is written in, as if it were a
  750. separate file. This uses the priority list of coding systems that you
  751. have specified. If a MIME message specifies a character set, Rmail
  752. obeys that specification, unless @code{rmail-decode-mime-charset} is
  753. @code{nil}.
  754. @vindex rmail-file-coding-system
  755. For reading and saving Rmail files themselves, Emacs uses the coding
  756. system specified by the variable @code{rmail-file-coding-system}. The
  757. default value is @code{nil}, which means that Rmail files are not
  758. translated (they are read and written in the Emacs internal character
  759. code).
  760. @node Specify Coding
  761. @section Specifying a Coding System
  762. In cases where Emacs does not automatically choose the right coding
  763. system, you can use these commands to specify one:
  764. @table @kbd
  765. @item C-x @key{RET} f @var{coding} @key{RET}
  766. Use coding system @var{coding} for the visited file
  767. in the current buffer.
  768. @item C-x @key{RET} c @var{coding} @key{RET}
  769. Specify coding system @var{coding} for the immediately following
  770. command.
  771. @item C-x @key{RET} k @var{coding} @key{RET}
  772. Use coding system @var{coding} for keyboard input.
  773. @item C-x @key{RET} t @var{coding} @key{RET}
  774. Use coding system @var{coding} for terminal output.
  775. @item C-x @key{RET} p @var{input-coding} @key{RET} @var{output-coding} @key{RET}
  776. Use coding systems @var{input-coding} and @var{output-coding} for
  777. subprocess input and output in the current buffer.
  778. @item C-x @key{RET} x @var{coding} @key{RET}
  779. Use coding system @var{coding} for transferring selections to and from
  780. other programs through the window system.
  781. @item C-x @key{RET} X @var{coding} @key{RET}
  782. Use coding system @var{coding} for transferring @emph{one}
  783. selection---the next one---to or from the window system.
  784. @end table
  785. @kindex C-x RET f
  786. @findex set-buffer-file-coding-system
  787. The command @kbd{C-x @key{RET} f} (@code{set-buffer-file-coding-system})
  788. specifies the file coding system for the current buffer---in other
  789. words, which coding system to use when saving or rereading the visited
  790. file. You specify which coding system using the minibuffer. Since this
  791. command applies to a file you have already visited, it affects only the
  792. way the file is saved.
  793. @kindex C-x RET c
  794. @findex universal-coding-system-argument
  795. Another way to specify the coding system for a file is when you visit
  796. the file. First use the command @kbd{C-x @key{RET} c}
  797. (@code{universal-coding-system-argument}); this command uses the
  798. minibuffer to read a coding system name. After you exit the minibuffer,
  799. the specified coding system is used for @emph{the immediately following
  800. command}.
  801. So if the immediately following command is @kbd{C-x C-f}, for example,
  802. it reads the file using that coding system (and records the coding
  803. system for when the file is saved). Or if the immediately following
  804. command is @kbd{C-x C-w}, it writes the file using that coding system.
  805. Other file commands affected by a specified coding system include
  806. @kbd{C-x C-i} and @kbd{C-x C-v}, as well as the other-window variants of
  807. @kbd{C-x C-f}.
  808. @kbd{C-x @key{RET} c} also affects commands that start subprocesses,
  809. including @kbd{M-x shell} (@pxref{Shell}).
  810. However, if the immediately following command does not use the coding
  811. system, then @kbd{C-x @key{RET} c} ultimately has no effect.
  812. An easy way to visit a file with no conversion is with the @kbd{M-x
  813. find-file-literally} command. @xref{Visiting}.
  814. @vindex default-buffer-file-coding-system
  815. The variable @code{default-buffer-file-coding-system} specifies the
  816. choice of coding system to use when you create a new file. It applies
  817. when you find a new file, and when you create a buffer and then save it
  818. in a file. Selecting a language environment typically sets this
  819. variable to a good choice of default coding system for that language
  820. environment.
  821. @kindex C-x RET t
  822. @findex set-terminal-coding-system
  823. The command @kbd{C-x @key{RET} t} (@code{set-terminal-coding-system})
  824. specifies the coding system for terminal output. If you specify a
  825. character code for terminal output, all characters output to the
  826. terminal are translated into that coding system.
  827. This feature is useful for certain character-only terminals built to
  828. support specific languages or character sets---for example, European
  829. terminals that support one of the ISO Latin character sets. You need to
  830. specify the terminal coding system when using multibyte text, so that
  831. Emacs knows which characters the terminal can actually handle.
  832. By default, output to the terminal is not translated at all, unless
  833. Emacs can deduce the proper coding system from your terminal type or
  834. your locale specification (@pxref{Language Environments}).
  835. @kindex C-x RET k
  836. @findex set-keyboard-coding-system
  837. @vindex keyboard-coding-system
  838. The command @kbd{C-x @key{RET} k} (@code{set-keyboard-coding-system})
  839. or the Custom option @code{keyboard-coding-system}
  840. specifies the coding system for keyboard input. Character-code
  841. translation of keyboard input is useful for terminals with keys that
  842. send non-ASCII graphic characters---for example, some terminals designed
  843. for ISO Latin-1 or subsets of it.
  844. By default, keyboard input is not translated at all.
  845. There is a similarity between using a coding system translation for
  846. keyboard input, and using an input method: both define sequences of
  847. keyboard input that translate into single characters. However, input
  848. methods are designed to be convenient for interactive use by humans, and
  849. the sequences that are translated are typically sequences of ASCII
  850. printing characters. Coding systems typically translate sequences of
  851. non-graphic characters.
  852. @kindex C-x RET x
  853. @kindex C-x RET X
  854. @findex set-selection-coding-system
  855. @findex set-next-selection-coding-system
  856. The command @kbd{C-x @key{RET} x} (@code{set-selection-coding-system})
  857. specifies the coding system for sending selected text to the window
  858. system, and for receiving the text of selections made in other
  859. applications. This command applies to all subsequent selections, until
  860. you override it by using the command again. The command @kbd{C-x
  861. @key{RET} X} (@code{set-next-selection-coding-system}) specifies the
  862. coding system for the next selection made in Emacs or read by Emacs.
  863. @kindex C-x RET p
  864. @findex set-buffer-process-coding-system
  865. The command @kbd{C-x @key{RET} p} (@code{set-buffer-process-coding-system})
  866. specifies the coding system for input and output to a subprocess. This
  867. command applies to the current buffer; normally, each subprocess has its
  868. own buffer, and thus you can use this command to specify translation to
  869. and from a particular subprocess by giving the command in the
  870. corresponding buffer.
  871. The default for translation of process input and output depends on the
  872. current language environment.
  873. @vindex file-name-coding-system
  874. @cindex file names with non-ASCII characters
  875. The variable @code{file-name-coding-system} specifies a coding system
  876. to use for encoding file names. If you set the variable to a coding
  877. system name (as a Lisp symbol or a string), Emacs encodes file names
  878. using that coding system for all file operations. This makes it
  879. possible to use non-ASCII characters in file names---or, at least, those
  880. non-ASCII characters which the specified coding system can encode.
  881. If @code{file-name-coding-system} is @code{nil}, Emacs uses a default
  882. coding system determined by the selected language environment. In the
  883. default language environment, any non-ASCII characters in file names are
  884. not encoded specially; they appear in the file system using the internal
  885. Emacs representation.
  886. @strong{Warning:} if you change @code{file-name-coding-system} (or the
  887. language environment) in the middle of an Emacs session, problems can
  888. result if you have already visited files whose names were encoded using
  889. the earlier coding system and cannot be encoded (or are encoded
  890. differently) under the new coding system. If you try to save one of
  891. these buffers under the visited file name, saving may use the wrong file
  892. name, or it may get an error. If such a problem happens, use @kbd{C-x
  893. C-w} to specify a new file name for that buffer.
  894. @vindex locale-coding-system
  895. The variable @code{locale-coding-system} specifies a coding system
  896. to use when encoding and decoding system strings such as system error
  897. messages and @code{format-time-string} formats and time stamps. You
  898. should choose a coding system that is compatible with the underlying
  899. system's text representation, which is normally specified by one of
  900. the environment variables @env{LC_ALL}, @env{LC_CTYPE}, and
  901. @env{LANG}. (The first one, in the order specified above, whose value
  902. is nonempty is the one that determines the text representation.)
  903. @node Fontsets
  904. @section Fontsets
  905. @cindex fontsets
  906. A font for X typically defines shapes for a single alphabet or script.
  907. Therefore, displaying the entire range of scripts that Emacs supports
  908. requires a collection of many fonts. In Emacs, such a collection is
  909. called a @dfn{fontset}. A fontset is defined by a list of fonts, each
  910. assigned to handle a range of character codes.
  911. Each fontset has a name, like a font. The available X fonts are
  912. defined by the X server; fontsets, however, are defined within Emacs
  913. itself. Once you have defined a fontset, you can use it within Emacs by
  914. specifying its name, anywhere that you could use a single font. Of
  915. course, Emacs fontsets can use only the fonts that the X server
  916. supports; if certain characters appear on the screen as hollow boxes,
  917. this means that the fontset in use for them has no font for those
  918. characters.@footnote{The Emacs installation instructions have information on
  919. additional font support.}
  920. Emacs creates two fontsets automatically: the @dfn{standard fontset}
  921. and the @dfn{startup fontset}. The standard fontset is most likely to
  922. have fonts for a wide variety of non-ASCII characters; however, this is
  923. not the default for Emacs to use. (By default, Emacs tries to find a
  924. font that has bold and italic variants.) You can specify use of the
  925. standard fontset with the @samp{-fn} option, or with the @samp{Font} X
  926. resource (@pxref{Font X}). For example,
  927. @example
  928. emacs -fn fontset-standard
  929. @end example
  930. A fontset does not necessarily specify a font for every character
  931. code. If a fontset specifies no font for a certain character, or if it
  932. specifies a font that does not exist on your system, then it cannot
  933. display that character properly. It will display that character as an
  934. empty box instead.
  935. @node Defining Fontsets
  936. @section Defining fontsets
  937. @vindex standard-fontset-spec
  938. @cindex standard fontset
  939. Emacs creates a standard fontset automatically according to the value
  940. of @code{standard-fontset-spec}. This fontset's name is
  941. @example
  942. -*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard
  943. @end example
  944. @noindent
  945. or just @samp{fontset-standard} for short.
  946. Bold, italic, and bold-italic variants of the standard fontset are
  947. created automatically. Their names have @samp{bold} instead of
  948. @samp{medium}, or @samp{i} instead of @samp{r}, or both.
  949. @cindex startup fontset
  950. If you specify a default ASCII font with the @samp{Font} resource or
  951. the @samp{-fn} argument, Emacs generates a fontset from it
  952. automatically. This is the @dfn{startup fontset} and its name is
  953. @code{fontset-startup}. It does this by replacing the @var{foundry},
  954. @var{family}, @var{add_style}, and @var{average_width} fields of the
  955. font name with @samp{*}, replacing @var{charset_registry} field with
  956. @samp{fontset}, and replacing @var{charset_encoding} field with
  957. @samp{startup}, then using the resulting string to specify a fontset.
  958. For instance, if you start Emacs this way,
  959. @example
  960. emacs -fn "*courier-medium-r-normal--14-140-*-iso8859-1"
  961. @end example
  962. @noindent
  963. Emacs generates the following fontset and uses it for the initial X
  964. window frame:
  965. @example
  966. -*-*-medium-r-normal-*-14-140-*-*-*-*-fontset-startup
  967. @end example
  968. With the X resource @samp{Emacs.Font}, you can specify a fontset name
  969. just like an actual font name. But be careful not to specify a fontset
  970. name in a wildcard resource like @samp{Emacs*Font}---that wildcard
  971. specification matches various other resources, such as for menus, and
  972. menus cannot handle fontsets.
  973. You can specify additional fontsets using X resources named
  974. @samp{Fontset-@var{n}}, where @var{n} is an integer starting from 0.
  975. The resource value should have this form:
  976. @smallexample
  977. @var{fontpattern}, @r{[}@var{charsetname}:@var{fontname}@r{]@dots{}}
  978. @end smallexample
  979. @noindent
  980. @var{fontpattern} should have the form of a standard X font name, except
  981. for the last two fields. They should have the form
  982. @samp{fontset-@var{alias}}.
  983. The fontset has two names, one long and one short. The long name is
  984. @var{fontpattern}. The short name is @samp{fontset-@var{alias}}. You
  985. can refer to the fontset by either name.
  986. The construct @samp{@var{charset}:@var{font}} specifies which font to
  987. use (in this fontset) for one particular character set. Here,
  988. @var{charset} is the name of a character set, and @var{font} is the
  989. font to use for that character set. You can use this construct any
  990. number of times in defining one fontset.
  991. For the other character sets, Emacs chooses a font based on
  992. @var{fontpattern}. It replaces @samp{fontset-@var{alias}} with values
  993. that describe the character set. For the ASCII character font,
  994. @samp{fontset-@var{alias}} is replaced with @samp{ISO8859-1}.
  995. In addition, when several consecutive fields are wildcards, Emacs
  996. collapses them into a single wildcard. This is to prevent use of
  997. auto-scaled fonts. Fonts made by scaling larger fonts are not usable
  998. for editing, and scaling a smaller font is not useful because it is
  999. better to use the smaller font in its own size, which is what Emacs
  1000. does.
  1001. Thus if @var{fontpattern} is this,
  1002. @example
  1003. -*-fixed-medium-r-normal-*-24-*-*-*-*-*-fontset-24
  1004. @end example
  1005. @noindent
  1006. the font specification for ASCII characters would be this:
  1007. @example
  1008. -*-fixed-medium-r-normal-*-24-*-ISO8859-1
  1009. @end example
  1010. @noindent
  1011. and the font specification for Chinese GB2312 characters would be this:
  1012. @example
  1013. -*-fixed-medium-r-normal-*-24-*-gb2312*-*
  1014. @end example
  1015. You may not have any Chinese font matching the above font
  1016. specification. Most X distributions include only Chinese fonts that
  1017. have @samp{song ti} or @samp{fangsong ti} in @var{family} field. In
  1018. such a case, @samp{Fontset-@var{n}} can be specified as below:
  1019. @smallexample
  1020. Emacs.Fontset-0: -*-fixed-medium-r-normal-*-24-*-*-*-*-*-fontset-24,\
  1021. chinese-gb2312:-*-*-medium-r-normal-*-24-*-gb2312*-*
  1022. @end smallexample
  1023. @noindent
  1024. Then, the font specifications for all but Chinese GB2312 characters have
  1025. @samp{fixed} in the @var{family} field, and the font specification for
  1026. Chinese GB2312 characters has a wild card @samp{*} in the @var{family}
  1027. field.
  1028. @findex create-fontset-from-fontset-spec
  1029. The function that processes the fontset resource value to create the
  1030. fontset is called @code{create-fontset-from-fontset-spec}. You can also
  1031. call this function explicitly to create a fontset.
  1032. @xref{Font X}, for more information about font naming in X.
  1033. @node Undisplayable Characters
  1034. @section Undisplayable Characters
  1035. Your terminal may be unable to display some non-ASCII
  1036. characters. Most non-windowing terminals can only use a single
  1037. character set (use the variable @code{default-terminal-coding-system}
  1038. (@pxref{Specify Coding}) to tell Emacs which one); characters which
  1039. can't be encoded in that coding system are displayed as @samp{?} by
  1040. default.
  1041. Windowing terminals can display a broader range of characters, but
  1042. you may not have fonts installed for all of them; characters that have
  1043. no font appear as a hollow box.
  1044. If you use Latin-1 characters but your terminal can't display
  1045. Latin-1, you can arrange to display mnemonic ASCII sequences
  1046. instead, e.g.@: @samp{"o} for o-umlaut. Load the library
  1047. @file{iso-ascii} to do this.
  1048. @vindex latin1-display
  1049. If your terminal can display Latin-1, you can display characters
  1050. from other European character sets using a mixture of equivalent
  1051. Latin-1 characters and ASCII mnemonics. Use the Custom option
  1052. @code{latin1-display} to enable this. The mnemonic ASCII
  1053. sequences mostly correspond to those of the prefix input methods.
  1054. @node Single-Byte Character Support
  1055. @section Single-byte Character Set Support
  1056. @cindex European character sets
  1057. @cindex accented characters
  1058. @cindex ISO Latin character sets
  1059. @cindex Unibyte operation
  1060. The ISO 8859 Latin-@var{n} character sets define character codes in
  1061. the range 0240 to 0377 octal (160 to 255 decimal) to handle the
  1062. accented letters and punctuation needed by various European languages
  1063. (and some non-European ones). If you disable multibyte characters,
  1064. Emacs can still handle @emph{one} of these character codes at a time.
  1065. To specify @emph{which} of these codes to use, invoke @kbd{M-x
  1066. set-language-environment} and specify a suitable language environment
  1067. such as @samp{Latin-@var{n}}.
  1068. For more information about unibyte operation, see @ref{Enabling
  1069. Multibyte}. Note particularly that you probably want to ensure that
  1070. your initialization files are read as unibyte if they contain non-ASCII
  1071. characters.
  1072. @vindex unibyte-display-via-language-environment
  1073. Emacs can also display those characters, provided the terminal or font
  1074. in use supports them. This works automatically. Alternatively, if you
  1075. are using a window system, Emacs can also display single-byte characters
  1076. through fontsets, in effect by displaying the equivalent multibyte
  1077. characters according to the current language environment. To request
  1078. this, set the variable @code{unibyte-display-via-language-environment}
  1079. to a non-@code{nil} value.
  1080. @cindex @code{iso-ascii} library
  1081. If your terminal does not support display of the Latin-1 character
  1082. set, Emacs can display these characters as ASCII sequences which at
  1083. least give you a clear idea of what the characters are. To do this,
  1084. load the library @code{iso-ascii}. Similar libraries for other
  1085. Latin-@var{n} character sets could be implemented, but we don't have
  1086. them yet.
  1087. @findex standard-display-8bit
  1088. @cindex 8-bit display
  1089. Normally non-ISO-8859 characters (decimal codes between 128 and 159
  1090. inclusive) are displayed as octal escapes. You can change this for
  1091. non-standard ``extended'' versions of ISO-8859 character sets by using the
  1092. function @code{standard-display-8bit} in the @code{disp-table} library.
  1093. There are several ways you can input single-byte non-ASCII
  1094. characters:
  1095. @itemize @bullet
  1096. @cindex 8-bit input
  1097. @item
  1098. If your keyboard can generate character codes 128 (decimal) and up,
  1099. representing non-ASCII characters, you can type those character codes
  1100. directly.
  1101. On a windowing terminal, you should not need to do anything special to
  1102. use these keys; they should simply work. On a text-only terminal, you
  1103. should use the command @code{M-x set-keyboard-coding-system} or the
  1104. Custom option @code{keyboard-coding-system} to specify which coding
  1105. system your keyboard uses (@pxref{Specify Coding}). Enabling this
  1106. feature will probably require you to use @kbd{ESC} to type Meta
  1107. characters; however, on a Linux console or in @code{xterm}, you can
  1108. arrange for Meta to be converted to @kbd{ESC} and still be able type
  1109. 8-bit characters present directly on the keyboard or using
  1110. @kbd{Compose} or @kbd{AltGr} keys. @xref{User Input}.
  1111. @item
  1112. You can use an input method for the selected language environment.
  1113. @xref{Input Methods}. When you use an input method in a unibyte buffer,
  1114. the non-ASCII character you specify with it is converted to unibyte.
  1115. @kindex C-x 8
  1116. @cindex @code{iso-transl} library
  1117. @cindex compose character
  1118. @cindex dead character
  1119. @item
  1120. For Latin-1 only, you can use the
  1121. key @kbd{C-x 8} as a ``compose character'' prefix for entry of
  1122. non-ASCII Latin-1 printing characters. @kbd{C-x 8} is good for
  1123. insertion (in the minibuffer as well as other buffers), for searching,
  1124. and in any other context where a key sequence is allowed.
  1125. @kbd{C-x 8} works by loading the @code{iso-transl} library. Once that
  1126. library is loaded, the @key{ALT} modifier key, if you have one, serves
  1127. the same purpose as @kbd{C-x 8}; use @key{ALT} together with an accent
  1128. character to modify the following letter. In addition, if you have keys
  1129. for the Latin-1 ``dead accent characters,'' they too are defined to
  1130. compose with the following character, once @code{iso-transl} is loaded.
  1131. Use @kbd{C-x 8 C-h} to list the available translations as mnemonic
  1132. command names.
  1133. @item
  1134. @cindex @code{iso-acc} library
  1135. @cindex ISO Accents mode
  1136. @findex iso-accents-mode
  1137. @cindex Latin-1, Latin-2 and Latin-3 input mode
  1138. For Latin-1, Latin-2 and Latin-3, @kbd{M-x iso-accents-mode} enables
  1139. a minor mode that works much like the @code{latin-1-prefix} input
  1140. method, but does not depend on having the input methods installed. This
  1141. mode is buffer-local. It can be customized for various languages with
  1142. @kbd{M-x iso-accents-customize}.
  1143. @end itemize
  1144. @node Charsets
  1145. @section Charsets
  1146. @cindex charsets
  1147. Emacs groups all supported characters into disjoint @dfn{charsets}.
  1148. Each character code belongs to one and only one charset. For
  1149. historical reasons, Emacs typically divides an 8-bit character code
  1150. for an extended version of ASCII into two charsets: ASCII, which
  1151. covers the codes 0 through 127, plus another charset which covers the
  1152. ``right-hand part'' (the codes 128 and up). For instance, the
  1153. characters of Latin-1 include the Emacs charset @code{ascii} plus the
  1154. Emacs charset @code{latin-iso8859-1}.
  1155. Emacs characters belonging to different charsets may look the same,
  1156. but they are still different characters. For example, the letter
  1157. @samp{o} with acute accent in charset @code{latin-iso8859-1}, used for
  1158. Latin-1, is different from the letter @samp{o} with acute accent in
  1159. charset @code{latin-iso8859-2}, used for Latin-2.
  1160. @findex list-charset-chars
  1161. @cindex characters in a certain charset
  1162. @findex describe-character-set
  1163. There are two commands for obtaining information about Emacs
  1164. charsets. The command @kbd{M-x list-charset-chars} prompts for a name
  1165. of a character set, and displays all the characters in that character
  1166. set. The command @kbd{M-x describe-character-set} prompts for a
  1167. charset name and displays information about that charset, including
  1168. its internal representation within Emacs.
  1169. To find out which charset a character in the buffer belongs to,
  1170. put point before it and type @kbd{C-u C-x =}.