1 ;;; emu-latin1.el --- emu module for Emacs 19 and XEmacs without MULE
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility, mule, Latin-1
8 ;; This file is part of emu.
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;;; @ buffer representation
30 (defmacro-maybe set-buffer-multibyte (flag)
31 "Set the multibyte flag of the current buffer to FLAG.
32 If FLAG is t, this makes the buffer a multibyte buffer.
33 If FLAG is nil, this makes the buffer a single-byte buffer.
34 The buffer contents remain unchanged as a sequence of bytes
35 but the contents viewed as characters do change.
36 \[Emacs 20.3 emulating macro]"
43 (put 'ascii 'charset-description "Character set of ASCII")
44 (put 'ascii 'charset-registry "ASCII")
46 (put 'latin-iso8859-1 'charset-description "Character set of ISO-8859-1")
47 (put 'latin-iso8859-1 'charset-registry "ISO8859-1")
49 (defun charset-description (charset)
50 "Return description of CHARSET."
51 (get charset 'charset-description)
54 (defun charset-registry (charset)
55 "Return registry name of CHARSET."
56 (get charset 'charset-registry)
59 (defun charset-width (charset)
60 "Return number of columns a CHARSET occupies when displayed."
63 (defun charset-direction (charset)
64 "Return the direction of a character of CHARSET by
65 0 (left-to-right) or 1 (right-to-left)."
68 (defun find-charset-string (str)
69 "Return a list of charsets in the string."
70 (if (string-match "[\200-\377]" str)
74 (defalias 'find-non-ascii-charset-string 'find-charset-string)
76 (defun find-charset-region (start end)
77 "Return a list of charsets in the region between START and END."
80 (re-search-forward "[\200-\377]" end t)
85 (defalias 'find-non-ascii-charset-region 'find-charset-region)
91 (defconst *internal* nil)
92 (defconst *ctext* nil)
93 (defconst *noconv* nil)
95 (defun decode-coding-string (string coding-system)
96 "Decode the STRING which is encoded in CODING-SYSTEM."
99 (defun encode-coding-string (string coding-system)
100 "Encode the STRING as CODING-SYSTEM."
103 (defun decode-coding-region (start end coding-system)
104 "Decode the text between START and END which is encoded in CODING-SYSTEM."
107 (defun encode-coding-region (start end coding-system)
108 "Encode the text between START and END to CODING-SYSTEM."
111 (defun detect-coding-region (start end)
112 "Detect coding-system of the text in the region between START and END."
115 (defun set-buffer-file-coding-system (coding-system &optional force)
116 "Set buffer-file-coding-system of the current buffer to CODING-SYSTEM."
119 (defmacro as-binary-process (&rest body)
120 (` (let (selective-display) ; Disable ^M to nl translation.
124 (defmacro as-binary-input-file (&rest body)
125 (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
129 (defmacro as-binary-output-file (&rest body)
130 (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
135 ;;; @@ for old MULE emulation
138 (defun code-convert-string (str ic oc)
139 "Convert code in STRING from SOURCE code to TARGET code,
140 On successful converion, returns the result string,
141 else returns nil. [emu-latin1.el; old MULE emulating function]"
144 (defun code-convert-region (beg end ic oc)
145 "Convert code of the text between BEGIN and END from SOURCE
146 to TARGET. On successful conversion returns t,
147 else returns nil. [emu-latin1.el; old MULE emulating function]"
154 (defun insert-file-contents-as-binary (filename
155 &optional visit beg end replace)
156 "Like `insert-file-contents', q.v., but don't code and format conversion.
157 Like `insert-file-contents-literary', but it allows find-file-hooks,
158 automatic uncompression, etc.
160 Namely this function ensures that only format decoding and character
161 code conversion will not take place."
162 (let ((emx-binary-mode t))
163 (insert-file-contents filename visit beg end replace)
166 (defalias 'insert-binary-file-contents 'insert-file-contents-as-binary)
167 (make-obsolete 'insert-binary-file-contents 'insert-file-contents-as-binary)
169 (defalias 'insert-file-contents-as-raw-text 'insert-file-contents)
171 (defun insert-binary-file-contents-literally (filename
172 &optional visit beg end replace)
173 "Like `insert-file-contents-literally', q.v., but don't code conversion.
174 A buffer may be modified in several ways after reading into the buffer due
175 to advanced Emacs features, such as file-name-handlers, format decoding,
176 find-file-hooks, etc.
177 This function ensures that none of these modifications will take place."
178 (let ((emx-binary-mode t))
179 (insert-file-contents-literally filename visit beg end replace)
182 (defun write-region-as-binary (start end filename
183 &optional append visit lockname)
184 "Like `write-region', q.v., but don't code conversion."
185 (let ((emx-binary-mode t))
186 (write-region start end filename append visit lockname)
193 (defvar charsets-mime-charset-alist
194 '(((ascii) . us-ascii)))
196 (defvar default-mime-charset 'iso-8859-1)
198 (defun mime-charset-to-coding-system (charset)
199 (if (stringp charset)
200 (setq charset (intern (downcase charset)))
202 (and (memq charset (list 'us-ascii default-mime-charset))
206 (defun detect-mime-charset-region (start end)
207 "Return MIME charset for region between START and END."
210 (re-search-forward "[\200-\377]" end t)
215 (defun encode-mime-charset-region (start end charset)
216 "Encode the text between START and END as MIME CHARSET."
219 (defun decode-mime-charset-region (start end charset)
220 "Decode the text between START and END as MIME CHARSET."
223 (defun encode-mime-charset-string (string charset)
224 "Encode the STRING as MIME CHARSET."
227 (defun decode-mime-charset-string (string charset)
228 "Decode the STRING as MIME CHARSET."
231 (defalias 'write-region-as-mime-charset 'write-region)
237 (defun char-charset (char)
238 "Return the character set of char CHAR."
243 (defun char-bytes (char)
244 "Return number of bytes a character in CHAR occupies in a buffer."
247 (defun char-width (char)
248 "Return number of columns a CHAR occupies when displayed."
251 (defun split-char (character)
252 "Return list of charset and one or two position-codes of CHARACTER."
253 (cons (char-charset character) character)
256 (defalias 'char-length 'char-bytes)
258 (defmacro char-next-index (char index)
259 "Return index of character succeeding CHAR whose index is INDEX."
266 (defalias 'string-width 'length)
268 (defun string-to-char-list (str)
269 (mapcar (function identity) str)
272 (defalias 'string-to-int-list 'string-to-char-list)
274 (defalias 'sref 'aref)
276 (defun truncate-string (str width &optional start-column)
277 "Truncate STR to fit in WIDTH columns.
278 Optional non-nil arg START-COLUMN specifies the starting column.
279 \[emu-latin1.el; MULE 2.3 emulating function]"
281 (setq start-column 0))
282 (substring str start-column width)
285 (defalias 'looking-at-as-unibyte 'looking-at)
287 ;;; @@ obsoleted aliases
289 ;;; You should not use them.
291 (defalias 'string-columns 'length)
292 (make-obsolete 'string-columns 'string-width)
298 (provide 'emu-latin1)
300 ;;; emu-latin1.el ends here