1 ;;; poem-om.el --- poem implementation for Mule 1.* and Mule 2.*
3 ;; Copyright (C) 1995-1999 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 poem-ccl-decode-raw-text
55 (read-if (r0 == ?\x0d)
56 (read-if (r1 == ?\x0a)
62 "Convert line-break code from CRLF to LF.")
64 (define-ccl-program poem-ccl-encode-raw-text
67 (loop (write-read-repeat r0))))
68 "Pass through without any conversions.")
70 (define-ccl-program poem-ccl-encode-raw-text-CRLF
73 (read-if (r0 == ?\x0a)
77 "Convert line-break code from LF to CRLF.")
83 (cons poem-ccl-decode-raw-text poem-ccl-encode-raw-text))
89 (cons poem-ccl-decode-raw-text poem-ccl-encode-raw-text-CRLF))
92 (defun poem-decode-raw-text (from to)
94 (narrow-to-region from to)
95 (goto-char (point-min))
96 (while (re-search-forward "\r$" nil t)
99 (defun poem-encode-raw-text-CRLF (from to)
101 (narrow-to-region from to)
102 (goto-char (point-min))
103 (while (re-search-forward "\\(\\=\\|[^\r]\\)\n" nil t)
104 (replace-match "\\1\r\n")
107 (make-coding-system 'raw-text nil ?= "No conversion")
108 (put 'raw-text 'post-read-conversion 'poem-decode-raw-text)
110 (make-coding-system 'raw-text-dos nil ?= "No conversion")
111 (put 'raw-text-dos 'post-read-conversion 'poem-decode-raw-text)
112 (put 'raw-text-dos 'pre-write-conversion 'poem-encode-raw-text-CRLF)
119 (defalias 'make-char 'make-character)
121 (defalias 'find-non-ascii-charset-string 'find-charset-string)
122 (defalias 'find-non-ascii-charset-region 'find-charset-region)
124 (defalias 'charset-bytes 'char-bytes)
125 (defalias 'charset-description 'char-description)
126 (defalias 'charset-registry 'char-registry)
127 (defalias 'charset-columns 'char-width)
128 (defalias 'charset-direction 'char-direction)
130 (defun charset-chars (charset)
131 "Return the number of characters per dimension of CHARSET."
132 (if (= (logand (nth 2 (character-set charset)) 1) 1)
140 (defun encode-coding-region (start end coding-system)
141 "Encode the text between START and END to CODING-SYSTEM.
142 \[EMACS 20 emulating function]"
143 ;; If `coding-system' is nil, do nothing.
144 (code-convert-region start end *internal* coding-system))
146 (defun decode-coding-region (start end coding-system)
147 "Decode the text between START and END which is encoded in CODING-SYSTEM.
148 \[EMACS 20 emulating function]"
149 ;; If `coding-system' is nil, do nothing.
150 (code-convert-region start end coding-system *internal*))
152 ;; XXX: Should we support optional NOCOPY argument? (only in Emacs 20.x)
153 (defun encode-coding-string (str coding-system)
154 "Encode the STRING to CODING-SYSTEM.
155 \[EMACS 20 emulating function]"
157 (code-convert-string str *internal* coding-system)
158 ;;(code-convert-string str *internal* nil) returns nil instead of str.
161 ;; XXX: Should we support optional NOCOPY argument? (only in Emacs 20.x)
162 (defun decode-coding-string (str coding-system)
163 "Decode the string STR which is encoded in CODING-SYSTEM.
164 \[EMACS 20 emulating function]"
166 (let ((len (length str))
168 (while (and (< 0 len)
171 (substring str 0 len)
172 coding-system *internal*))))
174 (concat ret (substring str len)))
177 (defalias 'detect-coding-region 'code-detect-region)
179 (defalias 'set-buffer-file-coding-system 'set-file-coding-system)
182 ;;; @ with code-conversion
185 (defun insert-file-contents-as-coding-system
186 (coding-system filename &optional visit beg end replace)
187 "Like `insert-file-contents', q.v., but CODING-SYSTEM the first arg will
188 be applied to `file-coding-system-for-read'."
189 (let ((file-coding-system-for-read coding-system))
190 (insert-file-contents filename visit beg end replace)))
193 ((and (>= emacs-major-version 19) (>= emacs-minor-version 29))
194 ;; for MULE 2.3 based on Emacs 19.34.
195 (defun write-region-as-coding-system
196 (coding-system start end filename &optional append visit lockname)
197 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
198 applied to `file-coding-system'."
199 (let ((file-coding-system coding-system)
200 jka-compr-compression-info-list jam-zcat-filename-list)
201 (write-region start end filename append visit lockname)))
203 (defun find-file-noselect-as-coding-system
204 (coding-system filename &optional nowarn rawfile)
205 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
206 be applied to `file-coding-system-for-read'."
207 (let ((file-coding-system-for-read coding-system))
208 (find-file-noselect filename nowarn rawfile)))
211 ;; for MULE 2.3 based on Emacs 19.28 or MULE 1.*.
212 (defun write-region-as-coding-system
213 (coding-system start end filename &optional append visit lockname)
214 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
215 applied to `file-coding-system'."
216 (let ((file-coding-system coding-system)
217 jka-compr-compression-info-list jam-zcat-filename-list)
218 (write-region start end filename append visit)))
220 (defun find-file-noselect-as-coding-system
221 (coding-system filename &optional nowarn rawfile)
222 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
223 be applied to `file-coding-system-for-read'."
224 (let ((file-coding-system-for-read coding-system))
225 (find-file-noselect filename nowarn)))
229 ;;; @ without code-conversion
232 (make-coding-system 'binary nil ?= "No conversion")
234 (defmacro as-binary-process (&rest body)
235 (` (let (selective-display ; Disable ^M to nl translation.
238 (default-process-coding-system (cons *noconv* *noconv*))
239 program-coding-system-alist)
242 (defmacro as-binary-input-file (&rest body)
244 (file-coding-system-for-read *noconv*)
248 (defmacro as-binary-output-file (&rest body)
250 (file-coding-system *noconv*)
254 (defalias 'set-process-input-coding-system 'set-process-coding-system)
256 (defun insert-binary-file-contents-literally (filename
257 &optional visit beg end replace)
258 "Like `insert-file-contents-literally', q.v., but don't code conversion.
259 A buffer may be modified in several ways after reading into the buffer due
260 to advanced Emacs features, such as file-name-handlers, format decoding,
261 find-file-hooks, etc.
262 This function ensures that none of these modifications will take place."
263 (as-binary-input-file
264 ;; Returns list absolute file name and length of data inserted.
265 (insert-file-contents-literally filename visit beg end replace)))
267 (defun insert-file-contents-as-binary (filename
268 &optional visit beg end replace)
269 "Like `insert-file-contents', q.v., but don't code and format conversion.
270 Like `insert-file-contents-literary', but it allows find-file-hooks,
271 automatic uncompression, etc.
273 Namely this function ensures that only format decoding and character
274 code conversion will not take place."
275 (as-binary-input-file
276 ;; Returns list absolute file name and length of data inserted.
277 (insert-file-contents filename visit beg end replace)))
279 (defun insert-file-contents-as-raw-text (filename
280 &optional visit beg end replace)
281 "Like `insert-file-contents', q.v., but don't code and format conversion.
282 Like `insert-file-contents-literary', but it allows find-file-hooks,
283 automatic uncompression, etc.
284 Like `insert-file-contents-as-binary', but it converts line-break
286 ;; Returns list absolute file name and length of data inserted.
287 (insert-file-contents-as-coding-system 'raw-text
288 filename visit beg end replace))
290 (defun write-region-as-binary (start end filename
291 &optional append visit lockname)
292 "Like `write-region', q.v., but don't code conversion."
293 (write-region-as-coding-system 'binary
294 start end filename append visit lockname))
296 (defun write-region-as-raw-text-CRLF (start end filename
297 &optional append visit lockname)
298 "Like `write-region', q.v., but don't code conversion."
299 (write-region-as-coding-system 'raw-text-dos
300 start end filename append visit lockname))
302 (defun open-network-stream-as-binary (name buffer host service)
303 "Like `open-network-stream', q.v., but don't code conversion."
304 (let ((process (open-network-stream name buffer host service)))
305 (set-process-coding-system process *noconv* *noconv*)
308 (defun find-file-noselect-as-binary (filename &optional nowarn rawfile)
309 "Like `find-file-noselect', q.v., but don't code and format conversion."
310 (find-file-noselect-as-coding-system 'binary filename nowarn rawfile))
312 (defun find-file-noselect-as-raw-text (filename &optional nowarn rawfile)
313 "Like `find-file-noselect', q.v., but it does not code and format
314 conversion except for line-break code."
315 (find-file-noselect-as-coding-system 'raw-text filename nowarn rawfile))
318 ;;; @ buffer representation
321 (defsubst-maybe set-buffer-multibyte (flag)
322 "Set the multibyte flag of the current buffer to FLAG.
323 If FLAG is t, this makes the buffer a multibyte buffer.
324 If FLAG is nil, this makes the buffer a single-byte buffer.
325 The buffer contents remain unchanged as a sequence of bytes
326 but the contents viewed as characters do change.
327 \[Emacs 20.3 emulating function]"
335 (defalias 'char-charset 'char-leading-char)
337 (defun split-char (character)
338 "Return list of charset and one or two position-codes of CHARACTER."
339 (let ((p (1- (char-bytes character)))
342 (setq dest (cons (- (char-component character p) 128) dest)
344 (cons (char-charset character) dest)))
346 (defmacro char-next-index (char index)
347 "Return index of character succeeding CHAR whose index is INDEX."
348 (` (+ (, index) (char-bytes (, char)))))
350 (if (subr-fboundp 'char-before)
354 (when (and (eq (car (get (car err) 'error-conditions))
355 'wrong-number-of-arguments)
356 (not (boundp 'si:char-before)))
357 (fset 'si:char-before (symbol-function 'char-before))
358 (defun char-before (&optional pos)
359 "Return character in current buffer preceding position POS.
360 POS is an integer or a buffer pointer.
361 If POS is out of range, the value is nil."
362 (si:char-before (or pos (point)))
365 (if (subr-fboundp 'char-after)
369 (when (and (eq (car (get (car err) 'error-conditions))
370 'wrong-number-of-arguments)
371 (not (boundp 'si:char-after)))
372 (fset 'si:char-after (symbol-function 'char-after))
373 (defun char-after (&optional pos)
374 "Return character in current buffer at position POS.
375 POS is an integer or a buffer pointer.
376 If POS is out of range, the value is nil."
377 (si:char-after (or pos (point)))
380 ;;; @@ obsoleted aliases
382 ;;; You should not use them.
384 (defalias 'char-length 'char-bytes)
385 ;;(defalias 'char-columns 'char-width)
391 (defalias 'string-columns 'string-width)
393 (defalias 'string-to-int-list 'string-to-char-list)
395 ;; Imported from Mule-2.3
396 (defun-maybe truncate-string (str width &optional start-column)
398 Truncate STR to fit in WIDTH columns.
399 Optional non-nil arg START-COLUMN specifies the starting column.
400 \[emu-mule.el; Mule 2.3 emulating function]"
402 (setq start-column 0))
403 (let ((max-width (string-width str))
408 (if (>= width max-width)
409 (setq width max-width))
410 (if (>= start-column width)
412 (while (< column start-column)
413 (setq ch (aref str from)
414 column (+ column (char-width ch))
415 from (+ from (char-bytes ch))))
416 (if (< width max-width)
419 (while (<= column width)
420 (setq ch (aref str to)
421 column (+ column (char-width ch))
423 to (+ to (char-bytes ch))))
425 (substring str from to))))
427 (defalias 'looking-at-as-unibyte 'looking-at)
435 ;;; poem-om.el ends here