* static.el: New file.
[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 (eval-when-compile
31   (require 'poe))
32
33 (defun-maybe set-buffer-multibyte (flag)
34   "Set the multibyte flag of the current buffer to FLAG.
35 If FLAG is t, this makes the buffer a multibyte buffer.
36 If FLAG is nil, this makes the buffer a single-byte buffer.
37 The buffer contents remain unchanged as a sequence of bytes
38 but the contents viewed as characters do change.
39 \[Emacs 20.3 emulating macro]"
40   )
41
42
43 ;;; @ character set
44 ;;;
45
46 (put 'ascii 'charset-description "Character set of ASCII")
47 (put 'ascii 'charset-registry "ASCII")
48
49 (put 'latin-iso8859-1 'charset-description "Character set of ISO-8859-1")
50 (put 'latin-iso8859-1 'charset-registry "ISO8859-1")
51
52 (defun charset-description (charset)
53   "Return description of CHARSET."
54   (get charset 'charset-description))
55
56 (defun charset-registry (charset)
57   "Return registry name of CHARSET."
58   (get charset 'charset-registry))
59
60 (defun charset-width (charset)
61   "Return number of columns a CHARSET occupies when displayed."
62   1)
63
64 (defun charset-direction (charset)
65   "Return the direction of a character of CHARSET by
66   0 (left-to-right) or 1 (right-to-left)."
67   0)
68
69 (defun find-charset-string (str)
70   "Return a list of charsets in the string."
71   (if (string-match "[\200-\377]" str)
72       '(latin-iso8859-1)
73     ))
74
75 (defalias 'find-non-ascii-charset-string 'find-charset-string)
76
77 (defun find-charset-region (start end)
78   "Return a list of charsets in the region between START and END."
79   (if (save-excursion
80         (goto-char start)
81         (re-search-forward "[\200-\377]" end t))
82       '(latin-iso8859-1)
83     ))
84
85 (defalias 'find-non-ascii-charset-region 'find-charset-region)
86
87
88 ;;; @ coding-system
89 ;;;
90
91 (defun decode-coding-string (string coding-system)
92   "Decode the STRING which is encoded in CODING-SYSTEM."
93   string)
94
95 (defun encode-coding-string (string coding-system)
96   "Encode the STRING as CODING-SYSTEM."
97   string)
98
99 (defun decode-coding-region (start end coding-system)
100   "Decode the text between START and END which is encoded in CODING-SYSTEM."
101   0)
102
103 (defun encode-coding-region (start end coding-system)
104   "Encode the text between START and END to CODING-SYSTEM."
105   0)
106
107 (defun detect-coding-region (start end)
108   "Detect coding-system of the text in the region between START and END."
109   )
110
111 (defun set-buffer-file-coding-system (coding-system &optional force)
112   "Set buffer-file-coding-system of the current buffer to CODING-SYSTEM."
113   )
114
115
116 ;;; @ without code-conversion
117 ;;;
118
119 (defmacro as-binary-process (&rest body)
120   (` (let (selective-display)   ; Disable ^M to nl translation.
121        (,@ body))))
122
123 (defmacro as-binary-input-file (&rest body)
124   (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
125        (,@ body))))
126
127 (defmacro as-binary-output-file (&rest body)
128   (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
129        (,@ body))))
130
131 (defun write-region-as-binary (start end filename
132                                      &optional append visit lockname)
133   "Like `write-region', q.v., but don't code conversion."
134   (let ((emx-binary-mode t))
135     (write-region start end filename append visit lockname)))
136
137 (defun insert-file-contents-as-binary (filename
138                                        &optional visit beg end replace)
139   "Like `insert-file-contents', q.v., but don't code and format conversion.
140 Like `insert-file-contents-literary', but it allows find-file-hooks,
141 automatic uncompression, etc.
142
143 Namely this function ensures that only format decoding and character
144 code conversion will not take place."
145   (let ((emx-binary-mode t))
146     ;; Returns list of absolute file name and length of data inserted.
147     (insert-file-contents filename visit beg end replace)))
148
149 (defun write-region-as-raw-text-CRLF (start end filename
150                                             &optional append visit lockname)
151   "Like `write-region', q.v., but write as network representation."
152   (let ((the-buf (current-buffer)))
153     (with-temp-buffer
154       (insert-buffer-substring the-buf start end)
155       (goto-char (point-min))
156       (while (re-search-forward "\\(\\=\\|[^\r]\\)\n" nil t)
157         (replace-match "\\1\r\n"))
158       (write-region (point-min)(point-max) filename append visit lockname))))
159
160 (defalias 'insert-file-contents-as-raw-text 'insert-file-contents)
161
162 (defalias 'insert-file-contents-as-raw-text-CRLF 'insert-file-contents)
163
164 (defun find-file-noselect-as-binary (filename &optional nowarn rawfile)
165   "Like `find-file-noselect', q.v., but don't code and format conversion."
166   (let ((emx-binary-mode t))
167     (find-file-noselect filename nowarn rawfile)))
168
169 (defalias 'find-file-noselect-as-raw-text 'find-file-noselect)
170
171 (defalias 'find-file-noselect-as-raw-text-CRLF 'find-file-noselect)
172
173 (defun save-buffer-as-binary (&optional args)
174   "Like `save-buffer', q.v., but don't encode."
175   (let ((emx-binary-mode t))
176     (save-buffer args)))
177
178 (defun save-buffer-as-raw-text-CRLF (&optional args)
179   "Like `save-buffer', q.v., but save as network representation."
180   (if (buffer-modified-p)
181       (save-restriction
182         (widen)
183         (let ((the-buf (current-buffer))
184               (filename (buffer-file-name)))
185           (if filename
186               (prog1
187                   (with-temp-buffer
188                     (insert-buffer the-buf)
189                     (goto-char (point-min))
190                     (while (re-search-forward "\\(\\=\\|[^\r]\\)\n" nil t)
191                       (replace-match "\\1\r\n"))
192                     (setq buffer-file-name filename)
193                     (save-buffer args))
194                 (set-buffer-modified-p nil)
195                 (clear-visited-file-modtime)))))))
196
197 (defun open-network-stream-as-binary (name buffer host service)
198   "Like `open-network-stream', q.v., but don't code conversion."
199   (let ((emx-binary-mode t))
200     (open-network-stream name buffer host service)))
201
202
203 ;;; @ with code-conversion (but actually it might be not done)
204 ;;;
205
206 (defun insert-file-contents-as-coding-system
207   (coding-system filename &optional visit beg end replace)
208   "Like `insert-file-contents', q.v., CODING-SYSTEM the first arg will be
209 ignored."
210   (insert-file-contents filename visit beg end replace))
211
212 (defun write-region-as-coding-system
213   (coding-system start end filename &optional append visit lockname)
214   "Like `write-region', q.v., CODING-SYSTEM the first arg will be ignored."
215   (let (jka-compr-compression-info-list jam-zcat-filename-list)
216     (write-region start end filename append visit lockname)))
217
218 (defun find-file-noselect-as-coding-system
219   (coding-system filename &optional nowarn rawfile)
220   "Like `find-file-noselect', q.v., CODING-SYSTEM the first arg will be
221 ignored."
222   (find-file-noselect filename nowarn rawfile))
223
224 (defun save-buffer-as-coding-system (coding-system &optional args)
225   "Like `save-buffer', q.v., CODING-SYSTEM the first arg will be ignored."
226   (save-buffer args))
227
228
229 ;;; @ character
230 ;;;
231
232 (defun char-charset (char)
233   "Return the character set of char CHAR."
234   (if (< char 128)
235       'ascii
236     'latin-iso8859-1))
237
238 (defun char-bytes (char)
239   "Return number of bytes a character in CHAR occupies in a buffer."
240   1)
241
242 (defun char-width (char)
243   "Return number of columns a CHAR occupies when displayed."
244   1)
245
246 (defun split-char (character)
247   "Return list of charset and one or two position-codes of CHARACTER."
248   (cons (char-charset character) character))
249
250 (defalias 'char-length 'char-bytes)
251
252 (defmacro char-next-index (char index)
253   "Return index of character succeeding CHAR whose index is INDEX."
254   (` (1+ (, index))))
255
256
257 ;;; @ string
258 ;;;
259
260 (defalias 'string-width 'length)
261
262 (defun string-to-char-list (str)
263   (mapcar (function identity) str))
264
265 (defalias 'string-to-int-list 'string-to-char-list)
266
267 (defalias 'sref 'aref)
268
269 (defun truncate-string (str width &optional start-column)
270   "Truncate STR to fit in WIDTH columns.
271 Optional non-nil arg START-COLUMN specifies the starting column.
272 \[emu-latin1.el; MULE 2.3 emulating function]"
273   (or start-column
274       (setq start-column 0))
275   (substring str start-column width))
276
277 (defalias 'looking-at-as-unibyte 'looking-at)
278
279 ;;; @@ obsoleted aliases
280 ;;;
281 ;;; You should not use them.
282
283 (defalias 'string-columns 'length)
284 (make-obsolete 'string-columns 'string-width)
285
286
287 ;;; @ end
288 ;;;
289
290 (provide 'poem-ltn1)
291
292 ;;; poem-ltn1.el ends here