annotate lispref/nonascii.texi @ 21603:058bff729a94

(HAVE_STRING_H, HAVE_STRFTIME): Define macros. (SYSTEM_PURESIZE_EXTRA): Increase to handle more dumped lisp files.
author Geoff Voelker <voelker@cs.washington.edu>
date Fri, 17 Apr 1998 05:06:20 +0000
parents 00022857f529
children 90da2489c498
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21006
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 @c -*-texinfo-*-
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 @c This is part of the GNU Emacs Lisp Reference Manual.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 @c Copyright (C) 1998 Free Software Foundation, Inc.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 @c See the file elisp.texi for copying conditions.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 @setfilename ../info/characters
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 @node Non-ASCII Characters, Searching and Matching, Text, Top
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 @chapter Non-ASCII Characters
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 @cindex multibyte characters
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 @cindex non-ASCII characters
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 This chapter covers the special issues relating to non-@sc{ASCII}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 characters and how they are stored in strings and buffers.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 @menu
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 * Text Representations::
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 * Converting Representations::
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 * Selecting a Representation::
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 * Character Codes::
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 * Character Sets::
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 * Scanning Charsets::
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 * Chars and Bytes::
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 * Coding Systems::
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 * Default Coding Systems::
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 * Specifying Coding Systems::
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 * Explicit Encoding::
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 @end menu
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 @node Text Representations
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 @section Text Representations
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 @cindex text representations
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 Emacs has two @dfn{text representations}---two ways to represent text
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 in a string or buffer. These are called @dfn{unibyte} and
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 @dfn{multibyte}. Each string, and each buffer, uses one of these two
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 representations. For most purposes, you can ignore the issue of
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 representations, because Emacs converts text between them as
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 appropriate. Occasionally in Lisp programming you will need to pay
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 attention to the difference.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 @cindex unibyte text
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 In unibyte representation, each character occupies one byte and
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 therefore the possible character codes range from 0 to 255. Codes 0
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 through 127 are @sc{ASCII} characters; the codes from 128 through 255
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 are used for one non-@sc{ASCII} character set (you can choose which one
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 by setting the variable @code{nonascii-insert-offset}).
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 @cindex leading code
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 @cindex multibyte text
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 In multibyte representation, a character may occupy more than one
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 byte, and as a result, the full range of Emacs character codes can be
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 stored. The first byte of a multibyte character is always in the range
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 128 through 159 (octal 0200 through 0237). These values are called
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 @dfn{leading codes}. The first byte determines which character set the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 character belongs to (@pxref{Character Sets}); in particular, it
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 determines how many bytes long the sequence is. The second and
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 subsequent bytes of a multibyte character are always in the range 160
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 through 255 (octal 0240 through 0377).
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 In a buffer, the buffer-local value of the variable
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 @code{enable-multibyte-characters} specifies the representation used.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 The representation for a string is determined based on the string
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 contents when the string is constructed.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 @tindex enable-multibyte-characters
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 @defvar enable-multibyte-characters
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 This variable specifies the current buffer's text representation.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 If it is non-@code{nil}, the buffer contains multibyte text; otherwise,
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 it contains unibyte text.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 @strong{Warning:} do not set this variable directly; instead, use the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 function @code{set-buffer-multibyte} to change a buffer's
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 representation.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 @end defvar
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 @tindex default-enable-multibyte-characters
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 @defvar default-enable-multibyte-characters
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 This variable`s value is entirely equivalent to @code{(default-value
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 'enable-multibyte-characters)}, and setting this variable changes that
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 default value. Although setting the local binding of
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 @code{enable-multibyte-characters} in a specific buffer is dangerous,
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 changing the default value is safe, and it is a reasonable thing to do.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 The @samp{--unibyte} command line option does its job by setting the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 default value to @code{nil} early in startup.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 @end defvar
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 @tindex multibyte-string-p
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 @defun multibyte-string-p string
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 Return @code{t} if @var{string} contains multibyte characters.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 @node Converting Representations
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 @section Converting Text Representations
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 Emacs can convert unibyte text to multibyte; it can also convert
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 multibyte text to unibyte, though this conversion loses information. In
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 general these conversions happen when inserting text into a buffer, or
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 when putting text from several strings together in one string. You can
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 also explicitly convert a string's contents to either representation.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 Emacs chooses the representation for a string based on the text that
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 it is constructed from. The general rule is to convert unibyte text to
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 multibyte text when combining it with other multibyte text, because the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 multibyte representation is more general and can hold whatever
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 characters the unibyte text has.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 When inserting text into a buffer, Emacs converts the text to the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 buffer's representation, as specified by
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 @code{enable-multibyte-characters} in that buffer. In particular, when
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 you insert multibyte text into a unibyte buffer, Emacs converts the text
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 to unibyte, even though this conversion cannot in general preserve all
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 the characters that might be in the multibyte text. The other natural
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 alternative, to convert the buffer contents to multibyte, is not
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 acceptable because the buffer's representation is a choice made by the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 user that cannot simply be overrided.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 Converting unibyte text to multibyte text leaves @sc{ASCII} characters
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 unchanged. It converts the non-@sc{ASCII} codes 128 through 255 by
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 adding the value @code{nonascii-insert-offset} to each character code.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 By setting this variable, you specify which character set the unibyte
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 characters correspond to. For example, if @code{nonascii-insert-offset}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 is 2048, which is @code{(- (make-char 'latin-iso8859-1 0) 128)}, then
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 the unibyte non-@sc{ASCII} characters correspond to Latin 1. If it is
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 2688, which is @code{(- (make-char 'greek-iso8859-7 0) 128)}, then they
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 correspond to Greek letters.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 Converting multibyte text to unibyte is simpler: it performs
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 logical-and of each character code with 255. If
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 @code{nonascii-insert-offset} has a reasonable value, corresponding to
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 the beginning of some character set, this conversion is the inverse of
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 the other: converting unibyte text to multibyte and back to unibyte
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 reproduces the original unibyte text.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 @tindex nonascii-insert-offset
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 @defvar nonascii-insert-offset
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 This variable specifies the amount to add to a non-@sc{ASCII} character
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 when converting unibyte text to multibyte. It also applies when
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 @code{insert-char} or @code{self-insert-command} inserts a character in
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 the unibyte non-@sc{ASCII} range, 128 through 255.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 The right value to use to select character set @var{cs} is @code{(-
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (make-char @var{cs} 0) 128)}. If the value of
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 @code{nonascii-insert-offset} is zero, then conversion actually uses the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 value for the Latin 1 character set, rather than zero.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 @end defvar
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 @tindex nonascii-translate-table
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 @defvar nonascii-translate-table
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 This variable provides a more general alternative to
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 @code{nonascii-insert-offset}. You can use it to specify independently
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 how to translate each code in the range of 128 through 255 into a
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 multibyte character. The value should be a vector, or @code{nil}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 @end defvar
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 @tindex string-make-unibyte
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 @defun string-make-unibyte string
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 This function converts the text of @var{string} to unibyte
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 representation, if it isn't already, and return the result. If
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 conversion does not change the contents, the value may be @var{string}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 itself.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 @tindex string-make-multibyte
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 @defun string-make-multibyte string
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 This function converts the text of @var{string} to multibyte
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 representation, if it isn't already, and return the result. If
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 conversion does not change the contents, the value may be @var{string}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 itself.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 @node Selecting a Representation
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 @section Selecting a Representation
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 Sometimes it is useful to examine an existing buffer or string as
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 multibyte when it was unibyte, or vice versa.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 @tindex set-buffer-multibyte
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 @defun set-buffer-multibyte multibyte
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 Set the representation type of the current buffer. If @var{multibyte}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 is non-@code{nil}, the buffer becomes multibyte. If @var{multibyte}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 is @code{nil}, the buffer becomes unibyte.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 This function leaves the buffer contents unchanged when viewed as a
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 sequence of bytes. As a consequence, it can change the contents viewed
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 as characters; a sequence of two bytes which is treated as one character
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 in multibyte representation will count as two characters in unibyte
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 representation.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 This function sets @code{enable-multibyte-characters} to record which
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 representation is in use. It also adjusts various data in the buffer
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (including its overlays, text properties and markers) so that they
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 cover or fall between the same text as they did before.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 @tindex string-as-unibyte
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 @defun string-as-unibyte string
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 This function returns a string with the same bytes as @var{string} but
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 treating each byte as a character. This means that the value may have
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 more characters than @var{string} has.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 If @var{string} is unibyte already, then the value may be @var{string}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 itself.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 @tindex string-as-multibyte
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 @defun string-as-multibyte string
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 This function returns a string with the same bytes as @var{string} but
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 treating each multibyte sequence as one character. This means that the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 value may have fewer characters than @var{string} has.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 If @var{string} is multibyte already, then the value may be @var{string}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 itself.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 @node Character Codes
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 @section Character Codes
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 @cindex character codes
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 The unibyte and multibyte text representations use different character
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 codes. The valid character codes for unibyte representation range from
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 0 to 255---the values that can fit in one byte. The valid character
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 codes for multibyte representation range from 0 to 524287, but not all
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 values in that range are valid. In particular, the values 128 through
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 255 are not valid in multibyte text. Only the @sc{ASCII} codes 0
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 through 127 are used in both representations.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 @defun char-valid-p charcode
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 This returns @code{t} if @var{charcode} is valid for either one of the two
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 text representations.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 @example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (char-valid-p 65)
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 @result{} t
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (char-valid-p 256)
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 @result{} nil
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (char-valid-p 2248)
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 @result{} t
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 @end example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 @node Character Sets
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 @section Character Sets
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 @cindex character sets
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 Emacs classifies characters into various @dfn{character sets}, each of
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 which has a name which is a symbol. Each character belongs to one and
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 only one character set.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 In general, there is one character set for each distinct script. For
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 example, @code{latin-iso8859-1} is one character set,
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 @code{greek-iso8859-7} is another, and @code{ascii} is another. An
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 Emacs character set can hold at most 9025 characters; therefore. in some
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 cases, a set of characters that would logically be grouped together are
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 split into several character sets. For example, one set of Chinese
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 characters is divided into eight Emacs character sets,
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 @code{chinese-cns11643-1} through @code{chinese-cns11643-7}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 @tindex charsetp
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 @defun charsetp object
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 Return @code{t} if @var{object} is a character set name symbol,
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 @code{nil} otherwise.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 @tindex charset-list
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 @defun charset-list
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 This function returns a list of all defined character set names.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 @tindex char-charset
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 @defun char-charset character
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 This function returns the the name of the character
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 set that @var{character} belongs to.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 @node Scanning Charsets
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 @section Scanning for Character Sets
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 Sometimes it is useful to find out which character sets appear in a
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 part of a buffer or a string. One use for this is in determining which
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 coding systems (@pxref{Coding Systems}) are capable of representing all
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 of the text in question.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 @tindex find-charset-region
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 @defun find-charset-region beg end &optional unification
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 This function returns a list of the character sets
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 that appear in the current buffer between positions @var{beg}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 and @var{end}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 @tindex find-charset-string
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 @defun find-charset-string string &optional unification
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 This function returns a list of the character sets
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 that appear in the string @var{string}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 @node Chars and Bytes
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 @section Characters and Bytes
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 @cindex bytes and characters
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 In multibyte representation, each character occupies one or more
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 bytes. The functions in this section convert between characters and the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 byte values used to represent them.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 @tindex char-bytes
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 @defun char-bytes character
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 This function returns the number of bytes used to represent the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 character @var{character}. In most cases, this is the same as
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 @code{(length (split-char @var{character}))}; the only exception is for
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 ASCII characters, which use just one byte.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 @example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (char-bytes 2248)
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 @result{} 2
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (char-bytes 65)
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 @result{} 1
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 @end example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 This function's values are correct for both multibyte and unibyte
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 representations, because the non-@sc{ASCII} character codes used in
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 those two representations do not overlap.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 @example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (char-bytes 192)
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 @result{} 1
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 @end example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 @tindex split-char
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 @defun split-char character
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 Return a list containing the name of the character set of
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 @var{character}, followed by one or two byte-values which identify
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 @var{character} within that character set.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 @example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (split-char 2248)
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 @result{} (latin-iso8859-1 72)
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (split-char 65)
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 @result{} (ascii 65)
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 @end example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 Unibyte non-@sc{ASCII} characters are considered as part of
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 the @code{ascii} character set:
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 @example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (split-char 192)
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 @result{} (ascii 192)
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 @end example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 @tindex make-char
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 @defun make-char charset &rest byte-values
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 Thus function returns the character in character set @var{charset}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 identified by @var{byte-values}. This is roughly the opposite of
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 split-char.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 @example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (make-char 'latin-iso8859-1 72)
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 @result{} 2248
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 @end example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 @node Coding Systems
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 @section Coding Systems
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 @cindex coding system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 When Emacs reads or writes a file, and when Emacs sends text to a
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 subprocess or receives text from a subprocess, it normally performs
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 character code conversion and end-of-line conversion as specified
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 by a particular @dfn{coding system}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 @cindex character code conversion
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 @dfn{Character code conversion} involves conversion between the encoding
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 used inside Emacs and some other encoding. Emacs supports many
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 different encodings, in that it can convert to and from them. For
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 example, it can convert text to or from encodings such as Latin 1, Latin
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 2, Latin 3, Latin 4, Latin 5, and several variants of ISO 2022. In some
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 cases, Emacs supports several alternative encodings for the same
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 characters; for example, there are three coding systems for the Cyrillic
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (Russian) alphabet: ISO, Alternativnyj, and KOI8.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 @cindex end of line conversion
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 @dfn{End of line conversion} handles three different conventions used
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 on various systems for end of line. The Unix convention is to use the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 linefeed character (also called newline). The DOS convention is to use
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 the two character sequence, carriage-return linefeed, at the end of a
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 line. The Mac convention is to use just carriage-return.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 Most coding systems specify a particular character code for
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 conversion, but some of them leave this unspecified---to be chosen
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 heuristically based on the data.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 @cindex base coding system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 @cindex variant coding system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 @dfn{Base coding systems} such as @code{latin-1} leave the end-of-line
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 conversion unspecified, to be chosen based on the data. @dfn{Variant
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 coding systems} such as @code{latin-1-unix}, @code{latin-1-dos} and
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 @code{latin-1-mac} specify the end-of-line conversion explicitly as
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 well. Each base coding system has three corresponding variants whose
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 names are formed by adding @samp{-unix}, @samp{-dos} and @samp{-mac}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 Here are Lisp facilities for working with coding systems;
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 @tindex coding-system-list
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 @defun coding-system-list &optional base-only
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 This function returns a list of all coding system names (symbols). If
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 @var{base-only} is non-@code{nil}, the value includes only the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 base coding systems. Otherwise, it includes variant coding systems as well.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 @tindex coding-system-p
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 @defun coding-system-p object
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 This function returns @code{t} if @var{object} is a coding system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 name.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 @tindex check-coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 @defun check-coding-system coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 This function checks the validity of @var{coding-system}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 If that is valid, it returns @var{coding-system}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 Otherwise it signals an error with condition @code{coding-system-error}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 @tindex detect-coding-region
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 @defun detect-coding-region start end highest
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 This function chooses a plausible coding system for decoding the text
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 from @var{start} to @var{end}. This text should be ``raw bytes''
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (@pxref{Specifying Coding Systems}).
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 Normally this function returns is a list of coding systems that could
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 handle decoding the text that was scanned. They are listed in order of
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 decreasing priority, based on the priority specified by the user with
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 @code{prefer-coding-system}. But if @var{highest} is non-@code{nil},
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 then the return value is just one coding system, the one that is highest
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 in priority.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 @tindex detect-coding-string string highest
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 @defun detect-coding-string
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 This function is like @code{detect-coding-region} except that it
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 operates on the contents of @var{string} instead of bytes in the buffer.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 @defun find-operation-coding-system operation &rest arguments
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 This function returns the coding system to use (by default) for
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 performing @var{operation} with @var{arguments}. The value has this
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 form:
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 @example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (@var{decoding-system} @var{encoding-system})
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 @end example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 The first element, @var{decoding-system}, is the coding system to use
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 for decoding (in case @var{operation} does decoding), and
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 @var{encoding-system} is the coding system for encoding (in case
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 @var{operation} does encoding).
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 The argument @var{operation} should be an Emacs I/O primitive:
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 @code{insert-file-contents}, @code{write-region}, @code{call-process},
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 @code{call-process-region}, @code{start-process}, or
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 @code{open-network-stream}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 The remaining arguments should be the same arguments that might be given
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 to that I/O primitive. Depending on which primitive, one of those
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 arguments is selected as the @dfn{target}. For example, if
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 @var{operation} does file I/O, whichever argument specifies the file
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 name is the target. For subprocess primitives, the process name is the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 target. For @code{open-network-stream}, the target is the service name
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 or port number.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 This function looks up the target in @code{file-coding-system-alist},
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 @code{process-coding-system-alist}, or
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 @code{network-coding-system-alist}, depending on @var{operation}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 @xref{Default Coding Systems}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 @node Default Coding Systems
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 @section Default Coding Systems
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 These variable specify which coding system to use by default for
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 certain files or when running certain subprograms. The idea of these
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 variables is that you set them once and for all to the defaults you
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 want, and then do not change them again. To specify a particular coding
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 system for a particular operation, don't change these variables;
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 instead, override them using @code{coding-system-for-read} and
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 @code{coding-system-for-write} (@pxref{Specifying Coding Systems}).
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 @tindex file-coding-system-alist
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 @defvar file-coding-system-alist
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 This variable is an alist that specifies the coding systems to use for
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 reading and writing particular files. Each element has the form
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 @code{(@var{pattern} . @var{coding})}, where @var{pattern} is a regular
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 expression that matches certain file names. The element applies to file
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 names that match @var{pattern}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 The @sc{cdr} of the element, @var{val}, should be either a coding
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 system, a cons cell containing two coding systems, or a function symbol.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 If @var{val} is a coding system, that coding system is used for both
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 reading the file and writing it. If @var{val} is a cons cell containing
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 two coding systems, its @sc{car} specifies the coding system for
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 decoding, and its @sc{cdr} specifies the coding system for encoding.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 If @var{val} is a function symbol, the function must return a coding
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 system or a cons cell containing two coding systems. This value is used
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 as described above.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 @end defvar
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 @tindex process-coding-system-alist
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 @defvar process-coding-system-alist
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 This variable is an alist specifying which coding systems to use for a
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 subprocess, depending on which program is running in the subprocess. It
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 works like @code{file-coding-system-alist}, except that @var{pattern} is
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 matched against the program name used to start the subprocess. The coding
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 system or systems specified in this alist are used to initialize the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 coding systems used for I/O to the subprocess, but you can specify
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 other coding systems later using @code{set-process-coding-system}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 @end defvar
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 @tindex network-coding-system-alist
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 @defvar network-coding-system-alist
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 This variable is an alist that specifies the coding system to use for
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 network streams. It works much like @code{file-coding-system-alist},
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 with the difference that the @var{pattern} in an elemetn may be either a
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 port number or a regular expression. If it is a regular expression, it
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 is matched against the network service name used to open the network
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 stream.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 @end defvar
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 @tindex default-process-coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 @defvar default-process-coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 This variable specifies the coding systems to use for subprocess (and
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 network stream) input and output, when nothing else specifies what to
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 do.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 The value should be a cons cell of the form @code{(@var{output-coding}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 . @var{input-coding})}. Here @var{output-coding} applies to output to
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 the subprocess, and @var{input-coding} applies to input from it.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 @end defvar
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 @node Specifying Coding Systems
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 @section Specifying a Coding System for One Operation
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 You can specify the coding system for a specific operation by binding
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 the variables @code{coding-system-for-read} and/or
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 @code{coding-system-for-write}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 @tindex coding-system-for-read
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 @defvar coding-system-for-read
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 If this variable is non-@code{nil}, it specifies the coding system to
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 use for reading a file, or for input from a synchronous subprocess.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 It also applies to any asynchronous subprocess or network stream, but in
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 a different way: the value of @code{coding-system-for-read} when you
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 start the subprocess or open the network stream specifies the input
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 decoding method for that subprocess or network stream. It remains in
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 use for that subprocess or network stream unless and until overridden.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 The right way to use this variable is to bind it with @code{let} for a
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 specific I/O operation. Its global value is normally @code{nil}, and
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 you should not globally set it to any other value. Here is an example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 of the right way to use the variable:
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 @example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 ;; @r{Read the file with no character code conversion.}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 ;; @r{Assume CRLF represents end-of-line.}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 (let ((coding-system-for-write 'emacs-mule-dos))
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 (insert-file-contents filename))
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 @end example
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 When its value is non-@code{nil}, @code{coding-system-for-read} takes
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 precedence all other methods of specifying a coding system to use for
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 input, including @code{file-coding-system-alist},
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 @code{process-coding-system-alist} and
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 @code{network-coding-system-alist}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 @end defvar
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 @tindex coding-system-for-write
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 @defvar coding-system-for-write
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 This works much like @code{coding-system-for-read}, except that it
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 applies to output rather than input. It affects writing to files,
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 subprocesses, and net connections.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 When a single operation does both input and output, as do
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 @code{call-process-region} and @code{start-process}, both
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 @code{coding-system-for-read} and @code{coding-system-for-write}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 affect it.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 @end defvar
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 @tindex last-coding-system-used
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 @defvar last-coding-system-used
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 All operations that use a coding system set this variable
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 to the coding system name that was used.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 @end defvar
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 @tindex inhibit-eol-conversion
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 @defvar inhibit-eol-conversion
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 When this variable is non-@code{nil}, no end-of-line conversion is done,
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 no matter which coding system is specified. This applies to all the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 Emacs I/O and subprocess primitives, and to the explicit encoding and
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 decoding functions (@pxref{Explicit Encoding}).
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 @end defvar
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 @tindex keyboard-coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 @defun keyboard-coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604 This function returns the coding system that is in use for decoding
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 keyboard input---or @code{nil} if no coding system is to be used.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 @tindex set-keyboard-coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 @defun set-keyboard-coding-system coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 This function specifies @var{coding-system} as the coding system to
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 use for decoding keyboard input. If @var{coding-system} is @code{nil},
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 that means do not decode keyboard input.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 @tindex terminal-coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 @defun terminal-coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 This function returns the coding system that is in use for encoding
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 terminal output---or @code{nil} for no encoding.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 @tindex set-terminal-coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 @defun set-terminal-coding-system coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 This function specifies @var{coding-system} as the coding system to use
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 for encoding terminal output. If @var{coding-system} is @code{nil},
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 that means do not encode terminal output.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 See also the functions @code{process-coding-system} and
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 @code{set-process-coding-system}. @xref{Process Information}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631 See also @code{read-coding-system} in @ref{High-Level Completion}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 @node Explicit Encoding
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 @section Explicit Encoding and Decoding
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 @cindex encoding text
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 @cindex decoding text
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 All the operations that transfer text in and out of Emacs have the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 ability to use a coding system to encode or decode the text.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 You can also explicitly encode and decode text using the functions
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 in this section.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643 @cindex raw bytes
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 The result of encoding, and the input to decoding, are not ordinary
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 text. They are ``raw bytes''---bytes that represent text in the same
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 way that an external file would. When a buffer contains raw bytes, it
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 is most natural to mark that buffer as using unibyte representation,
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 using @code{set-buffer-multibyte} (@pxref{Selecting a Representation}),
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 but this is not required.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 The usual way to get raw bytes in a buffer, for explicit decoding, is
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 to read them with from a file with @code{insert-file-contents-literally}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 (@pxref{Reading from Files}) or specify a non-@code{nil} @var{rawfile}
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 arguments when visiting a file with @code{find-file-noselect}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 The usual way to use the raw bytes that result from explicitly
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 encoding text is to copy them to a file or process---for example, to
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 write it with @code{write-region} (@pxref{Writing to Files}), and
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 suppress encoding for that @code{write-region} call by binding
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 @code{coding-system-for-write} to @code{no-conversion}.
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 @tindex encode-coding-region
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 @defun encode-coding-region start end coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 This function encodes the text from @var{start} to @var{end} according
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 to coding system @var{coding-system}. The encoded text replaces
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 the original text in the buffer. The result of encoding is
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 ``raw bytes.''
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 @tindex encode-coding-string
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 @defun encode-coding-string string coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 This function encodes the text in @var{string} according to coding
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 system @var{coding-system}. It returns a new string containing the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 encoded text. The result of encoding is ``raw bytes.''
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 @tindex decode-coding-region
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 @defun decode-coding-region start end coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 This function decodes the text from @var{start} to @var{end} according
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 to coding system @var{coding-system}. The decoded text replaces the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 original text in the buffer. To make explicit decoding useful, the text
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 before decoding ought to be ``raw bytes.''
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 @end defun
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 @tindex decode-coding-string
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 @defun decode-coding-string string coding-system
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 This function decodes the text in @var{string} according to coding
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 system @var{coding-system}. It returns a new string containing the
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 decoded text. To make explicit decoding useful, the contents of
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 @var{string} ought to be ``raw bytes.''
00022857f529 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691 @end defun