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 ;;; @ version and variant specific features
30 ;; (cond (running-xemacs
31 ;; (require 'emu-xemacs))
40 (put 'ascii 'charset-description "Character set of ASCII")
41 (put 'ascii 'charset-registry "ASCII")
43 (put 'latin-iso8859-1 'charset-description "Character set of ISO-8859-1")
44 (put 'latin-iso8859-1 'charset-registry "ISO8859-1")
46 (defun charset-description (charset)
47 "Return description of CHARSET."
48 (get charset 'charset-description)
51 (defun charset-registry (charset)
52 "Return registry name of CHARSET."
53 (get charset 'charset-registry)
56 (defun charset-width (charset)
57 "Return number of columns a CHARSET occupies when displayed."
60 (defun charset-direction (charset)
61 "Return the direction of a character of CHARSET by
62 0 (left-to-right) or 1 (right-to-left)."
65 (defun find-charset-string (str)
66 "Return a list of charsets in the string."
67 (if (string-match "[\200-\377]" str)
71 (defalias 'find-non-ascii-charset-string 'find-charset-string)
73 (defun find-charset-region (start end)
74 "Return a list of charsets in the region between START and END."
77 (re-search-forward "[\200-\377]" end t)
82 (defalias 'find-non-ascii-charset-region 'find-charset-region)
88 (defconst *internal* nil)
89 (defconst *ctext* nil)
90 (defconst *noconv* nil)
92 (defun decode-coding-string (string coding-system)
93 "Decode the STRING which is encoded in CODING-SYSTEM."
96 (defun encode-coding-string (string coding-system)
97 "Encode the STRING as CODING-SYSTEM."
100 (defun decode-coding-region (start end coding-system)
101 "Decode the text between START and END which is encoded in CODING-SYSTEM."
104 (defun encode-coding-region (start end coding-system)
105 "Encode the text between START and END to CODING-SYSTEM."
108 (defun detect-coding-region (start end)
109 "Detect coding-system of the text in the region between START and END."
112 (defun set-buffer-file-coding-system (coding-system &optional force)
113 "Set buffer-file-coding-system of the current buffer to CODING-SYSTEM."
116 (defmacro as-binary-process (&rest body)
117 (` (let (selective-display) ; Disable ^M to nl translation.
121 (defmacro as-binary-input-file (&rest body)
122 (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
126 (defmacro as-binary-output-file (&rest body)
127 (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
132 ;;; @@ for old MULE emulation
135 (defun code-convert-string (str ic oc)
136 "Convert code in STRING from SOURCE code to TARGET code,
137 On successful converion, returns the result string,
138 else returns nil. [emu-latin1.el; old MULE emulating function]"
141 (defun code-convert-region (beg end ic oc)
142 "Convert code of the text between BEGIN and END from SOURCE
143 to TARGET. On successful conversion returns t,
144 else returns nil. [emu-latin1.el; old MULE emulating function]"
151 (defun insert-file-contents-as-binary (filename
152 &optional visit beg end replace)
153 "Like `insert-file-contents', q.v., but don't code and format conversion.
154 Like `insert-file-contents-literary', but it allows find-file-hooks,
155 automatic uncompression, etc.
157 Namely this function ensures that only format decoding and character
158 code conversion will not take place."
159 (let ((emx-binary-mode t))
160 (insert-file-contents filename visit beg end replace)
163 (defalias 'insert-binary-file-contents 'insert-file-contents-as-binary)
164 (make-obsolete 'insert-binary-file-contents 'insert-file-contents-as-binary)
166 (defun insert-binary-file-contents-literally (filename
167 &optional visit beg end replace)
168 "Like `insert-file-contents-literally', q.v., but don't code conversion.
169 A buffer may be modified in several ways after reading into the buffer due
170 to advanced Emacs features, such as file-name-handlers, format decoding,
171 find-file-hooks, etc.
172 This function ensures that none of these modifications will take place."
173 (let ((emx-binary-mode t))
174 (insert-file-contents-literally filename visit beg end replace)
177 (defun write-region-as-binary (start end filename
178 &optional append visit lockname)
179 "Like `write-region', q.v., but don't code conversion."
180 (let ((emx-binary-mode t))
181 (write-region start end filename append visit lockname)
188 (defvar charsets-mime-charset-alist
189 '(((ascii) . us-ascii)))
191 (defvar default-mime-charset 'iso-8859-1)
193 (defun mime-charset-to-coding-system (charset)
194 (if (stringp charset)
195 (setq charset (intern (downcase charset)))
197 (and (memq charset (list 'us-ascii default-mime-charset))
201 (defun detect-mime-charset-region (start end)
202 "Return MIME charset for region between START and END."
205 (re-search-forward "[\200-\377]" end t)
210 (defun encode-mime-charset-region (start end charset)
211 "Encode the text between START and END as MIME CHARSET."
214 (defun decode-mime-charset-region (start end charset)
215 "Decode the text between START and END as MIME CHARSET."
218 (defun encode-mime-charset-string (string charset)
219 "Encode the STRING as MIME CHARSET."
222 (defun decode-mime-charset-string (string charset)
223 "Decode the STRING as MIME CHARSET."
230 (defun char-charset (char)
231 "Return the character set of char CHAR."
236 (defun char-bytes (char)
237 "Return number of bytes a character in CHAR occupies in a buffer."
240 (defun char-width (char)
241 "Return number of columns a CHAR occupies when displayed."
244 (defalias 'char-length 'char-bytes)
246 (defmacro char-next-index (char index)
247 "Return index of character succeeding CHAR whose index is INDEX."
254 (defalias 'string-width 'length)
256 (defun string-to-char-list (str)
257 (mapcar (function identity) str)
260 (defalias 'string-to-int-list 'string-to-char-list)
262 (defalias 'sref 'aref)
264 (defun truncate-string (str width &optional start-column)
265 "Truncate STR to fit in WIDTH columns.
266 Optional non-nil arg START-COLUMN specifies the starting column.
267 \[emu-latin1.el; MULE 2.3 emulating function]"
269 (setq start-column 0))
270 (substring str start-column width)
273 ;;; @@ obsoleted aliases
275 ;;; You should not use them.
277 (defalias 'string-columns 'length)
278 (make-obsolete 'string-columns 'string-width)
284 (provide 'emu-latin1)
286 ;;; emu-latin1.el ends here