Mercurial > emacs
annotate doc/lispref/nonascii.texi @ 99851:68981b04c1ac
2008-11-23 Carsten Dominik <dominik@science.uva.nl>
* org.texi (Setting up Remember): Document `org-remember-mode'.
(External links): Document that bbdb links can use a regular
expression.
(External links): Document that elisp links can contain interactive
commands.
author | Carsten Dominik <dominik@science.uva.nl> |
---|---|
date | Sun, 23 Nov 2008 13:40:03 +0000 |
parents | 512ddf0d1748 |
children | 527cfe29292e |
rev | line source |
---|---|
84090 | 1 @c -*-texinfo-*- |
2 @c This is part of the GNU Emacs Lisp Reference Manual. | |
3 @c Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, | |
87649 | 4 @c 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
84090 | 5 @c See the file elisp.texi for copying conditions. |
84116
0ba80d073e27
(setfilename): Go up one more level to ../../info.
Glenn Morris <rgm@gnu.org>
parents:
84090
diff
changeset
|
6 @setfilename ../../info/characters |
84090 | 7 @node Non-ASCII Characters, Searching and Matching, Text, Top |
8 @chapter Non-@acronym{ASCII} Characters | |
9 @cindex multibyte characters | |
10 @cindex characters, multi-byte | |
11 @cindex non-@acronym{ASCII} characters | |
12 | |
99313
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
13 This chapter covers the special issues relating to characters and |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
14 how they are stored in strings and buffers. |
84090 | 15 |
16 @menu | |
99313
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
17 * Text Representations:: How Emacs represents text. |
84090 | 18 * Converting Representations:: Converting unibyte to multibyte and vice versa. |
19 * Selecting a Representation:: Treating a byte sequence as unibyte or multi. | |
20 * Character Codes:: How unibyte and multibyte relate to | |
21 codes of individual characters. | |
22 * Character Sets:: The space of possible character codes | |
23 is divided into various character sets. | |
24 * Scanning Charsets:: Which character sets are used in a buffer? | |
25 * Translation of Characters:: Translation tables are used for conversion. | |
26 * Coding Systems:: Coding systems are conversions for saving files. | |
27 * Input Methods:: Input methods allow users to enter various | |
28 non-ASCII characters without special keyboards. | |
29 * Locales:: Interacting with the POSIX locale. | |
30 @end menu | |
31 | |
32 @node Text Representations | |
33 @section Text Representations | |
99313
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
34 @cindex text representation |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
35 |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
36 Emacs buffers and strings support a large repertoire of characters |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
37 from many different scripts. This is so users could type and display |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
38 text in most any known written language. |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
39 |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
40 @cindex character codepoint |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
41 @cindex codespace |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
42 @cindex Unicode |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
43 To support this multitude of characters and scripts, Emacs closely |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
44 follows the @dfn{Unicode Standard}. The Unicode Standard assigns a |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
45 unique number, called a @dfn{codepoint}, to each and every character. |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
46 The range of codepoints defined by Unicode, or the Unicode |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
47 @dfn{codespace}, is @code{0..10FFFF} (in hex) inclusive. Emacs |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
48 extends this range with codepoints in the range @code{110000..3FFFFF}, |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
49 which it uses for representing characters that are not unified with |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
50 Unicode and raw 8-bit bytes that cannot be interpreted as characters |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
51 (the latter occupy the range @code{3FFF80..3FFFFF}). Thus, a |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
52 character codepoint in Emacs is a 22-bit integer number. |
84090 | 53 |
99313
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
54 @cindex internal representation of characters |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
55 @cindex characters, representation in buffers and strings |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
56 @cindex multibyte text |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
57 To conserve memory, Emacs does not hold fixed-length 22-bit numbers |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
58 that are codepoints of text characters within buffers and strings. |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
59 Rather, Emacs uses a variable-length internal representation of |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
60 characters, that stores each character as a sequence of 1 to 5 8-bit |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
61 bytes, depending on the magnitude of its codepoint@footnote{ |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
62 This internal representation is based on one of the encodings defined |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
63 by the Unicode Standard, called @dfn{UTF-8}, for representing any |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
64 Unicode codepoint, but Emacs extends UTF-8 to represent the additional |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
65 codepoints it uses for raw 8-bit bytes.}. |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
66 For example, any @acronym{ASCII} character takes up only 1 byte, a |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
67 Latin-1 character takes up 2 bytes, etc. We call this representation |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
68 of text @dfn{multibyte}, because it uses several bytes for each |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
69 character. |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
70 |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
71 Outside Emacs, characters can be represented in many different |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
72 encodings, such as ISO-8859-1, GB-2312, Big-5, etc. Emacs converts |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
73 between these external encodings and the internal representation, as |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
74 appropriate, when it reads text into a buffer or a string, or when it |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
75 writes text to a disk file or passes it to some other process. |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
76 |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
77 Occasionally, Emacs needs to hold and manipulate encoded text or |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
78 binary non-text data in its buffers or strings. For example, when |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
79 Emacs visits a file, it first reads the file's text verbatim into a |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
80 buffer, and only then converts it to the internal representation. |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
81 Before the conversion, the buffer holds encoded text. |
84090 | 82 |
83 @cindex unibyte text | |
99313
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
84 Encoded text is not really text, as far as Emacs is concerned, but |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
85 rather a sequence of raw 8-bit bytes. We call buffers and strings |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
86 that hold encoded text @dfn{unibyte} buffers and strings, because |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
87 Emacs treats them as a sequence of individual bytes. In particular, |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
88 Emacs usually displays unibyte buffers and strings as octal codes such |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
89 as @code{\237}. We recommend that you never use unibyte buffers and |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
90 strings except for manipulating encoded text or binary non-text data. |
84090 | 91 |
92 In a buffer, the buffer-local value of the variable | |
93 @code{enable-multibyte-characters} specifies the representation used. | |
94 The representation for a string is determined and recorded in the string | |
95 when the string is constructed. | |
96 | |
97 @defvar enable-multibyte-characters | |
98 This variable specifies the current buffer's text representation. | |
99 If it is non-@code{nil}, the buffer contains multibyte text; otherwise, | |
99313
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
100 it contains unibyte encoded text or binary non-text data. |
84090 | 101 |
102 You cannot set this variable directly; instead, use the function | |
103 @code{set-buffer-multibyte} to change a buffer's representation. | |
104 @end defvar | |
105 | |
106 @defvar default-enable-multibyte-characters | |
107 This variable's value is entirely equivalent to @code{(default-value | |
108 'enable-multibyte-characters)}, and setting this variable changes that | |
109 default value. Setting the local binding of | |
110 @code{enable-multibyte-characters} in a specific buffer is not allowed, | |
111 but changing the default value is supported, and it is a reasonable | |
112 thing to do, because it has no effect on existing buffers. | |
113 | |
114 The @samp{--unibyte} command line option does its job by setting the | |
115 default value to @code{nil} early in startup. | |
116 @end defvar | |
117 | |
118 @defun position-bytes position | |
99313
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
119 Buffer positions are measured in character units. This function |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
120 returns the byte-position corresponding to buffer position |
84090 | 121 @var{position} in the current buffer. This is 1 at the start of the |
122 buffer, and counts upward in bytes. If @var{position} is out of | |
123 range, the value is @code{nil}. | |
124 @end defun | |
125 | |
126 @defun byte-to-position byte-position | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
127 Return the buffer position, in character units, corresponding to given |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
128 @var{byte-position} in the current buffer. If @var{byte-position} is |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
129 out of range, the value is @code{nil}. In a multibyte buffer, an |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
130 arbitrary value of @var{byte-position} can be not at character |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
131 boundary, but inside a multibyte sequence representing a single |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
132 character; in this case, this function returns the buffer position of |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
133 the character whose multibyte sequence includes @var{byte-position}. |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
134 In other words, the value does not change for all byte positions that |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
135 belong to the same character. |
84090 | 136 @end defun |
137 | |
138 @defun multibyte-string-p string | |
99313
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
139 Return @code{t} if @var{string} is a multibyte string, @code{nil} |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
140 otherwise. |
84090 | 141 @end defun |
142 | |
143 @defun string-bytes string | |
144 @cindex string, number of bytes | |
145 This function returns the number of bytes in @var{string}. | |
146 If @var{string} is a multibyte string, this can be greater than | |
147 @code{(length @var{string})}. | |
148 @end defun | |
149 | |
99313
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
150 @defun unibyte-string &rest bytes |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
151 This function concatenates all its argument @var{bytes} and makes the |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
152 result a unibyte string. |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
153 @end defun |
175420e76f65
(Text Representations): Rewrite to make consistent with Emacs 23
Eli Zaretskii <eliz@gnu.org>
parents:
99044
diff
changeset
|
154 |
84090 | 155 @node Converting Representations |
156 @section Converting Text Representations | |
157 | |
158 Emacs can convert unibyte text to multibyte; it can also convert | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
159 multibyte text to unibyte, provided that the multibyte text contains |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
160 only @acronym{ASCII} and 8-bit characters. In general, these |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
161 conversions happen when inserting text into a buffer, or when putting |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
162 text from several strings together in one string. You can also |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
163 explicitly convert a string's contents to either representation. |
84090 | 164 |
165 Emacs chooses the representation for a string based on the text that | |
166 it is constructed from. The general rule is to convert unibyte text to | |
167 multibyte text when combining it with other multibyte text, because the | |
168 multibyte representation is more general and can hold whatever | |
169 characters the unibyte text has. | |
170 | |
171 When inserting text into a buffer, Emacs converts the text to the | |
172 buffer's representation, as specified by | |
173 @code{enable-multibyte-characters} in that buffer. In particular, when | |
174 you insert multibyte text into a unibyte buffer, Emacs converts the text | |
175 to unibyte, even though this conversion cannot in general preserve all | |
176 the characters that might be in the multibyte text. The other natural | |
177 alternative, to convert the buffer contents to multibyte, is not | |
178 acceptable because the buffer's representation is a choice made by the | |
179 user that cannot be overridden automatically. | |
180 | |
181 Converting unibyte text to multibyte text leaves @acronym{ASCII} characters | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
182 unchanged, and converts bytes with codes 128 through 159 to the |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
183 multibyte representation of raw eight-bit bytes. |
84090 | 184 |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
185 Converting multibyte text to unibyte converts all @acronym{ASCII} |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
186 and eight-bit characters to their single-byte form, but loses |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
187 information for non-@acronym{ASCII} characters by discarding all but |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
188 the low 8 bits of each character's codepoint. Converting unibyte text |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
189 to multibyte and back to unibyte reproduces the original unibyte text. |
84090 | 190 |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
191 The next two functions either return the argument @var{string}, or a |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
192 newly created string with no text properties. |
84090 | 193 |
194 @defun string-to-multibyte string | |
195 This function returns a multibyte string containing the same sequence | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
196 of characters as @var{string}. If @var{string} is a multibyte string, |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
197 it is returned unchanged. |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
198 @end defun |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
199 |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
200 @defun string-to-unibyte string |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
201 This function returns a unibyte string containing the same sequence of |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
202 characters as @var{string}. It signals an error if @var{string} |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
203 contains a non-@acronym{ASCII} character. If @var{string} is a |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
204 unibyte string, it is returned unchanged. |
84090 | 205 @end defun |
206 | |
207 @defun multibyte-char-to-unibyte char | |
208 This convert the multibyte character @var{char} to a unibyte | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
209 character. If @var{char} is a non-@acronym{ASCII} character, the |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
210 value is -1. |
84090 | 211 @end defun |
212 | |
213 @defun unibyte-char-to-multibyte char | |
214 This convert the unibyte character @var{char} to a multibyte | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
215 character. |
84090 | 216 @end defun |
217 | |
218 @node Selecting a Representation | |
219 @section Selecting a Representation | |
220 | |
221 Sometimes it is useful to examine an existing buffer or string as | |
222 multibyte when it was unibyte, or vice versa. | |
223 | |
224 @defun set-buffer-multibyte multibyte | |
225 Set the representation type of the current buffer. If @var{multibyte} | |
226 is non-@code{nil}, the buffer becomes multibyte. If @var{multibyte} | |
227 is @code{nil}, the buffer becomes unibyte. | |
228 | |
229 This function leaves the buffer contents unchanged when viewed as a | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
230 sequence of bytes. As a consequence, it can change the contents |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
231 viewed as characters; a sequence of three bytes which is treated as |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
232 one character in multibyte representation will count as three |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
233 characters in unibyte representation. Eight-bit characters |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
234 representing raw bytes are an exception. They are represented by one |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
235 byte in a unibyte buffer, but when the buffer is set to multibyte, |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
236 they are converted to two-byte sequences, and vice versa. |
84090 | 237 |
238 This function sets @code{enable-multibyte-characters} to record which | |
239 representation is in use. It also adjusts various data in the buffer | |
240 (including overlays, text properties and markers) so that they cover the | |
241 same text as they did before. | |
242 | |
243 You cannot use @code{set-buffer-multibyte} on an indirect buffer, | |
244 because indirect buffers always inherit the representation of the | |
245 base buffer. | |
246 @end defun | |
247 | |
248 @defun string-as-unibyte string | |
249 This function returns a string with the same bytes as @var{string} but | |
250 treating each byte as a character. This means that the value may have | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
251 more characters than @var{string} has. Eight-bit characters |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
252 representing raw bytes are an exception: each one of them is converted |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
253 to a single byte. |
84090 | 254 |
255 If @var{string} is already a unibyte string, then the value is | |
256 @var{string} itself. Otherwise it is a newly created string, with no | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
257 text properties. |
84090 | 258 @end defun |
259 | |
260 @defun string-as-multibyte string | |
261 This function returns a string with the same bytes as @var{string} but | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
262 treating each multibyte sequence as one character. This means that |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
263 the value may have fewer characters than @var{string} has. If a byte |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
264 sequence in @var{string} is invalid as a multibyte representation of a |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
265 single character, each byte in the sequence is treated as raw 8-bit |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
266 byte. |
84090 | 267 |
268 If @var{string} is already a multibyte string, then the value is | |
269 @var{string} itself. Otherwise it is a newly created string, with no | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
270 text properties. |
84090 | 271 @end defun |
272 | |
273 @node Character Codes | |
274 @section Character Codes | |
275 @cindex character codes | |
276 | |
99044
7c989edf1f9f
(Character Codes): Remove obsolete function char-valid-p, and document
Chong Yidong <cyd@stupidchicken.com>
parents:
98710
diff
changeset
|
277 The unibyte and multibyte text representations use different |
7c989edf1f9f
(Character Codes): Remove obsolete function char-valid-p, and document
Chong Yidong <cyd@stupidchicken.com>
parents:
98710
diff
changeset
|
278 character codes. The valid character codes for unibyte representation |
7c989edf1f9f
(Character Codes): Remove obsolete function char-valid-p, and document
Chong Yidong <cyd@stupidchicken.com>
parents:
98710
diff
changeset
|
279 range from 0 to 255---the values that can fit in one byte. The valid |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
280 character codes for multibyte representation range from 0 to 4194303 |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
281 (#x3FFFFF). In this code space, values 0 through 127 are for |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
282 @acronym{ASCII} charcters, and values 129 through 4194175 (#x3FFF7F) |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
283 are for non-@acronym{ASCII} characters. Values 0 through 1114111 |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
284 (#10FFFF) corresponds to Unicode characters of the same codepoint, |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
285 while values 4194176 (#x3FFF80) through 4194303 (#x3FFFFF) are for |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
286 representing eight-bit raw bytes. |
84090 | 287 |
99044
7c989edf1f9f
(Character Codes): Remove obsolete function char-valid-p, and document
Chong Yidong <cyd@stupidchicken.com>
parents:
98710
diff
changeset
|
288 @defun characterp charcode |
7c989edf1f9f
(Character Codes): Remove obsolete function char-valid-p, and document
Chong Yidong <cyd@stupidchicken.com>
parents:
98710
diff
changeset
|
289 This returns @code{t} if @var{charcode} is a valid character, and |
7c989edf1f9f
(Character Codes): Remove obsolete function char-valid-p, and document
Chong Yidong <cyd@stupidchicken.com>
parents:
98710
diff
changeset
|
290 @code{nil} otherwise. |
84090 | 291 |
292 @example | |
99044
7c989edf1f9f
(Character Codes): Remove obsolete function char-valid-p, and document
Chong Yidong <cyd@stupidchicken.com>
parents:
98710
diff
changeset
|
293 (characterp 65) |
84090 | 294 @result{} t |
99044
7c989edf1f9f
(Character Codes): Remove obsolete function char-valid-p, and document
Chong Yidong <cyd@stupidchicken.com>
parents:
98710
diff
changeset
|
295 (characterp 4194303) |
7c989edf1f9f
(Character Codes): Remove obsolete function char-valid-p, and document
Chong Yidong <cyd@stupidchicken.com>
parents:
98710
diff
changeset
|
296 @result{} t |
7c989edf1f9f
(Character Codes): Remove obsolete function char-valid-p, and document
Chong Yidong <cyd@stupidchicken.com>
parents:
98710
diff
changeset
|
297 (characterp 4194304) |
7c989edf1f9f
(Character Codes): Remove obsolete function char-valid-p, and document
Chong Yidong <cyd@stupidchicken.com>
parents:
98710
diff
changeset
|
298 @result{} nil |
84090 | 299 @end example |
300 @end defun | |
301 | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
302 @defun get-byte pos &optional string |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
303 This function returns the byte at current buffer's character position |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
304 @var{pos}. If the current buffer is unibyte, this is literally the |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
305 byte at that position. If the buffer is multibyte, byte values of |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
306 @acronym{ASCII} characters are the same as character codepoints, |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
307 whereas eight-bit raw bytes are converted to their 8-bit codes. The |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
308 function signals an error if the character at @var{pos} is |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
309 non-@acronym{ASCII}. |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
310 |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
311 The optional argument @var{string} means to get a byte value from that |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
312 string instead of the current buffer. |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
313 @end defun |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
314 |
84090 | 315 @node Character Sets |
316 @section Character Sets | |
317 @cindex character sets | |
318 | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
319 @cindex charset |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
320 @cindex coded character set |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
321 An Emacs @dfn{character set}, or @dfn{charset}, is a set of characters |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
322 in which each character is assigned a numeric code point. (The |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
323 Unicode standard calls this a @dfn{coded character set}.) Each |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
324 charset has a name which is a symbol. A single character can belong |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
325 to any number of different character sets, but it will generally have |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
326 a different code point in each charset. Examples of character sets |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
327 include @code{ascii}, @code{iso-8859-1}, @code{greek-iso8859-7}, and |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
328 @code{windows-1255}. The code point assigned to a character in a |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
329 charset is usually different from its code point used in Emacs buffers |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
330 and strings. |
84090 | 331 |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
332 @cindex @code{emacs}, a charset |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
333 @cindex @code{unicode}, a charset |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
334 @cindex @code{eight-bit}, a charset |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
335 Emacs defines several special character sets. The character set |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
336 @code{unicode} includes all the characters whose Emacs code points are |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
337 in the range @code{0..10FFFF}. The character set @code{emacs} |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
338 includes all @acronym{ASCII} and non-@acronym{ASCII} characters. |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
339 Finally, the @code{eight-bit} charset includes the 8-bit raw bytes; |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
340 Emacs uses it to represent raw bytes encountered in text. |
84090 | 341 |
342 @defun charsetp object | |
343 Returns @code{t} if @var{object} is a symbol that names a character set, | |
344 @code{nil} otherwise. | |
345 @end defun | |
346 | |
347 @defvar charset-list | |
348 The value is a list of all defined character set names. | |
349 @end defvar | |
350 | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
351 @defun charset-priority-list &optional highestp |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
352 This functions returns a list of all defined character sets ordered by |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
353 their priority. If @var{highestp} is non-@code{nil}, the function |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
354 returns a single character set of the highest priority. |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
355 @end defun |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
356 |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
357 @defun set-charset-priority &rest charsets |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
358 This function makes @var{charsets} the highest priority character sets. |
84090 | 359 @end defun |
360 | |
361 @defun char-charset character | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
362 This function returns the name of the character set of highest |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
363 priority that @var{character} belongs to. @acronym{ASCII} characters |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
364 are an exception: for them, this function always returns @code{ascii}. |
84090 | 365 @end defun |
366 | |
367 @defun charset-plist charset | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
368 This function returns the property list of the character set |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
369 @var{charset}. Although @var{charset} is a symbol, this is not the |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
370 same as the property list of that symbol. Charset properties include |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
371 important information about the charset, such as its documentation |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
372 string, short name, etc. |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
373 @end defun |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
374 |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
375 @defun put-charset-property charset propname value |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
376 This function sets the @var{propname} property of @var{charset} to the |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
377 given @var{value}. |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
378 @end defun |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
379 |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
380 @defun get-charset-property charset propname |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
381 This function returns the value of @var{charset}s property |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
382 @var{propname}. |
84090 | 383 @end defun |
384 | |
385 @deffn Command list-charset-chars charset | |
386 This command displays a list of characters in the character set | |
387 @var{charset}. | |
388 @end deffn | |
389 | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
390 @defun decode-char charset code-point |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
391 This function decodes a character that is assigned a @var{code-point} |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
392 in @var{charset}, to the corresponding Emacs character, and returns |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
393 that character. If @var{charset} doesn't contain a character of that |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
394 code point, the value is @code{nil}. If @var{code-point} doesnt't fit |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
395 in a Lisp integer (@pxref{Integer Basics, most-positive-fixnum}), it |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
396 can be specified as a cons cell @code{(@var{high} . @var{low})}, where |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
397 @var{low} are the lower 16 bits of the value and @var{high} are the |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
398 high 16 bits. |
84090 | 399 @end defun |
400 | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
401 @defun encode-char char charset |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
402 This function returns the code point assigned to the character |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
403 @var{char} in @var{charset}. If @var{charset} doesn't contain |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
404 @var{char}, the value is @code{nil}. |
84090 | 405 @end defun |
406 | |
407 @node Scanning Charsets | |
408 @section Scanning for Character Sets | |
409 | |
410 Sometimes it is useful to find out which character sets appear in a | |
411 part of a buffer or a string. One use for this is in determining which | |
412 coding systems (@pxref{Coding Systems}) are capable of representing all | |
413 of the text in question. | |
414 | |
415 @defun charset-after &optional pos | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
416 This function returns the charset of highest priority containing the |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
417 character in the current buffer at position @var{pos}. If @var{pos} |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
418 is omitted or @code{nil}, it defaults to the current value of point. |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
419 If @var{pos} is out of range, the value is @code{nil}. |
84090 | 420 @end defun |
421 | |
422 @defun find-charset-region beg end &optional translation | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
423 This function returns a list of the character sets of highest priority |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
424 that contain charcters in the current buffer between positions |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
425 @var{beg} and @var{end}. |
84090 | 426 |
427 The optional argument @var{translation} specifies a translation table to | |
428 be used in scanning the text (@pxref{Translation of Characters}). If it | |
429 is non-@code{nil}, then each character in the region is translated | |
430 through this table, and the value returned describes the translated | |
431 characters instead of the characters actually in the buffer. | |
432 @end defun | |
433 | |
434 @defun find-charset-string string &optional translation | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
435 This function returns a list of the character sets of highest priority |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
436 that contain characters in @var{string}. It is just like |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
437 @code{find-charset-region}, except that it applies to the contents of |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
438 @var{string} instead of part of the current buffer. |
84090 | 439 @end defun |
440 | |
441 @node Translation of Characters | |
442 @section Translation of Characters | |
443 @cindex character translation tables | |
444 @cindex translation tables | |
445 | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
446 A @dfn{translation table} is a char-table (@pxref{Char-Tables}) that |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
447 specifies a mapping of characters into characters. These tables are |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
448 used in encoding and decoding, and for other purposes. Some coding |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
449 systems specify their own particular translation tables; there are |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
450 also default translation tables which apply to all other coding |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
451 systems. |
84090 | 452 |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
453 A translation table has two extra slots. The first is either |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
454 @code{nil} or a translation table that performs the reverse |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
455 translation; the second is the maximum number of characters to look up |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
456 for translation. |
84090 | 457 |
458 @defun make-translation-table &rest translations | |
459 This function returns a translation table based on the argument | |
460 @var{translations}. Each element of @var{translations} should be a | |
461 list of elements of the form @code{(@var{from} . @var{to})}; this says | |
462 to translate the character @var{from} into @var{to}. | |
463 | |
464 The arguments and the forms in each argument are processed in order, | |
465 and if a previous form already translates @var{to} to some other | |
466 character, say @var{to-alt}, @var{from} is also translated to | |
467 @var{to-alt}. | |
468 @end defun | |
469 | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
470 During decoding, the translation table's translations are applied to |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
471 the characters that result from ordinary decoding. If a coding system |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
472 has property @code{:decode-translation-table}, that specifies the |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
473 translation table to use, or a list of translation tables to apply in |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
474 sequence. (This is a property of the coding system, as returned by |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
475 @code{coding-system-get}, not a property of the symbol that is the |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
476 coding system's name. @xref{Coding System Basics,, Basic Concepts of |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
477 Coding Systems}.) Finally, if |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
478 @code{standard-translation-table-for-decode} is non-@code{nil}, the |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
479 resulting characters are translated by that table. |
84090 | 480 |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
481 During encoding, the translation table's translations are applied to |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
482 the characters in the buffer, and the result of translation is |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
483 actually encoded. If a coding system has property |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
484 @code{:encode-translation-table}, that specifies the translation table |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
485 to use, or a list of translation tables to apply in sequence. In |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
486 addition, if the variable @code{standard-translation-table-for-encode} |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
487 is non-@code{nil}, it specifies the translation table to use for |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
488 translating the result. |
84090 | 489 |
490 @defvar standard-translation-table-for-decode | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
491 This is the default translation table for decoding. If a coding |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
492 systems specifies its own translation tables, the table that is the |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
493 value of this variable, if non-@code{nil}, is applied after them. |
84090 | 494 @end defvar |
495 | |
496 @defvar standard-translation-table-for-encode | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
497 This is the default translation table for encoding. If a coding |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
498 systems specifies its own translation tables, the table that is the |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
499 value of this variable, if non-@code{nil}, is applied after them. |
84090 | 500 @end defvar |
501 | |
99802
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
502 @defun make-translation-table-from-vector vec |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
503 This function returns a translation table made from @var{vec} that is |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
504 an array of 256 elements to map byte values 0 through 255 to |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
505 characters. Elements may be @code{nil} for untranslated bytes. The |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
506 returned table has a translation table for reverse mapping in the |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
507 first extra slot. |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
508 |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
509 This function provides an easy way to make a private coding system |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
510 that maps each byte to a specific character. You can specify the |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
511 returned table and the reverse translation table using the properties |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
512 @code{:decode-translation-table} and @code{:encode-translation-table} |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
513 respectively in the @var{props} argument to |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
514 @code{define-coding-system}. |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
515 @end defun |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
516 |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
517 @defun make-translation-table-from-alist alist |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
518 This function is similar to @code{make-translation-table} but returns |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
519 a complex translation table rather than a simple one-to-one mapping. |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
520 Each element of @var{alist} is of the form @code{(@var{from} |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
521 . @var{to})}, where @var{from} and @var{to} are either a character or |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
522 a vector specifying a sequence of characters. If @var{from} is a |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
523 character, that character is translated to @var{to} (i.e.@: to a |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
524 character or a character sequence). If @var{from} is a vector of |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
525 characters, that sequence is translated to @var{to}. The returned |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
526 table has a translation table for reverse mapping in the first extra |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
527 slot. |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
528 @end defun |
512ddf0d1748
(Character Codes, Character Sets)
Eli Zaretskii <eliz@gnu.org>
parents:
99313
diff
changeset
|
529 |
84090 | 530 @node Coding Systems |
531 @section Coding Systems | |
532 | |
533 @cindex coding system | |
534 When Emacs reads or writes a file, and when Emacs sends text to a | |
535 subprocess or receives text from a subprocess, it normally performs | |
536 character code conversion and end-of-line conversion as specified | |
537 by a particular @dfn{coding system}. | |
538 | |
539 How to define a coding system is an arcane matter, and is not | |
540 documented here. | |
541 | |
542 @menu | |
543 * Coding System Basics:: Basic concepts. | |
544 * Encoding and I/O:: How file I/O functions handle coding systems. | |
545 * Lisp and Coding Systems:: Functions to operate on coding system names. | |
546 * User-Chosen Coding Systems:: Asking the user to choose a coding system. | |
547 * Default Coding Systems:: Controlling the default choices. | |
548 * Specifying Coding Systems:: Requesting a particular coding system | |
549 for a single file operation. | |
550 * Explicit Encoding:: Encoding or decoding text without doing I/O. | |
551 * Terminal I/O Encoding:: Use of encoding for terminal I/O. | |
552 * MS-DOS File Types:: How DOS "text" and "binary" files | |
553 relate to coding systems. | |
554 @end menu | |
555 | |
556 @node Coding System Basics | |
557 @subsection Basic Concepts of Coding Systems | |
558 | |
559 @cindex character code conversion | |
560 @dfn{Character code conversion} involves conversion between the encoding | |
561 used inside Emacs and some other encoding. Emacs supports many | |
562 different encodings, in that it can convert to and from them. For | |
563 example, it can convert text to or from encodings such as Latin 1, Latin | |
564 2, Latin 3, Latin 4, Latin 5, and several variants of ISO 2022. In some | |
565 cases, Emacs supports several alternative encodings for the same | |
566 characters; for example, there are three coding systems for the Cyrillic | |
567 (Russian) alphabet: ISO, Alternativnyj, and KOI8. | |
568 | |
569 Most coding systems specify a particular character code for | |
570 conversion, but some of them leave the choice unspecified---to be chosen | |
571 heuristically for each file, based on the data. | |
572 | |
573 In general, a coding system doesn't guarantee roundtrip identity: | |
574 decoding a byte sequence using coding system, then encoding the | |
575 resulting text in the same coding system, can produce a different byte | |
576 sequence. However, the following coding systems do guarantee that the | |
577 byte sequence will be the same as what you originally decoded: | |
578 | |
579 @quotation | |
580 chinese-big5 chinese-iso-8bit cyrillic-iso-8bit emacs-mule | |
581 greek-iso-8bit hebrew-iso-8bit iso-latin-1 iso-latin-2 iso-latin-3 | |
582 iso-latin-4 iso-latin-5 iso-latin-8 iso-latin-9 iso-safe | |
583 japanese-iso-8bit japanese-shift-jis korean-iso-8bit raw-text | |
584 @end quotation | |
585 | |
586 Encoding buffer text and then decoding the result can also fail to | |
587 reproduce the original text. For instance, if you encode Latin-2 | |
588 characters with @code{utf-8} and decode the result using the same | |
589 coding system, you'll get Unicode characters (of charset | |
590 @code{mule-unicode-0100-24ff}). If you encode Unicode characters with | |
591 @code{iso-latin-2} and decode the result with the same coding system, | |
592 you'll get Latin-2 characters. | |
593 | |
594 @cindex EOL conversion | |
595 @cindex end-of-line conversion | |
596 @cindex line end conversion | |
597 @dfn{End of line conversion} handles three different conventions used | |
598 on various systems for representing end of line in files. The Unix | |
599 convention is to use the linefeed character (also called newline). The | |
600 DOS convention is to use a carriage-return and a linefeed at the end of | |
601 a line. The Mac convention is to use just carriage-return. | |
602 | |
603 @cindex base coding system | |
604 @cindex variant coding system | |
605 @dfn{Base coding systems} such as @code{latin-1} leave the end-of-line | |
606 conversion unspecified, to be chosen based on the data. @dfn{Variant | |
607 coding systems} such as @code{latin-1-unix}, @code{latin-1-dos} and | |
608 @code{latin-1-mac} specify the end-of-line conversion explicitly as | |
609 well. Most base coding systems have three corresponding variants whose | |
610 names are formed by adding @samp{-unix}, @samp{-dos} and @samp{-mac}. | |
611 | |
612 The coding system @code{raw-text} is special in that it prevents | |
613 character code conversion, and causes the buffer visited with that | |
614 coding system to be a unibyte buffer. It does not specify the | |
615 end-of-line conversion, allowing that to be determined as usual by the | |
616 data, and has the usual three variants which specify the end-of-line | |
617 conversion. @code{no-conversion} is equivalent to @code{raw-text-unix}: | |
618 it specifies no conversion of either character codes or end-of-line. | |
619 | |
620 The coding system @code{emacs-mule} specifies that the data is | |
621 represented in the internal Emacs encoding. This is like | |
622 @code{raw-text} in that no code conversion happens, but different in | |
623 that the result is multibyte data. | |
624 | |
625 @defun coding-system-get coding-system property | |
626 This function returns the specified property of the coding system | |
627 @var{coding-system}. Most coding system properties exist for internal | |
628 purposes, but one that you might find useful is @code{mime-charset}. | |
629 That property's value is the name used in MIME for the character coding | |
630 which this coding system can read and write. Examples: | |
631 | |
632 @example | |
633 (coding-system-get 'iso-latin-1 'mime-charset) | |
634 @result{} iso-8859-1 | |
635 (coding-system-get 'iso-2022-cn 'mime-charset) | |
636 @result{} iso-2022-cn | |
637 (coding-system-get 'cyrillic-koi8 'mime-charset) | |
638 @result{} koi8-r | |
639 @end example | |
640 | |
641 The value of the @code{mime-charset} property is also defined | |
642 as an alias for the coding system. | |
643 @end defun | |
644 | |
645 @node Encoding and I/O | |
646 @subsection Encoding and I/O | |
647 | |
648 The principal purpose of coding systems is for use in reading and | |
649 writing files. The function @code{insert-file-contents} uses | |
650 a coding system for decoding the file data, and @code{write-region} | |
651 uses one to encode the buffer contents. | |
652 | |
653 You can specify the coding system to use either explicitly | |
654 (@pxref{Specifying Coding Systems}), or implicitly using a default | |
655 mechanism (@pxref{Default Coding Systems}). But these methods may not | |
656 completely specify what to do. For example, they may choose a coding | |
657 system such as @code{undefined} which leaves the character code | |
658 conversion to be determined from the data. In these cases, the I/O | |
659 operation finishes the job of choosing a coding system. Very often | |
660 you will want to find out afterwards which coding system was chosen. | |
661 | |
662 @defvar buffer-file-coding-system | |
87276
c9e81d5cb2e7
(Encoding and I/O): Reword to avoid saying
Martin Rudalics <rudalics@gmx.at>
parents:
84116
diff
changeset
|
663 This buffer-local variable records the coding system used for saving the |
c9e81d5cb2e7
(Encoding and I/O): Reword to avoid saying
Martin Rudalics <rudalics@gmx.at>
parents:
84116
diff
changeset
|
664 buffer and for writing part of the buffer with @code{write-region}. If |
c9e81d5cb2e7
(Encoding and I/O): Reword to avoid saying
Martin Rudalics <rudalics@gmx.at>
parents:
84116
diff
changeset
|
665 the text to be written cannot be safely encoded using the coding system |
c9e81d5cb2e7
(Encoding and I/O): Reword to avoid saying
Martin Rudalics <rudalics@gmx.at>
parents:
84116
diff
changeset
|
666 specified by this variable, these operations select an alternative |
c9e81d5cb2e7
(Encoding and I/O): Reword to avoid saying
Martin Rudalics <rudalics@gmx.at>
parents:
84116
diff
changeset
|
667 encoding by calling the function @code{select-safe-coding-system} |
c9e81d5cb2e7
(Encoding and I/O): Reword to avoid saying
Martin Rudalics <rudalics@gmx.at>
parents:
84116
diff
changeset
|
668 (@pxref{User-Chosen Coding Systems}). If selecting a different encoding |
c9e81d5cb2e7
(Encoding and I/O): Reword to avoid saying
Martin Rudalics <rudalics@gmx.at>
parents:
84116
diff
changeset
|
669 requires to ask the user to specify a coding system, |
c9e81d5cb2e7
(Encoding and I/O): Reword to avoid saying
Martin Rudalics <rudalics@gmx.at>
parents:
84116
diff
changeset
|
670 @code{buffer-file-coding-system} is updated to the newly selected coding |
c9e81d5cb2e7
(Encoding and I/O): Reword to avoid saying
Martin Rudalics <rudalics@gmx.at>
parents:
84116
diff
changeset
|
671 system. |
84090 | 672 |
673 @code{buffer-file-coding-system} does @emph{not} affect sending text | |
674 to a subprocess. | |
675 @end defvar | |
676 | |
677 @defvar save-buffer-coding-system | |
678 This variable specifies the coding system for saving the buffer (by | |
679 overriding @code{buffer-file-coding-system}). Note that it is not used | |
680 for @code{write-region}. | |
681 | |
682 When a command to save the buffer starts out to use | |
683 @code{buffer-file-coding-system} (or @code{save-buffer-coding-system}), | |
684 and that coding system cannot handle | |
685 the actual text in the buffer, the command asks the user to choose | |
686 another coding system (by calling @code{select-safe-coding-system}). | |
687 After that happens, the command also updates | |
688 @code{buffer-file-coding-system} to represent the coding system that | |
689 the user specified. | |
690 @end defvar | |
691 | |
692 @defvar last-coding-system-used | |
693 I/O operations for files and subprocesses set this variable to the | |
694 coding system name that was used. The explicit encoding and decoding | |
695 functions (@pxref{Explicit Encoding}) set it too. | |
696 | |
697 @strong{Warning:} Since receiving subprocess output sets this variable, | |
698 it can change whenever Emacs waits; therefore, you should copy the | |
699 value shortly after the function call that stores the value you are | |
700 interested in. | |
701 @end defvar | |
702 | |
703 The variable @code{selection-coding-system} specifies how to encode | |
704 selections for the window system. @xref{Window System Selections}. | |
705 | |
706 @defvar file-name-coding-system | |
707 The variable @code{file-name-coding-system} specifies the coding | |
708 system to use for encoding file names. Emacs encodes file names using | |
709 that coding system for all file operations. If | |
710 @code{file-name-coding-system} is @code{nil}, Emacs uses a default | |
711 coding system determined by the selected language environment. In the | |
712 default language environment, any non-@acronym{ASCII} characters in | |
713 file names are not encoded specially; they appear in the file system | |
714 using the internal Emacs representation. | |
715 @end defvar | |
716 | |
717 @strong{Warning:} if you change @code{file-name-coding-system} (or | |
718 the language environment) in the middle of an Emacs session, problems | |
719 can result if you have already visited files whose names were encoded | |
720 using the earlier coding system and are handled differently under the | |
721 new coding system. If you try to save one of these buffers under the | |
722 visited file name, saving may use the wrong file name, or it may get | |
723 an error. If such a problem happens, use @kbd{C-x C-w} to specify a | |
724 new file name for that buffer. | |
725 | |
726 @node Lisp and Coding Systems | |
727 @subsection Coding Systems in Lisp | |
728 | |
729 Here are the Lisp facilities for working with coding systems: | |
730 | |
731 @defun coding-system-list &optional base-only | |
732 This function returns a list of all coding system names (symbols). If | |
733 @var{base-only} is non-@code{nil}, the value includes only the | |
734 base coding systems. Otherwise, it includes alias and variant coding | |
735 systems as well. | |
736 @end defun | |
737 | |
738 @defun coding-system-p object | |
739 This function returns @code{t} if @var{object} is a coding system | |
740 name or @code{nil}. | |
741 @end defun | |
742 | |
743 @defun check-coding-system coding-system | |
744 This function checks the validity of @var{coding-system}. | |
745 If that is valid, it returns @var{coding-system}. | |
746 Otherwise it signals an error with condition @code{coding-system-error}. | |
747 @end defun | |
748 | |
749 @defun coding-system-eol-type coding-system | |
750 This function returns the type of end-of-line (a.k.a.@: @dfn{eol}) | |
751 conversion used by @var{coding-system}. If @var{coding-system} | |
752 specifies a certain eol conversion, the return value is an integer 0, | |
753 1, or 2, standing for @code{unix}, @code{dos}, and @code{mac}, | |
754 respectively. If @var{coding-system} doesn't specify eol conversion | |
755 explicitly, the return value is a vector of coding systems, each one | |
756 with one of the possible eol conversion types, like this: | |
757 | |
758 @lisp | |
759 (coding-system-eol-type 'latin-1) | |
760 @result{} [latin-1-unix latin-1-dos latin-1-mac] | |
761 @end lisp | |
762 | |
763 @noindent | |
764 If this function returns a vector, Emacs will decide, as part of the | |
765 text encoding or decoding process, what eol conversion to use. For | |
766 decoding, the end-of-line format of the text is auto-detected, and the | |
767 eol conversion is set to match it (e.g., DOS-style CRLF format will | |
768 imply @code{dos} eol conversion). For encoding, the eol conversion is | |
769 taken from the appropriate default coding system (e.g., | |
770 @code{default-buffer-file-coding-system} for | |
771 @code{buffer-file-coding-system}), or from the default eol conversion | |
772 appropriate for the underlying platform. | |
773 @end defun | |
774 | |
775 @defun coding-system-change-eol-conversion coding-system eol-type | |
776 This function returns a coding system which is like @var{coding-system} | |
777 except for its eol conversion, which is specified by @code{eol-type}. | |
778 @var{eol-type} should be @code{unix}, @code{dos}, @code{mac}, or | |
779 @code{nil}. If it is @code{nil}, the returned coding system determines | |
780 the end-of-line conversion from the data. | |
781 | |
782 @var{eol-type} may also be 0, 1 or 2, standing for @code{unix}, | |
783 @code{dos} and @code{mac}, respectively. | |
784 @end defun | |
785 | |
786 @defun coding-system-change-text-conversion eol-coding text-coding | |
787 This function returns a coding system which uses the end-of-line | |
788 conversion of @var{eol-coding}, and the text conversion of | |
789 @var{text-coding}. If @var{text-coding} is @code{nil}, it returns | |
790 @code{undecided}, or one of its variants according to @var{eol-coding}. | |
791 @end defun | |
792 | |
793 @defun find-coding-systems-region from to | |
794 This function returns a list of coding systems that could be used to | |
795 encode a text between @var{from} and @var{to}. All coding systems in | |
796 the list can safely encode any multibyte characters in that portion of | |
797 the text. | |
798 | |
799 If the text contains no multibyte characters, the function returns the | |
800 list @code{(undecided)}. | |
801 @end defun | |
802 | |
803 @defun find-coding-systems-string string | |
804 This function returns a list of coding systems that could be used to | |
805 encode the text of @var{string}. All coding systems in the list can | |
806 safely encode any multibyte characters in @var{string}. If the text | |
807 contains no multibyte characters, this returns the list | |
808 @code{(undecided)}. | |
809 @end defun | |
810 | |
811 @defun find-coding-systems-for-charsets charsets | |
812 This function returns a list of coding systems that could be used to | |
813 encode all the character sets in the list @var{charsets}. | |
814 @end defun | |
815 | |
816 @defun detect-coding-region start end &optional highest | |
817 This function chooses a plausible coding system for decoding the text | |
818 from @var{start} to @var{end}. This text should be a byte sequence | |
819 (@pxref{Explicit Encoding}). | |
820 | |
821 Normally this function returns a list of coding systems that could | |
822 handle decoding the text that was scanned. They are listed in order of | |
823 decreasing priority. But if @var{highest} is non-@code{nil}, then the | |
824 return value is just one coding system, the one that is highest in | |
825 priority. | |
826 | |
827 If the region contains only @acronym{ASCII} characters except for such | |
828 ISO-2022 control characters ISO-2022 as @code{ESC}, the value is | |
829 @code{undecided} or @code{(undecided)}, or a variant specifying | |
830 end-of-line conversion, if that can be deduced from the text. | |
831 @end defun | |
832 | |
833 @defun detect-coding-string string &optional highest | |
834 This function is like @code{detect-coding-region} except that it | |
835 operates on the contents of @var{string} instead of bytes in the buffer. | |
836 @end defun | |
837 | |
838 @xref{Coding systems for a subprocess,, Process Information}, in | |
839 particular the description of the functions | |
840 @code{process-coding-system} and @code{set-process-coding-system}, for | |
841 how to examine or set the coding systems used for I/O to a subprocess. | |
842 | |
843 @node User-Chosen Coding Systems | |
844 @subsection User-Chosen Coding Systems | |
845 | |
846 @cindex select safe coding system | |
847 @defun select-safe-coding-system from to &optional default-coding-system accept-default-p file | |
848 This function selects a coding system for encoding specified text, | |
849 asking the user to choose if necessary. Normally the specified text | |
850 is the text in the current buffer between @var{from} and @var{to}. If | |
851 @var{from} is a string, the string specifies the text to encode, and | |
852 @var{to} is ignored. | |
853 | |
854 If @var{default-coding-system} is non-@code{nil}, that is the first | |
855 coding system to try; if that can handle the text, | |
856 @code{select-safe-coding-system} returns that coding system. It can | |
857 also be a list of coding systems; then the function tries each of them | |
858 one by one. After trying all of them, it next tries the current | |
859 buffer's value of @code{buffer-file-coding-system} (if it is not | |
860 @code{undecided}), then the value of | |
861 @code{default-buffer-file-coding-system} and finally the user's most | |
862 preferred coding system, which the user can set using the command | |
863 @code{prefer-coding-system} (@pxref{Recognize Coding,, Recognizing | |
864 Coding Systems, emacs, The GNU Emacs Manual}). | |
865 | |
866 If one of those coding systems can safely encode all the specified | |
867 text, @code{select-safe-coding-system} chooses it and returns it. | |
868 Otherwise, it asks the user to choose from a list of coding systems | |
869 which can encode all the text, and returns the user's choice. | |
870 | |
871 @var{default-coding-system} can also be a list whose first element is | |
872 t and whose other elements are coding systems. Then, if no coding | |
873 system in the list can handle the text, @code{select-safe-coding-system} | |
874 queries the user immediately, without trying any of the three | |
875 alternatives described above. | |
876 | |
877 The optional argument @var{accept-default-p}, if non-@code{nil}, | |
878 should be a function to determine whether a coding system selected | |
879 without user interaction is acceptable. @code{select-safe-coding-system} | |
880 calls this function with one argument, the base coding system of the | |
881 selected coding system. If @var{accept-default-p} returns @code{nil}, | |
882 @code{select-safe-coding-system} rejects the silently selected coding | |
883 system, and asks the user to select a coding system from a list of | |
884 possible candidates. | |
885 | |
886 @vindex select-safe-coding-system-accept-default-p | |
887 If the variable @code{select-safe-coding-system-accept-default-p} is | |
888 non-@code{nil}, its value overrides the value of | |
889 @var{accept-default-p}. | |
890 | |
891 As a final step, before returning the chosen coding system, | |
892 @code{select-safe-coding-system} checks whether that coding system is | |
893 consistent with what would be selected if the contents of the region | |
894 were read from a file. (If not, this could lead to data corruption in | |
895 a file subsequently re-visited and edited.) Normally, | |
896 @code{select-safe-coding-system} uses @code{buffer-file-name} as the | |
897 file for this purpose, but if @var{file} is non-@code{nil}, it uses | |
898 that file instead (this can be relevant for @code{write-region} and | |
899 similar functions). If it detects an apparent inconsistency, | |
900 @code{select-safe-coding-system} queries the user before selecting the | |
901 coding system. | |
902 @end defun | |
903 | |
904 Here are two functions you can use to let the user specify a coding | |
905 system, with completion. @xref{Completion}. | |
906 | |
907 @defun read-coding-system prompt &optional default | |
908 This function reads a coding system using the minibuffer, prompting with | |
909 string @var{prompt}, and returns the coding system name as a symbol. If | |
910 the user enters null input, @var{default} specifies which coding system | |
911 to return. It should be a symbol or a string. | |
912 @end defun | |
913 | |
914 @defun read-non-nil-coding-system prompt | |
915 This function reads a coding system using the minibuffer, prompting with | |
916 string @var{prompt}, and returns the coding system name as a symbol. If | |
917 the user tries to enter null input, it asks the user to try again. | |
918 @xref{Coding Systems}. | |
919 @end defun | |
920 | |
921 @node Default Coding Systems | |
922 @subsection Default Coding Systems | |
923 | |
924 This section describes variables that specify the default coding | |
925 system for certain files or when running certain subprograms, and the | |
926 function that I/O operations use to access them. | |
927 | |
928 The idea of these variables is that you set them once and for all to the | |
929 defaults you want, and then do not change them again. To specify a | |
930 particular coding system for a particular operation in a Lisp program, | |
931 don't change these variables; instead, override them using | |
932 @code{coding-system-for-read} and @code{coding-system-for-write} | |
933 (@pxref{Specifying Coding Systems}). | |
934 | |
935 @defvar auto-coding-regexp-alist | |
936 This variable is an alist of text patterns and corresponding coding | |
937 systems. Each element has the form @code{(@var{regexp} | |
938 . @var{coding-system})}; a file whose first few kilobytes match | |
939 @var{regexp} is decoded with @var{coding-system} when its contents are | |
940 read into a buffer. The settings in this alist take priority over | |
941 @code{coding:} tags in the files and the contents of | |
942 @code{file-coding-system-alist} (see below). The default value is set | |
943 so that Emacs automatically recognizes mail files in Babyl format and | |
944 reads them with no code conversions. | |
945 @end defvar | |
946 | |
947 @defvar file-coding-system-alist | |
948 This variable is an alist that specifies the coding systems to use for | |
949 reading and writing particular files. Each element has the form | |
950 @code{(@var{pattern} . @var{coding})}, where @var{pattern} is a regular | |
951 expression that matches certain file names. The element applies to file | |
952 names that match @var{pattern}. | |
953 | |
954 The @sc{cdr} of the element, @var{coding}, should be either a coding | |
955 system, a cons cell containing two coding systems, or a function name (a | |
956 symbol with a function definition). If @var{coding} is a coding system, | |
957 that coding system is used for both reading the file and writing it. If | |
958 @var{coding} is a cons cell containing two coding systems, its @sc{car} | |
959 specifies the coding system for decoding, and its @sc{cdr} specifies the | |
960 coding system for encoding. | |
961 | |
962 If @var{coding} is a function name, the function should take one | |
963 argument, a list of all arguments passed to | |
964 @code{find-operation-coding-system}. It must return a coding system | |
965 or a cons cell containing two coding systems. This value has the same | |
966 meaning as described above. | |
967 | |
968 If @var{coding} (or what returned by the above function) is | |
969 @code{undecided}, the normal code-detection is performed. | |
970 @end defvar | |
971 | |
972 @defvar process-coding-system-alist | |
973 This variable is an alist specifying which coding systems to use for a | |
974 subprocess, depending on which program is running in the subprocess. It | |
975 works like @code{file-coding-system-alist}, except that @var{pattern} is | |
976 matched against the program name used to start the subprocess. The coding | |
977 system or systems specified in this alist are used to initialize the | |
978 coding systems used for I/O to the subprocess, but you can specify | |
979 other coding systems later using @code{set-process-coding-system}. | |
980 @end defvar | |
981 | |
982 @strong{Warning:} Coding systems such as @code{undecided}, which | |
983 determine the coding system from the data, do not work entirely reliably | |
984 with asynchronous subprocess output. This is because Emacs handles | |
985 asynchronous subprocess output in batches, as it arrives. If the coding | |
986 system leaves the character code conversion unspecified, or leaves the | |
987 end-of-line conversion unspecified, Emacs must try to detect the proper | |
988 conversion from one batch at a time, and this does not always work. | |
989 | |
990 Therefore, with an asynchronous subprocess, if at all possible, use a | |
991 coding system which determines both the character code conversion and | |
992 the end of line conversion---that is, one like @code{latin-1-unix}, | |
993 rather than @code{undecided} or @code{latin-1}. | |
994 | |
995 @defvar network-coding-system-alist | |
996 This variable is an alist that specifies the coding system to use for | |
997 network streams. It works much like @code{file-coding-system-alist}, | |
998 with the difference that the @var{pattern} in an element may be either a | |
999 port number or a regular expression. If it is a regular expression, it | |
1000 is matched against the network service name used to open the network | |
1001 stream. | |
1002 @end defvar | |
1003 | |
1004 @defvar default-process-coding-system | |
1005 This variable specifies the coding systems to use for subprocess (and | |
1006 network stream) input and output, when nothing else specifies what to | |
1007 do. | |
1008 | |
1009 The value should be a cons cell of the form @code{(@var{input-coding} | |
1010 . @var{output-coding})}. Here @var{input-coding} applies to input from | |
1011 the subprocess, and @var{output-coding} applies to output to it. | |
1012 @end defvar | |
1013 | |
1014 @defvar auto-coding-functions | |
1015 This variable holds a list of functions that try to determine a | |
1016 coding system for a file based on its undecoded contents. | |
1017 | |
1018 Each function in this list should be written to look at text in the | |
1019 current buffer, but should not modify it in any way. The buffer will | |
1020 contain undecoded text of parts of the file. Each function should | |
1021 take one argument, @var{size}, which tells it how many characters to | |
1022 look at, starting from point. If the function succeeds in determining | |
1023 a coding system for the file, it should return that coding system. | |
1024 Otherwise, it should return @code{nil}. | |
1025 | |
1026 If a file has a @samp{coding:} tag, that takes precedence, so these | |
1027 functions won't be called. | |
1028 @end defvar | |
1029 | |
1030 @defun find-operation-coding-system operation &rest arguments | |
1031 This function returns the coding system to use (by default) for | |
1032 performing @var{operation} with @var{arguments}. The value has this | |
1033 form: | |
1034 | |
1035 @example | |
1036 (@var{decoding-system} . @var{encoding-system}) | |
1037 @end example | |
1038 | |
1039 The first element, @var{decoding-system}, is the coding system to use | |
1040 for decoding (in case @var{operation} does decoding), and | |
1041 @var{encoding-system} is the coding system for encoding (in case | |
1042 @var{operation} does encoding). | |
1043 | |
1044 The argument @var{operation} is a symbol, one of @code{write-region}, | |
1045 @code{start-process}, @code{call-process}, @code{call-process-region}, | |
1046 @code{insert-file-contents}, or @code{open-network-stream}. These are | |
1047 the names of the Emacs I/O primitives that can do character code and | |
1048 eol conversion. | |
1049 | |
1050 The remaining arguments should be the same arguments that might be given | |
1051 to the corresponding I/O primitive. Depending on the primitive, one | |
1052 of those arguments is selected as the @dfn{target}. For example, if | |
1053 @var{operation} does file I/O, whichever argument specifies the file | |
1054 name is the target. For subprocess primitives, the process name is the | |
1055 target. For @code{open-network-stream}, the target is the service name | |
1056 or port number. | |
1057 | |
1058 Depending on @var{operation}, this function looks up the target in | |
1059 @code{file-coding-system-alist}, @code{process-coding-system-alist}, | |
1060 or @code{network-coding-system-alist}. If the target is found in the | |
1061 alist, @code{find-operation-coding-system} returns its association in | |
1062 the alist; otherwise it returns @code{nil}. | |
1063 | |
1064 If @var{operation} is @code{insert-file-contents}, the argument | |
1065 corresponding to the target may be a cons cell of the form | |
1066 @code{(@var{filename} . @var{buffer})}). In that case, @var{filename} | |
1067 is a file name to look up in @code{file-coding-system-alist}, and | |
1068 @var{buffer} is a buffer that contains the file's contents (not yet | |
1069 decoded). If @code{file-coding-system-alist} specifies a function to | |
1070 call for this file, and that function needs to examine the file's | |
1071 contents (as it usually does), it should examine the contents of | |
1072 @var{buffer} instead of reading the file. | |
1073 @end defun | |
1074 | |
1075 @node Specifying Coding Systems | |
1076 @subsection Specifying a Coding System for One Operation | |
1077 | |
1078 You can specify the coding system for a specific operation by binding | |
1079 the variables @code{coding-system-for-read} and/or | |
1080 @code{coding-system-for-write}. | |
1081 | |
1082 @defvar coding-system-for-read | |
1083 If this variable is non-@code{nil}, it specifies the coding system to | |
1084 use for reading a file, or for input from a synchronous subprocess. | |
1085 | |
1086 It also applies to any asynchronous subprocess or network stream, but in | |
1087 a different way: the value of @code{coding-system-for-read} when you | |
1088 start the subprocess or open the network stream specifies the input | |
1089 decoding method for that subprocess or network stream. It remains in | |
1090 use for that subprocess or network stream unless and until overridden. | |
1091 | |
1092 The right way to use this variable is to bind it with @code{let} for a | |
1093 specific I/O operation. Its global value is normally @code{nil}, and | |
1094 you should not globally set it to any other value. Here is an example | |
1095 of the right way to use the variable: | |
1096 | |
1097 @example | |
1098 ;; @r{Read the file with no character code conversion.} | |
1099 ;; @r{Assume @acronym{crlf} represents end-of-line.} | |
1100 (let ((coding-system-for-read 'emacs-mule-dos)) | |
1101 (insert-file-contents filename)) | |
1102 @end example | |
1103 | |
1104 When its value is non-@code{nil}, this variable takes precedence over | |
1105 all other methods of specifying a coding system to use for input, | |
1106 including @code{file-coding-system-alist}, | |
1107 @code{process-coding-system-alist} and | |
1108 @code{network-coding-system-alist}. | |
1109 @end defvar | |
1110 | |
1111 @defvar coding-system-for-write | |
1112 This works much like @code{coding-system-for-read}, except that it | |
1113 applies to output rather than input. It affects writing to files, | |
1114 as well as sending output to subprocesses and net connections. | |
1115 | |
1116 When a single operation does both input and output, as do | |
1117 @code{call-process-region} and @code{start-process}, both | |
1118 @code{coding-system-for-read} and @code{coding-system-for-write} | |
1119 affect it. | |
1120 @end defvar | |
1121 | |
1122 @defvar inhibit-eol-conversion | |
1123 When this variable is non-@code{nil}, no end-of-line conversion is done, | |
1124 no matter which coding system is specified. This applies to all the | |
1125 Emacs I/O and subprocess primitives, and to the explicit encoding and | |
1126 decoding functions (@pxref{Explicit Encoding}). | |
1127 @end defvar | |
1128 | |
1129 @node Explicit Encoding | |
1130 @subsection Explicit Encoding and Decoding | |
1131 @cindex encoding in coding systems | |
1132 @cindex decoding in coding systems | |
1133 | |
1134 All the operations that transfer text in and out of Emacs have the | |
1135 ability to use a coding system to encode or decode the text. | |
1136 You can also explicitly encode and decode text using the functions | |
1137 in this section. | |
1138 | |
1139 The result of encoding, and the input to decoding, are not ordinary | |
1140 text. They logically consist of a series of byte values; that is, a | |
1141 series of characters whose codes are in the range 0 through 255. In a | |
1142 multibyte buffer or string, character codes 128 through 159 are | |
1143 represented by multibyte sequences, but this is invisible to Lisp | |
1144 programs. | |
1145 | |
1146 The usual way to read a file into a buffer as a sequence of bytes, so | |
1147 you can decode the contents explicitly, is with | |
1148 @code{insert-file-contents-literally} (@pxref{Reading from Files}); | |
1149 alternatively, specify a non-@code{nil} @var{rawfile} argument when | |
1150 visiting a file with @code{find-file-noselect}. These methods result in | |
1151 a unibyte buffer. | |
1152 | |
1153 The usual way to use the byte sequence that results from explicitly | |
1154 encoding text is to copy it to a file or process---for example, to write | |
1155 it with @code{write-region} (@pxref{Writing to Files}), and suppress | |
1156 encoding by binding @code{coding-system-for-write} to | |
1157 @code{no-conversion}. | |
1158 | |
1159 Here are the functions to perform explicit encoding or decoding. The | |
1160 encoding functions produce sequences of bytes; the decoding functions | |
1161 are meant to operate on sequences of bytes. All of these functions | |
1162 discard text properties. | |
1163 | |
1164 @deffn Command encode-coding-region start end coding-system | |
1165 This command encodes the text from @var{start} to @var{end} according | |
1166 to coding system @var{coding-system}. The encoded text replaces the | |
1167 original text in the buffer. The result of encoding is logically a | |
1168 sequence of bytes, but the buffer remains multibyte if it was multibyte | |
1169 before. | |
1170 | |
1171 This command returns the length of the encoded text. | |
1172 @end deffn | |
1173 | |
1174 @defun encode-coding-string string coding-system &optional nocopy | |
1175 This function encodes the text in @var{string} according to coding | |
1176 system @var{coding-system}. It returns a new string containing the | |
1177 encoded text, except when @var{nocopy} is non-@code{nil}, in which | |
1178 case the function may return @var{string} itself if the encoding | |
1179 operation is trivial. The result of encoding is a unibyte string. | |
1180 @end defun | |
1181 | |
1182 @deffn Command decode-coding-region start end coding-system | |
1183 This command decodes the text from @var{start} to @var{end} according | |
1184 to coding system @var{coding-system}. The decoded text replaces the | |
1185 original text in the buffer. To make explicit decoding useful, the text | |
1186 before decoding ought to be a sequence of byte values, but both | |
1187 multibyte and unibyte buffers are acceptable. | |
1188 | |
1189 This command returns the length of the decoded text. | |
1190 @end deffn | |
1191 | |
1192 @defun decode-coding-string string coding-system &optional nocopy | |
1193 This function decodes the text in @var{string} according to coding | |
1194 system @var{coding-system}. It returns a new string containing the | |
1195 decoded text, except when @var{nocopy} is non-@code{nil}, in which | |
1196 case the function may return @var{string} itself if the decoding | |
1197 operation is trivial. To make explicit decoding useful, the contents | |
1198 of @var{string} ought to be a sequence of byte values, but a multibyte | |
1199 string is acceptable. | |
1200 @end defun | |
1201 | |
1202 @defun decode-coding-inserted-region from to filename &optional visit beg end replace | |
1203 This function decodes the text from @var{from} to @var{to} as if | |
1204 it were being read from file @var{filename} using @code{insert-file-contents} | |
1205 using the rest of the arguments provided. | |
1206 | |
1207 The normal way to use this function is after reading text from a file | |
1208 without decoding, if you decide you would rather have decoded it. | |
1209 Instead of deleting the text and reading it again, this time with | |
1210 decoding, you can call this function. | |
1211 @end defun | |
1212 | |
1213 @node Terminal I/O Encoding | |
1214 @subsection Terminal I/O Encoding | |
1215 | |
1216 Emacs can decode keyboard input using a coding system, and encode | |
1217 terminal output. This is useful for terminals that transmit or display | |
1218 text using a particular encoding such as Latin-1. Emacs does not set | |
1219 @code{last-coding-system-used} for encoding or decoding for the | |
1220 terminal. | |
1221 | |
1222 @defun keyboard-coding-system | |
1223 This function returns the coding system that is in use for decoding | |
1224 keyboard input---or @code{nil} if no coding system is to be used. | |
1225 @end defun | |
1226 | |
1227 @deffn Command set-keyboard-coding-system coding-system | |
1228 This command specifies @var{coding-system} as the coding system to | |
1229 use for decoding keyboard input. If @var{coding-system} is @code{nil}, | |
1230 that means do not decode keyboard input. | |
1231 @end deffn | |
1232 | |
1233 @defun terminal-coding-system | |
1234 This function returns the coding system that is in use for encoding | |
1235 terminal output---or @code{nil} for no encoding. | |
1236 @end defun | |
1237 | |
1238 @deffn Command set-terminal-coding-system coding-system | |
1239 This command specifies @var{coding-system} as the coding system to use | |
1240 for encoding terminal output. If @var{coding-system} is @code{nil}, | |
1241 that means do not encode terminal output. | |
1242 @end deffn | |
1243 | |
1244 @node MS-DOS File Types | |
1245 @subsection MS-DOS File Types | |
1246 @cindex DOS file types | |
1247 @cindex MS-DOS file types | |
1248 @cindex Windows file types | |
1249 @cindex file types on MS-DOS and Windows | |
1250 @cindex text files and binary files | |
1251 @cindex binary files and text files | |
1252 | |
1253 On MS-DOS and Microsoft Windows, Emacs guesses the appropriate | |
1254 end-of-line conversion for a file by looking at the file's name. This | |
1255 feature classifies files as @dfn{text files} and @dfn{binary files}. By | |
1256 ``binary file'' we mean a file of literal byte values that are not | |
1257 necessarily meant to be characters; Emacs does no end-of-line conversion | |
1258 and no character code conversion for them. On the other hand, the bytes | |
1259 in a text file are intended to represent characters; when you create a | |
1260 new file whose name implies that it is a text file, Emacs uses DOS | |
1261 end-of-line conversion. | |
1262 | |
1263 @defvar buffer-file-type | |
1264 This variable, automatically buffer-local in each buffer, records the | |
1265 file type of the buffer's visited file. When a buffer does not specify | |
1266 a coding system with @code{buffer-file-coding-system}, this variable is | |
1267 used to determine which coding system to use when writing the contents | |
1268 of the buffer. It should be @code{nil} for text, @code{t} for binary. | |
1269 If it is @code{t}, the coding system is @code{no-conversion}. | |
1270 Otherwise, @code{undecided-dos} is used. | |
1271 | |
1272 Normally this variable is set by visiting a file; it is set to | |
1273 @code{nil} if the file was visited without any actual conversion. | |
1274 @end defvar | |
1275 | |
1276 @defopt file-name-buffer-file-type-alist | |
1277 This variable holds an alist for recognizing text and binary files. | |
1278 Each element has the form (@var{regexp} . @var{type}), where | |
1279 @var{regexp} is matched against the file name, and @var{type} may be | |
1280 @code{nil} for text, @code{t} for binary, or a function to call to | |
1281 compute which. If it is a function, then it is called with a single | |
1282 argument (the file name) and should return @code{t} or @code{nil}. | |
1283 | |
1284 When running on MS-DOS or MS-Windows, Emacs checks this alist to decide | |
1285 which coding system to use when reading a file. For a text file, | |
1286 @code{undecided-dos} is used. For a binary file, @code{no-conversion} | |
1287 is used. | |
1288 | |
1289 If no element in this alist matches a given file name, then | |
1290 @code{default-buffer-file-type} says how to treat the file. | |
1291 @end defopt | |
1292 | |
1293 @defopt default-buffer-file-type | |
1294 This variable says how to handle files for which | |
1295 @code{file-name-buffer-file-type-alist} says nothing about the type. | |
1296 | |
1297 If this variable is non-@code{nil}, then these files are treated as | |
1298 binary: the coding system @code{no-conversion} is used. Otherwise, | |
1299 nothing special is done for them---the coding system is deduced solely | |
1300 from the file contents, in the usual Emacs fashion. | |
1301 @end defopt | |
1302 | |
1303 @node Input Methods | |
1304 @section Input Methods | |
1305 @cindex input methods | |
1306 | |
1307 @dfn{Input methods} provide convenient ways of entering non-@acronym{ASCII} | |
1308 characters from the keyboard. Unlike coding systems, which translate | |
1309 non-@acronym{ASCII} characters to and from encodings meant to be read by | |
1310 programs, input methods provide human-friendly commands. (@xref{Input | |
1311 Methods,,, emacs, The GNU Emacs Manual}, for information on how users | |
1312 use input methods to enter text.) How to define input methods is not | |
1313 yet documented in this manual, but here we describe how to use them. | |
1314 | |
1315 Each input method has a name, which is currently a string; | |
1316 in the future, symbols may also be usable as input method names. | |
1317 | |
1318 @defvar current-input-method | |
1319 This variable holds the name of the input method now active in the | |
1320 current buffer. (It automatically becomes local in each buffer when set | |
1321 in any fashion.) It is @code{nil} if no input method is active in the | |
1322 buffer now. | |
1323 @end defvar | |
1324 | |
1325 @defopt default-input-method | |
1326 This variable holds the default input method for commands that choose an | |
1327 input method. Unlike @code{current-input-method}, this variable is | |
1328 normally global. | |
1329 @end defopt | |
1330 | |
1331 @deffn Command set-input-method input-method | |
1332 This command activates input method @var{input-method} for the current | |
1333 buffer. It also sets @code{default-input-method} to @var{input-method}. | |
1334 If @var{input-method} is @code{nil}, this command deactivates any input | |
1335 method for the current buffer. | |
1336 @end deffn | |
1337 | |
1338 @defun read-input-method-name prompt &optional default inhibit-null | |
1339 This function reads an input method name with the minibuffer, prompting | |
1340 with @var{prompt}. If @var{default} is non-@code{nil}, that is returned | |
1341 by default, if the user enters empty input. However, if | |
1342 @var{inhibit-null} is non-@code{nil}, empty input signals an error. | |
1343 | |
1344 The returned value is a string. | |
1345 @end defun | |
1346 | |
1347 @defvar input-method-alist | |
1348 This variable defines all the supported input methods. | |
1349 Each element defines one input method, and should have the form: | |
1350 | |
1351 @example | |
1352 (@var{input-method} @var{language-env} @var{activate-func} | |
1353 @var{title} @var{description} @var{args}...) | |
1354 @end example | |
1355 | |
1356 Here @var{input-method} is the input method name, a string; | |
1357 @var{language-env} is another string, the name of the language | |
1358 environment this input method is recommended for. (That serves only for | |
1359 documentation purposes.) | |
1360 | |
1361 @var{activate-func} is a function to call to activate this method. The | |
1362 @var{args}, if any, are passed as arguments to @var{activate-func}. All | |
1363 told, the arguments to @var{activate-func} are @var{input-method} and | |
1364 the @var{args}. | |
1365 | |
1366 @var{title} is a string to display in the mode line while this method is | |
1367 active. @var{description} is a string describing this method and what | |
1368 it is good for. | |
1369 @end defvar | |
1370 | |
1371 The fundamental interface to input methods is through the | |
1372 variable @code{input-method-function}. @xref{Reading One Event}, | |
1373 and @ref{Invoking the Input Method}. | |
1374 | |
1375 @node Locales | |
1376 @section Locales | |
1377 @cindex locale | |
1378 | |
1379 POSIX defines a concept of ``locales'' which control which language | |
1380 to use in language-related features. These Emacs variables control | |
1381 how Emacs interacts with these features. | |
1382 | |
1383 @defvar locale-coding-system | |
1384 @cindex keyboard input decoding on X | |
1385 This variable specifies the coding system to use for decoding system | |
1386 error messages and---on X Window system only---keyboard input, for | |
1387 encoding the format argument to @code{format-time-string}, and for | |
1388 decoding the return value of @code{format-time-string}. | |
1389 @end defvar | |
1390 | |
1391 @defvar system-messages-locale | |
1392 This variable specifies the locale to use for generating system error | |
1393 messages. Changing the locale can cause messages to come out in a | |
1394 different language or in a different orthography. If the variable is | |
1395 @code{nil}, the locale is specified by environment variables in the | |
1396 usual POSIX fashion. | |
1397 @end defvar | |
1398 | |
1399 @defvar system-time-locale | |
1400 This variable specifies the locale to use for formatting time values. | |
1401 Changing the locale can cause messages to appear according to the | |
1402 conventions of a different language. If the variable is @code{nil}, the | |
1403 locale is specified by environment variables in the usual POSIX fashion. | |
1404 @end defvar | |
1405 | |
1406 @defun locale-info item | |
1407 This function returns locale data @var{item} for the current POSIX | |
1408 locale, if available. @var{item} should be one of these symbols: | |
1409 | |
1410 @table @code | |
1411 @item codeset | |
1412 Return the character set as a string (locale item @code{CODESET}). | |
1413 | |
1414 @item days | |
1415 Return a 7-element vector of day names (locale items | |
1416 @code{DAY_1} through @code{DAY_7}); | |
1417 | |
1418 @item months | |
1419 Return a 12-element vector of month names (locale items @code{MON_1} | |
1420 through @code{MON_12}). | |
1421 | |
1422 @item paper | |
1423 Return a list @code{(@var{width} @var{height})} for the default paper | |
1424 size measured in millimeters (locale items @code{PAPER_WIDTH} and | |
1425 @code{PAPER_HEIGHT}). | |
1426 @end table | |
1427 | |
1428 If the system can't provide the requested information, or if | |
1429 @var{item} is not one of those symbols, the value is @code{nil}. All | |
1430 strings in the return value are decoded using | |
1431 @code{locale-coding-system}. @xref{Locales,,, libc, The GNU Libc Manual}, | |
1432 for more information about locales and locale items. | |
1433 @end defun | |
1434 | |
1435 @ignore | |
1436 arch-tag: be705bf8-941b-4c35-84fc-ad7d20ddb7cb | |
1437 @end ignore |