1 ;;; poem-om.el --- poem implementation for Mule 1.* and Mule 2.*
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: emulation, compatibility, Mule
9 ;; This file is part of APEL (A Portable Emacs Library).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
31 ;;; @ version specific features
34 (cond ((= emacs-major-version 19)
35 ;; Suggested by SASAKI Osamu <osamu@shuugr.bekkoame.or.jp>
36 ;; (cf. [os2-emacs-ja:78])
37 (defun fontset-pixel-size (fontset)
38 (let* ((font (get-font-info
39 (aref (cdr (get-fontset-info fontset)) 0)))
44 (let ((pat (aref font 1)))
45 (if (string-match "-[0-9]+-" pat)
48 pat (1+ (match-beginning 0)) (1- (match-end 0))))
52 (define-ccl-program ccl-decode-raw-text
68 "Convert line-break code from CRLF to LF.")
70 (define-ccl-program ccl-encode-raw-text
73 (loop (write-read-repeat r0))))
74 "Pass through without any conversions.")
76 (define-ccl-program ccl-encode-raw-text-CRLF
84 "Convert line-break code from LF to CRLF.")
90 (cons ccl-decode-raw-text ccl-encode-raw-text))
96 (cons ccl-decode-raw-text ccl-encode-raw-text-CRLF))
103 (defalias 'make-char 'make-character)
105 (defalias 'find-non-ascii-charset-string 'find-charset-string)
106 (defalias 'find-non-ascii-charset-region 'find-charset-region)
108 (defalias 'charset-bytes 'char-bytes)
109 (defalias 'charset-description 'char-description)
110 (defalias 'charset-registry 'char-registry)
111 (defalias 'charset-columns 'char-width)
112 (defalias 'charset-direction 'char-direction)
114 (defun charset-chars (charset)
115 "Return the number of characters per dimension of CHARSET."
116 (if (= (logand (nth 2 (character-set charset)) 1) 1)
124 (defun encode-coding-region (start end coding-system)
125 "Encode the text between START and END to CODING-SYSTEM.
126 \[EMACS 20 emulating function]"
127 ;; If `coding-system' is nil, do nothing.
128 (code-convert-region start end *internal* coding-system))
130 (defun decode-coding-region (start end coding-system)
131 "Decode the text between START and END which is encoded in CODING-SYSTEM.
132 \[EMACS 20 emulating function]"
133 ;; If `coding-system' is nil, do nothing.
134 (code-convert-region start end coding-system *internal*))
136 ;; XXX: Should we support optional NOCOPY argument? (only in Emacs 20.x)
137 (defun encode-coding-string (str coding-system)
138 "Encode the STRING to CODING-SYSTEM.
139 \[EMACS 20 emulating function]"
141 (code-convert-string str *internal* coding-system)
142 ;;(code-convert-string str *internal* nil) returns nil instead of str.
145 ;; XXX: Should we support optional NOCOPY argument? (only in Emacs 20.x)
146 (defun decode-coding-string (str coding-system)
147 "Decode the string STR which is encoded in CODING-SYSTEM.
148 \[EMACS 20 emulating function]"
150 (let ((len (length str))
152 (while (and (< 0 len)
155 (substring str 0 len)
156 coding-system *internal*))))
158 (concat ret (substring str len)))
161 (defalias 'detect-coding-region 'code-detect-region)
163 (defalias 'set-buffer-file-coding-system 'set-file-coding-system)
166 ;;; @ with code-conversion
169 (defun insert-file-contents-as-coding-system
170 (coding-system filename &optional visit beg end replace)
171 "Like `insert-file-contents', q.v., but CODING-SYSTEM the first arg will
172 be applied to `file-coding-system-for-read'."
173 (let ((file-coding-system-for-read coding-system))
174 (insert-file-contents filename visit beg end replace)))
177 ((and (>= emacs-major-version 19) (>= emacs-minor-version 29))
178 ;; for MULE 2.3 based on Emacs 19.34.
179 (defun write-region-as-coding-system
180 (coding-system start end filename &optional append visit lockname)
181 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
182 applied to `file-coding-system'."
183 (let ((file-coding-system coding-system)
184 jka-compr-compression-info-list jam-zcat-filename-list)
185 (write-region start end filename append visit lockname)))
187 (defun find-file-noselect-as-coding-system
188 (coding-system filename &optional nowarn rawfile)
189 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
190 be applied to `file-coding-system-for-read'."
191 (let ((file-coding-system-for-read coding-system))
192 (find-file-noselect filename nowarn rawfile)))
195 ;; for MULE 2.3 based on Emacs 19.28 or MULE 1.*.
196 (defun write-region-as-coding-system
197 (coding-system start end filename &optional append visit lockname)
198 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
199 applied to `file-coding-system'."
200 (let ((file-coding-system coding-system)
201 jka-compr-compression-info-list jam-zcat-filename-list)
202 (write-region start end filename append visit)))
204 (defun find-file-noselect-as-coding-system
205 (coding-system filename &optional nowarn rawfile)
206 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
207 be applied to `file-coding-system-for-read'."
208 (let ((file-coding-system-for-read coding-system))
209 (find-file-noselect filename nowarn)))
213 ;;; @ without code-conversion
216 (make-coding-system 'binary nil ?= "No conversion")
218 (defmacro as-binary-process (&rest body)
219 (` (let (selective-display ; Disable ^M to nl translation.
222 (default-process-coding-system (cons *noconv* *noconv*))
223 program-coding-system-alist)
226 (defmacro as-binary-input-file (&rest body)
228 (file-coding-system-for-read *noconv*)
232 (defmacro as-binary-output-file (&rest body)
234 (file-coding-system *noconv*)
238 (defalias 'set-process-input-coding-system 'set-process-coding-system)
240 (defun insert-binary-file-contents-literally (filename
241 &optional visit beg end replace)
242 "Like `insert-file-contents-literally', q.v., but don't code conversion.
243 A buffer may be modified in several ways after reading into the buffer due
244 to advanced Emacs features, such as file-name-handlers, format decoding,
245 find-file-hooks, etc.
246 This function ensures that none of these modifications will take place."
247 (as-binary-input-file
248 ;; Returns list absolute file name and length of data inserted.
249 (insert-file-contents-literally filename visit beg end replace)))
251 (defun insert-file-contents-as-binary (filename
252 &optional visit beg end replace)
253 "Like `insert-file-contents', q.v., but don't code and format conversion.
254 Like `insert-file-contents-literary', but it allows find-file-hooks,
255 automatic uncompression, etc.
257 Namely this function ensures that only format decoding and character
258 code conversion will not take place."
259 (as-binary-input-file
260 ;; Returns list absolute file name and length of data inserted.
261 (insert-file-contents filename visit beg end replace)))
263 (defun write-region-as-binary (start end filename
264 &optional append visit lockname)
265 "Like `write-region', q.v., but don't code conversion."
266 (write-region-as-coding-system 'binary
267 start end filename append visit lockname))
269 (defun find-file-noselect-as-binary (filename &optional nowarn rawfile)
270 "Like `find-file-noselect', q.v., but don't code and format conversion."
271 (find-file-noselect-as-coding-system 'binary filename nowarn rawfile))
274 ((>= emacs-major-version 19)
276 (defun insert-file-contents-as-raw-text (filename
277 &optional visit beg end replace)
278 "Like `insert-file-contents', q.v., but don't code and format conversion.
279 Like `insert-file-contents-literary', but it allows find-file-hooks,
280 automatic uncompression, etc.
281 Like `insert-file-contents-as-binary', but it converts line-break
283 ;; Returns list absolute file name and length of data inserted.
284 (insert-file-contents-as-coding-system 'raw-text
285 filename visit beg end replace))
287 (defun write-region-as-raw-text-CRLF (start end filename
288 &optional append visit lockname)
289 "Like `write-region', q.v., but don't code conversion."
290 (write-region-as-coding-system 'raw-text-dos
291 start end filename append visit lockname))
293 (defun find-file-noselect-as-raw-text (filename &optional nowarn rawfile)
294 "Like `find-file-noselect', q.v., but it does not code and format
295 conversion except for line-break code."
296 (find-file-noselect-as-coding-system 'raw-text
297 filename nowarn rawfile))
301 (defun insert-file-contents-as-raw-text (filename
302 &optional visit beg end replace)
303 "Like `insert-file-contents', q.v., but don't code and format conversion.
304 Like `insert-file-contents-literary', but it allows find-file-hooks,
305 automatic uncompression, etc.
306 Like `insert-file-contents-as-binary', but it converts line-break
310 (narrow-to-region (point)(point))
312 ;; Returns list absolute file name and length of data inserted.
313 (insert-file-contents-as-binary filename
314 visit beg end replace)))
315 (goto-char (point-min))
316 (while (re-search-forward "\r$" nil t)
318 (list (car return-val) (buffer-size))))))
320 (defun write-region-as-raw-text-CRLF (start end filename
321 &optional append visit lockname)
322 "Like `write-region', q.v., but don't code conversion."
323 (let ((the-buf (current-buffer)))
325 (insert-buffer-substring the-buf start end)
326 (goto-char (point-min))
327 (while (re-search-forward "\\(\\=\\|[^\r]\\)\n" nil t)
328 (replace-match "\\1\r\n"))
329 (write-region-as-binary (point-min)(point-max)
330 filename append visit))))
332 (defun find-file-noselect-as-raw-text (filename &optional nowarn rawfile)
333 "Like `find-file-noselect', q.v., but it does not code and format
334 conversion except for line-break code."
337 (set-buffer (find-file-noselect-as-binary filename nowarn rawfile))
338 (let ((flag (buffer-modified-p)))
340 (goto-char (point-min))
341 (while (re-search-forward "\r$" nil t)
343 (set-buffer-modified-p flag)))))
346 (defun open-network-stream-as-binary (name buffer host service)
347 "Like `open-network-stream', q.v., but don't code conversion."
348 (let ((process (open-network-stream name buffer host service)))
349 (set-process-coding-system process *noconv* *noconv*)
353 ;;; @ buffer representation
356 (defsubst-maybe set-buffer-multibyte (flag)
357 "Set the multibyte flag of the current buffer to FLAG.
358 If FLAG is t, this makes the buffer a multibyte buffer.
359 If FLAG is nil, this makes the buffer a single-byte buffer.
360 The buffer contents remain unchanged as a sequence of bytes
361 but the contents viewed as characters do change.
362 \[Emacs 20.3 emulating function]"
370 (defalias 'char-charset 'char-leading-char)
372 (defun split-char (character)
373 "Return list of charset and one or two position-codes of CHARACTER."
374 (let ((p (1- (char-bytes character)))
377 (setq dest (cons (- (char-component character p) 128) dest)
379 (cons (char-charset character) dest)))
381 (defmacro char-next-index (char index)
382 "Return index of character succeeding CHAR whose index is INDEX."
383 (` (+ (, index) (char-bytes (, char)))))
385 (if (subr-fboundp 'char-before)
389 (when (and (eq (car (get (car err) 'error-conditions))
390 'wrong-number-of-arguments)
391 (not (boundp 'si:char-before)))
392 (fset 'si:char-before (symbol-function 'char-before))
393 (defun char-before (&optional pos)
394 "Return character in current buffer preceding position POS.
395 POS is an integer or a buffer pointer.
396 If POS is out of range, the value is nil."
397 (si:char-before (or pos (point)))
400 (if (subr-fboundp 'char-after)
404 (when (and (eq (car (get (car err) 'error-conditions))
405 'wrong-number-of-arguments)
406 (not (boundp 'si:char-after)))
407 (fset 'si:char-after (symbol-function 'char-after))
408 (defun char-after (&optional pos)
409 "Return character in current buffer at position POS.
410 POS is an integer or a buffer pointer.
411 If POS is out of range, the value is nil."
412 (si:char-after (or pos (point)))
415 ;;; @@ obsoleted aliases
417 ;;; You should not use them.
419 (defalias 'char-length 'char-bytes)
420 ;;(defalias 'char-columns 'char-width)
426 (defalias 'string-columns 'string-width)
428 (defalias 'string-to-int-list 'string-to-char-list)
430 ;; Imported from Mule-2.3
431 (defun-maybe truncate-string (str width &optional start-column)
433 Truncate STR to fit in WIDTH columns.
434 Optional non-nil arg START-COLUMN specifies the starting column.
435 \[emu-mule.el; Mule 2.3 emulating function]"
437 (setq start-column 0))
438 (let ((max-width (string-width str))
443 (if (>= width max-width)
444 (setq width max-width))
445 (if (>= start-column width)
447 (while (< column start-column)
448 (setq ch (aref str from)
449 column (+ column (char-width ch))
450 from (+ from (char-bytes ch))))
451 (if (< width max-width)
454 (while (<= column width)
455 (setq ch (aref str to)
456 column (+ column (char-width ch))
458 to (+ to (char-bytes ch))))
460 (substring str from to))))
462 (defalias 'looking-at-as-unibyte 'looking-at)
470 ;;; poem-om.el ends here