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 ;; Keywords: emulation, compatibility, Mule
8 ;; This file is part of APEL (A Portable Emacs Library).
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.
30 ;;; @ version specific features
33 (cond ((= emacs-major-version 19)
34 ;; Suggested by SASAKI Osamu <osamu@shuugr.bekkoame.or.jp>
35 ;; (cf. [os2-emacs-ja:78])
36 (defun fontset-pixel-size (fontset)
37 (let* ((font (get-font-info
38 (aref (cdr (get-fontset-info fontset)) 0)))
43 (let ((pat (aref font 1)))
44 (if (string-match "-[0-9]+-" pat)
47 pat (1+ (match-beginning 0)) (1- (match-end 0))))
51 (define-ccl-program ccl-decode-raw-text
67 "Convert line-break code from CRLF to LF.")
69 (define-ccl-program ccl-encode-raw-text
72 (loop (write-read-repeat r0))))
73 "Pass through without any conversions.")
75 (define-ccl-program ccl-encode-raw-text-CRLF
83 "Convert line-break code from LF to CRLF.")
89 (cons ccl-decode-raw-text ccl-encode-raw-text))
95 (cons ccl-decode-raw-text ccl-encode-raw-text-CRLF))
106 (defalias 'make-char 'make-character)
108 (defalias 'find-non-ascii-charset-string 'find-charset-string)
109 (defalias 'find-non-ascii-charset-region 'find-charset-region)
111 (defalias 'charset-bytes 'char-bytes)
112 (defalias 'charset-description 'char-description)
113 (defalias 'charset-registry 'char-registry)
114 (defalias 'charset-columns 'char-width)
115 (defalias 'charset-direction 'char-direction)
117 (defun charset-chars (charset)
118 "Return the number of characters per dimension of CHARSET."
119 (if (= (logand (nth 2 (character-set charset)) 1) 1)
127 (defun encode-coding-region (start end coding-system)
128 "Encode the text between START and END to CODING-SYSTEM.
129 \[EMACS 20 emulating function]"
130 ;; If `coding-system' is nil, do nothing.
131 (code-convert-region start end *internal* coding-system))
133 (defun decode-coding-region (start end coding-system)
134 "Decode the text between START and END which is encoded in CODING-SYSTEM.
135 \[EMACS 20 emulating function]"
136 ;; If `coding-system' is nil, do nothing.
137 (code-convert-region start end coding-system *internal*))
139 ;; XXX: Should we support optional NOCOPY argument? (only in Emacs 20.x)
140 (defun encode-coding-string (str coding-system)
141 "Encode the STRING to CODING-SYSTEM.
142 \[EMACS 20 emulating function]"
144 (code-convert-string str *internal* coding-system)
145 ;;(code-convert-string str *internal* nil) returns nil instead of str.
148 ;; XXX: Should we support optional NOCOPY argument? (only in Emacs 20.x)
149 (defun decode-coding-string (str coding-system)
150 "Decode the string STR which is encoded in CODING-SYSTEM.
151 \[EMACS 20 emulating function]"
153 (let ((len (length str))
155 (while (and (< 0 len)
158 (substring str 0 len)
159 coding-system *internal*))))
161 (concat ret (substring str len)))
164 (defalias 'detect-coding-region 'code-detect-region)
166 (defalias 'set-buffer-file-coding-system 'set-file-coding-system)
169 ;;; @ without code-conversion
172 (defmacro as-binary-process (&rest body)
173 (` (let (selective-display ; Disable ^M to nl translation.
176 (default-process-coding-system (cons *noconv* *noconv*))
177 program-coding-system-alist)
180 (defmacro as-binary-input-file (&rest body)
182 (file-coding-system-for-read *noconv*)
186 (defmacro as-binary-output-file (&rest body)
188 (file-coding-system *noconv*)
192 (defalias 'set-process-input-coding-system 'set-process-coding-system)
194 (defun insert-file-contents-as-binary (filename
195 &optional visit beg end replace)
196 "Like `insert-file-contents', q.v., but don't code and format conversion.
197 Like `insert-file-contents-literary', but it allows find-file-hooks,
198 automatic uncompression, etc.
200 Namely this function ensures that only format decoding and character
201 code conversion will not take place."
202 (as-binary-input-file
203 ;; Returns list absolute file name and length of data inserted.
204 (insert-file-contents filename visit beg end replace)))
206 (defun insert-file-contents-as-raw-text (filename
207 &optional visit beg end replace)
208 "Like `insert-file-contents', q.v., but don't code and format conversion.
209 Like `insert-file-contents-literary', but it allows find-file-hooks,
210 automatic uncompression, etc.
211 Like `insert-file-contents-as-binary', but it converts line-break
215 (narrow-to-region (point)(point))
217 ;; Returns list absolute file name and length of data inserted.
218 (insert-file-contents-as-binary filename visit beg end replace)))
219 (goto-char (point-min))
220 (while (re-search-forward "\r$" nil t)
222 (list (car return-val) (buffer-size))))))
224 (defun insert-binary-file-contents-literally (filename
225 &optional visit beg end replace)
226 "Like `insert-file-contents-literally', q.v., but don't code conversion.
227 A buffer may be modified in several ways after reading into the buffer due
228 to advanced Emacs features, such as file-name-handlers, format decoding,
229 find-file-hooks, etc.
230 This function ensures that none of these modifications will take place."
231 (as-binary-input-file
232 ;; Returns list absolute file name and length of data inserted.
233 (insert-file-contents-literally filename visit beg end replace)))
236 (running-emacs-19_29-or-later
237 ;; for MULE 2.3 based on Emacs 19.34.
238 (defun write-region-as-binary (start end filename
239 &optional append visit lockname)
240 "Like `write-region', q.v., but don't code conversion."
241 (as-binary-output-file
242 (write-region start end filename append visit lockname)))
244 (defun write-region-as-raw-text-CRLF (start end filename
245 &optional append visit lockname)
246 "Like `write-region', q.v., but don't code conversion."
247 (let ((the-buf (current-buffer)))
249 (insert-buffer-substring the-buf start end)
250 (goto-char (point-min))
251 (while (re-search-forward "\\(\\=\\|[^\r]\\)\n" nil t)
252 (replace-match "\\1\r\n"))
253 (write-region-as-binary (point-min)(point-max)
254 filename append visit lockname))))
256 (defun find-file-noselect-as-binary (filename &optional nowarn rawfile)
257 "Like `find-file-noselect', q.v., but don't code and format conversion."
258 (as-binary-input-file (find-file-noselect filename nowarn rawfile)))
261 ;; for MULE 2.3 based on Emacs 19.28.
262 (defun write-region-as-binary (start end filename
263 &optional append visit lockname)
264 "Like `write-region', q.v., but don't code conversion."
265 (as-binary-output-file
266 (write-region start end filename append visit)))
268 (defun write-region-as-raw-text-CRLF (start end filename
269 &optional append visit lockname)
270 "Like `write-region', q.v., but don't code conversion."
271 (let ((the-buf (current-buffer)))
273 (insert-buffer-substring the-buf start end)
274 (goto-char (point-min))
275 (while (re-search-forward "\\(\\=\\|[^\r]\\)\n" nil t)
276 (replace-match "\\1\r\n"))
277 (write-region-as-binary (point-min)(point-max)
278 filename append visit))))
280 (defun find-file-noselect-as-binary (filename &optional nowarn rawfile)
281 "Like `find-file-noselect', q.v., but don't code and format conversion."
282 (as-binary-input-file (find-file-noselect filename nowarn)))
285 (defun find-file-noselect-as-raw-text (filename &optional nowarn rawfile)
286 "Like `find-file-noselect', q.v., but it does not code and format conversion
287 except for line-break code."
290 (set-buffer (find-file-noselect-as-binary filename nowarn rawfile))
291 (let ((flag (buffer-modified-p)))
293 (goto-char (point-min))
294 (while (re-search-forward "\r$" nil t)
296 (set-buffer-modified-p flag)))))
298 (defun open-network-stream-as-binary (name buffer host service)
299 "Like `open-network-stream', q.v., but don't code conversion."
300 (let ((process (open-network-stream name buffer host service)))
301 (set-process-coding-system process *noconv* *noconv*)
305 ;;; @ with code-conversion
308 (defun insert-file-contents-as-coding-system
309 (coding-system filename &optional visit beg end replace)
310 "Like `insert-file-contents', q.v., but CODING-SYSTEM the first arg will
311 be applied to `file-coding-system-for-read'."
312 (let ((file-coding-system-for-read coding-system))
313 (insert-file-contents filename visit beg end replace)))
316 (running-emacs-19_29-or-later
317 ;; for MULE 2.3 based on Emacs 19.34.
318 (defun write-region-as-coding-system
319 (coding-system start end filename &optional append visit lockname)
320 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
321 applied to `file-coding-system'."
322 (let ((file-coding-system coding-system)
323 jka-compr-compression-info-list jam-zcat-filename-list)
324 (write-region start end filename append visit lockname)))
326 (defun find-file-noselect-as-coding-system
327 (coding-system filename &optional nowarn rawfile)
328 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
329 be applied to `file-coding-system-for-read'."
330 (let ((file-coding-system-for-read coding-system))
331 (find-file-noselect filename nowarn rawfile)))
334 ;; for MULE 2.3 based on Emacs 19.28.
335 (defun write-region-as-coding-system
336 (coding-system start end filename &optional append visit lockname)
337 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
338 applied to `file-coding-system'."
339 (let ((file-coding-system coding-system)
340 jka-compr-compression-info-list jam-zcat-filename-list)
341 (write-region start end filename append visit)))
343 (defun find-file-noselect-as-coding-system
344 (coding-system filename &optional nowarn rawfile)
345 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
346 be applied to `file-coding-system-for-read'."
347 (let ((file-coding-system-for-read coding-system))
348 (find-file-noselect filename nowarn)))
352 ;;; @ buffer representation
355 (defsubst-maybe set-buffer-multibyte (flag)
356 "Set the multibyte flag of the current buffer to FLAG.
357 If FLAG is t, this makes the buffer a multibyte buffer.
358 If FLAG is nil, this makes the buffer a single-byte buffer.
359 The buffer contents remain unchanged as a sequence of bytes
360 but the contents viewed as characters do change.
361 \[Emacs 20.3 emulating function]"
369 (defalias 'char-charset 'char-leading-char)
371 (defun split-char (character)
372 "Return list of charset and one or two position-codes of CHARACTER."
373 (let ((p (1- (char-bytes character)))
376 (setq dest (cons (- (char-component character p) 128) dest)
378 (cons (char-charset character) dest)))
380 (defmacro char-next-index (char index)
381 "Return index of character succeeding CHAR whose index is INDEX."
382 (` (+ (, index) (char-bytes (, char)))))
384 (if (subr-fboundp 'char-before)
388 (when (and (eq (car (get (car err) 'error-conditions))
389 'wrong-number-of-arguments)
390 (not (boundp 'si:char-before)))
391 (fset 'si:char-before (symbol-function 'char-before))
392 (defun char-before (&optional pos)
393 "Return character in current buffer preceding position POS.
394 POS is an integer or a buffer pointer.
395 If POS is out of range, the value is nil."
396 (si:char-before (or pos (point)))
399 (if (subr-fboundp 'char-after)
403 (when (and (eq (car (get (car err) 'error-conditions))
404 'wrong-number-of-arguments)
405 (not (boundp 'si:char-after)))
406 (fset 'si:char-after (symbol-function 'char-after))
407 (defun char-after (&optional pos)
408 "Return character in current buffer at position POS.
409 POS is an integer or a buffer pointer.
410 If POS is out of range, the value is nil."
411 (si:char-after (or pos (point)))
414 ;;; @@ obsoleted aliases
416 ;;; You should not use them.
418 (defalias 'char-length 'char-bytes)
419 ;;(defalias 'char-columns 'char-width)
425 (defalias 'string-columns 'string-width)
427 (defalias 'string-to-int-list 'string-to-char-list)
429 (or (fboundp 'truncate-string)
430 ;; Imported from Mule-2.3
431 (defun 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))))
463 (defalias 'looking-at-as-unibyte 'looking-at)
471 ;;; poem-om.el ends here