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