annotate lispref/nonascii.texi @ 22041:e977f2414da5

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