* poem-20.el, poem-ltn1.el, poem-nemacs.el, poem-om.el
[elisp/apel.git] / poem-ltn1.el
1 ;;; poem-ltn1.el --- poem implementation for Emacs 19 and XEmacs without MULE
2
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility, Mule
7
8 ;; This file is part of APEL (A Portable Emacs Library).
9
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.
14
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.
19
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.
24
25 ;;; Code:
26
27 ;;; @ buffer representation
28 ;;;
29
30 (defun-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]"
37   )
38
39
40 ;;; @ character set
41 ;;;
42
43 (put 'ascii 'charset-description "Character set of ASCII")
44 (put 'ascii 'charset-registry "ASCII")
45
46 (put 'latin-iso8859-1 'charset-description "Character set of ISO-8859-1")
47 (put 'latin-iso8859-1 'charset-registry "ISO8859-1")
48
49 (defun charset-description (charset)
50   "Return description of CHARSET."
51   (get charset 'charset-description))
52
53 (defun charset-registry (charset)
54   "Return registry name of CHARSET."
55   (get charset 'charset-registry))
56
57 (defun charset-width (charset)
58   "Return number of columns a CHARSET occupies when displayed."
59   1)
60
61 (defun charset-direction (charset)
62   "Return the direction of a character of CHARSET by
63   0 (left-to-right) or 1 (right-to-left)."
64   0)
65
66 (defun find-charset-string (str)
67   "Return a list of charsets in the string."
68   (if (string-match "[\200-\377]" str)
69       '(latin-iso8859-1)
70     ))
71
72 (defalias 'find-non-ascii-charset-string 'find-charset-string)
73
74 (defun find-charset-region (start end)
75   "Return a list of charsets in the region between START and END."
76   (if (save-excursion
77         (goto-char start)
78         (re-search-forward "[\200-\377]" end t))
79       '(latin-iso8859-1)
80     ))
81
82 (defalias 'find-non-ascii-charset-region 'find-charset-region)
83
84
85 ;;; @ coding-system
86 ;;;
87
88 (defun decode-coding-string (string coding-system)
89   "Decode the STRING which is encoded in CODING-SYSTEM."
90   string)
91
92 (defun encode-coding-string (string coding-system)
93   "Encode the STRING as CODING-SYSTEM."
94   string)
95
96 (defun decode-coding-region (start end coding-system)
97   "Decode the text between START and END which is encoded in CODING-SYSTEM."
98   0)
99
100 (defun encode-coding-region (start end coding-system)
101   "Encode the text between START and END to CODING-SYSTEM."
102   0)
103
104 (defun detect-coding-region (start end)
105   "Detect coding-system of the text in the region between START and END."
106   )
107
108 (defun set-buffer-file-coding-system (coding-system &optional force)
109   "Set buffer-file-coding-system of the current buffer to CODING-SYSTEM."
110   )
111
112
113 ;;; @ without code-conversion
114 ;;;
115
116 (defmacro as-binary-process (&rest body)
117   (` (let (selective-display)   ; Disable ^M to nl translation.
118        (,@ body))))
119
120 (defmacro as-binary-input-file (&rest body)
121   (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
122        (,@ body))))
123
124 (defmacro as-binary-output-file (&rest body)
125   (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
126        (,@ body))))
127
128 (defun write-region-as-binary (start end filename
129                                      &optional append visit lockname)
130   "Like `write-region', q.v., but don't code conversion."
131   (let ((emx-binary-mode t))
132     (write-region start end filename append visit lockname)))
133
134 (defun insert-file-contents-as-binary (filename
135                                        &optional visit beg end replace)
136   "Like `insert-file-contents', q.v., but don't code and format conversion.
137 Like `insert-file-contents-literary', but it allows find-file-hooks,
138 automatic uncompression, etc.
139
140 Namely this function ensures that only format decoding and character
141 code conversion will not take place."
142   (let ((emx-binary-mode t))
143     ;; Returns list of absolute file name and length of data inserted.
144     (insert-file-contents filename visit beg end replace)))
145
146 (defun write-region-as-raw-text-CRLF (start end filename
147                                             &optional append visit lockname)
148   "Like `write-region', q.v., but write as network representation."
149   (let ((the-buf (current-buffer)))
150     (with-temp-buffer
151       (insert-buffer-substring the-buf start end)
152       (goto-char (point-min))
153       (while (re-search-forward "\\(\\=\\|[^\r]\\)\n" nil t)
154         (replace-match "\\1\r\n"))
155       (write-region (point-min)(point-max) filename append visit lockname))))
156
157 (defalias 'insert-file-contents-as-raw-text 'insert-file-contents)
158
159 (defun open-network-stream-as-binary (name buffer host service)
160   "Like `open-network-stream', q.v., but don't code conversion."
161   (let ((emx-binary-mode t))
162     (open-network-stream name buffer host service)))
163
164
165 ;;; @ with code-conversion (but actually it might be not done)
166 ;;;
167
168 (defun insert-file-contents-as-specified-coding-system (filename &rest args)
169   "Like `insert-file-contents', q.v., but code convert by the specified
170 coding-system. ARGS the optional arguments are passed to
171 `insert-file-contents' except for the last element. The last element of
172 ARGS must be a coding-system."
173   (apply 'insert-file-contents filename (nreverse (cdr (nreverse args)))))
174
175 (defun write-region-as-specified-coding-system (start end filename
176                                                       &rest args)
177   "Like `write-region', q.v., but code convert by the specified coding-system.
178 ARGS the optional arguments are passed to `write-region' except for the last
179 element. The last element of ARGS must be a coding-system."
180   (let (jka-compr-compression-info-list jam-zcat-filename-list)
181     (apply 'write-region start end filename
182            (nreverse (cdr (nreverse args))))))
183
184
185 ;;; @ character
186 ;;;
187
188 (defun char-charset (char)
189   "Return the character set of char CHAR."
190   (if (< char 128)
191       'ascii
192     'latin-iso8859-1))
193
194 (defun char-bytes (char)
195   "Return number of bytes a character in CHAR occupies in a buffer."
196   1)
197
198 (defun char-width (char)
199   "Return number of columns a CHAR occupies when displayed."
200   1)
201
202 (defun split-char (character)
203   "Return list of charset and one or two position-codes of CHARACTER."
204   (cons (char-charset character) character))
205
206 (defalias 'char-length 'char-bytes)
207
208 (defmacro char-next-index (char index)
209   "Return index of character succeeding CHAR whose index is INDEX."
210   (` (1+ (, index))))
211
212
213 ;;; @ string
214 ;;;
215
216 (defalias 'string-width 'length)
217
218 (defun string-to-char-list (str)
219   (mapcar (function identity) str))
220
221 (defalias 'string-to-int-list 'string-to-char-list)
222
223 (defalias 'sref 'aref)
224
225 (defun truncate-string (str width &optional start-column)
226   "Truncate STR to fit in WIDTH columns.
227 Optional non-nil arg START-COLUMN specifies the starting column.
228 \[emu-latin1.el; MULE 2.3 emulating function]"
229   (or start-column
230       (setq start-column 0))
231   (substring str start-column width))
232
233 (defalias 'looking-at-as-unibyte 'looking-at)
234
235 ;;; @@ obsoleted aliases
236 ;;;
237 ;;; You should not use them.
238
239 (defalias 'string-columns 'length)
240 (make-obsolete 'string-columns 'string-width)
241
242
243 ;;; @ end
244 ;;;
245
246 (provide 'poem-ltn1)
247
248 ;;; poem-ltn1.el ends here