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 ;;; @ with code-conversion
172 (defun insert-file-contents-as-coding-system
173 (coding-system filename &optional visit beg end replace)
174 "Like `insert-file-contents', q.v., but CODING-SYSTEM the first arg will
175 be applied to `file-coding-system-for-read'."
176 (let ((file-coding-system-for-read coding-system))
177 (insert-file-contents filename visit beg end replace)))
180 ((and (>= emacs-major-version 19) (>= emacs-minor-version 29))
181 ;; for MULE 2.3 based on Emacs 19.34.
182 (defun write-region-as-coding-system
183 (coding-system start end filename &optional append visit lockname)
184 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
185 applied to `file-coding-system'."
186 (let ((file-coding-system coding-system)
187 jka-compr-compression-info-list jam-zcat-filename-list)
188 (write-region start end filename append visit lockname)))
190 (defun find-file-noselect-as-coding-system
191 (coding-system filename &optional nowarn rawfile)
192 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
193 be applied to `file-coding-system-for-read'."
194 (let ((file-coding-system-for-read coding-system))
195 (find-file-noselect filename nowarn rawfile)))
198 ;; for MULE 2.3 based on Emacs 19.28 or MULE 1.*.
199 (defun write-region-as-coding-system
200 (coding-system start end filename &optional append visit lockname)
201 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
202 applied to `file-coding-system'."
203 (let ((file-coding-system coding-system)
204 jka-compr-compression-info-list jam-zcat-filename-list)
205 (write-region start end filename append visit)))
207 (defun find-file-noselect-as-coding-system
208 (coding-system filename &optional nowarn rawfile)
209 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
210 be applied to `file-coding-system-for-read'."
211 (let ((file-coding-system-for-read coding-system))
212 (find-file-noselect filename nowarn)))
216 ;;; @ without code-conversion
219 (defmacro as-binary-process (&rest body)
220 (` (let (selective-display ; Disable ^M to nl translation.
223 (default-process-coding-system (cons *noconv* *noconv*))
224 program-coding-system-alist)
227 (defmacro as-binary-input-file (&rest body)
229 (file-coding-system-for-read *noconv*)
233 (defmacro as-binary-output-file (&rest body)
235 (file-coding-system *noconv*)
239 (defalias 'set-process-input-coding-system 'set-process-coding-system)
241 (defun insert-binary-file-contents-literally (filename
242 &optional visit beg end replace)
243 "Like `insert-file-contents-literally', q.v., but don't code conversion.
244 A buffer may be modified in several ways after reading into the buffer due
245 to advanced Emacs features, such as file-name-handlers, format decoding,
246 find-file-hooks, etc.
247 This function ensures that none of these modifications will take place."
248 (as-binary-input-file
249 ;; Returns list absolute file name and length of data inserted.
250 (insert-file-contents-literally filename visit beg end replace)))
253 ((>= emacs-major-version 19)
255 (defun insert-file-contents-as-binary (filename
256 &optional visit beg end replace)
257 "Like `insert-file-contents', q.v., but don't code and format conversion.
258 Like `insert-file-contents-literary', but it allows find-file-hooks,
259 automatic uncompression, etc.
261 Namely this function ensures that only format decoding and character
262 code conversion will not take place."
263 ;; Returns list absolute file name and length of data inserted.
264 (insert-file-contents-as-coding-system 'binary
265 filename visit beg end replace))
267 (defun insert-file-contents-as-raw-text (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.
272 Like `insert-file-contents-as-binary', but it converts line-break
274 ;; Returns list absolute file name and length of data inserted.
275 (insert-file-contents-as-coding-system 'raw-text
276 filename visit beg end replace))
278 (defun write-region-as-binary (start end filename
279 &optional append visit lockname)
280 "Like `write-region', q.v., but don't code conversion."
281 (write-region-as-coding-system 'binary
282 start end filename append visit lockname))
284 (defun write-region-as-raw-text-CRLF (start end filename
285 &optional append visit lockname)
286 "Like `write-region', q.v., but don't code conversion."
287 (write-region-as-coding-system 'raw-text-dos
288 start end filename append visit lockname))
290 (defun find-file-noselect-as-binary (filename &optional nowarn rawfile)
291 "Like `find-file-noselect', q.v., but don't code and format conversion."
292 (find-file-noselect-as-coding-system 'binary
293 filename nowarn rawfile))
295 (defun find-file-noselect-as-raw-text (filename &optional nowarn rawfile)
296 "Like `find-file-noselect', q.v., but it does not code and format
297 conversion except for line-break code."
298 (find-file-noselect-as-coding-system 'raw-text
299 filename nowarn rawfile))
303 (defun insert-file-contents-as-binary (filename
304 &optional visit beg end replace)
305 "Like `insert-file-contents', q.v., but don't code and format conversion.
306 Like `insert-file-contents-literary', but it allows find-file-hooks,
307 automatic uncompression, etc.
309 Namely this function ensures that only format decoding and character
310 code conversion will not take place."
311 (as-binary-input-file
312 ;; Returns list absolute file name and length of data inserted.
313 (insert-file-contents filename visit beg end replace)))
315 (defun insert-file-contents-as-raw-text (filename
316 &optional visit beg end replace)
317 "Like `insert-file-contents', q.v., but don't code and format conversion.
318 Like `insert-file-contents-literary', but it allows find-file-hooks,
319 automatic uncompression, etc.
320 Like `insert-file-contents-as-binary', but it converts line-break
324 (narrow-to-region (point)(point))
326 ;; Returns list absolute file name and length of data inserted.
327 (insert-file-contents-as-binary filename
328 visit beg end replace)))
329 (goto-char (point-min))
330 (while (re-search-forward "\r$" nil t)
332 (list (car return-val) (buffer-size))))))
334 (defun write-region-as-binary (start end filename
335 &optional append visit lockname)
336 "Like `write-region', q.v., but don't code conversion."
337 (as-binary-output-file
338 (write-region start end filename append visit)))
340 (defun write-region-as-raw-text-CRLF (start end filename
341 &optional append visit lockname)
342 "Like `write-region', q.v., but don't code conversion."
343 (let ((the-buf (current-buffer)))
345 (insert-buffer-substring the-buf start end)
346 (goto-char (point-min))
347 (while (re-search-forward "\\(\\=\\|[^\r]\\)\n" nil t)
348 (replace-match "\\1\r\n"))
349 (write-region-as-binary (point-min)(point-max)
350 filename append visit))))
352 (defun find-file-noselect-as-binary (filename &optional nowarn rawfile)
353 "Like `find-file-noselect', q.v., but don't code and format conversion."
354 (as-binary-input-file (find-file-noselect filename nowarn)))
356 (defun find-file-noselect-as-raw-text (filename &optional nowarn rawfile)
357 "Like `find-file-noselect', q.v., but it does not code and format
358 conversion except for line-break code."
361 (set-buffer (find-file-noselect-as-binary filename nowarn rawfile))
362 (let ((flag (buffer-modified-p)))
364 (goto-char (point-min))
365 (while (re-search-forward "\r$" nil t)
367 (set-buffer-modified-p flag)))))
370 (defun open-network-stream-as-binary (name buffer host service)
371 "Like `open-network-stream', q.v., but don't code conversion."
372 (let ((process (open-network-stream name buffer host service)))
373 (set-process-coding-system process *noconv* *noconv*)
377 ;;; @ buffer representation
380 (defsubst-maybe set-buffer-multibyte (flag)
381 "Set the multibyte flag of the current buffer to FLAG.
382 If FLAG is t, this makes the buffer a multibyte buffer.
383 If FLAG is nil, this makes the buffer a single-byte buffer.
384 The buffer contents remain unchanged as a sequence of bytes
385 but the contents viewed as characters do change.
386 \[Emacs 20.3 emulating function]"
394 (defalias 'char-charset 'char-leading-char)
396 (defun split-char (character)
397 "Return list of charset and one or two position-codes of CHARACTER."
398 (let ((p (1- (char-bytes character)))
401 (setq dest (cons (- (char-component character p) 128) dest)
403 (cons (char-charset character) dest)))
405 (defmacro char-next-index (char index)
406 "Return index of character succeeding CHAR whose index is INDEX."
407 (` (+ (, index) (char-bytes (, char)))))
409 (if (subr-fboundp 'char-before)
413 (when (and (eq (car (get (car err) 'error-conditions))
414 'wrong-number-of-arguments)
415 (not (boundp 'si:char-before)))
416 (fset 'si:char-before (symbol-function 'char-before))
417 (defun char-before (&optional pos)
418 "Return character in current buffer preceding position POS.
419 POS is an integer or a buffer pointer.
420 If POS is out of range, the value is nil."
421 (si:char-before (or pos (point)))
424 (if (subr-fboundp 'char-after)
428 (when (and (eq (car (get (car err) 'error-conditions))
429 'wrong-number-of-arguments)
430 (not (boundp 'si:char-after)))
431 (fset 'si:char-after (symbol-function 'char-after))
432 (defun char-after (&optional pos)
433 "Return character in current buffer at position POS.
434 POS is an integer or a buffer pointer.
435 If POS is out of range, the value is nil."
436 (si:char-after (or pos (point)))
439 ;;; @@ obsoleted aliases
441 ;;; You should not use them.
443 (defalias 'char-length 'char-bytes)
444 ;;(defalias 'char-columns 'char-width)
450 (defalias 'string-columns 'string-width)
452 (defalias 'string-to-int-list 'string-to-char-list)
454 ;; Imported from Mule-2.3
455 (defun-maybe truncate-string (str width &optional start-column)
457 Truncate STR to fit in WIDTH columns.
458 Optional non-nil arg START-COLUMN specifies the starting column.
459 \[emu-mule.el; Mule 2.3 emulating function]"
461 (setq start-column 0))
462 (let ((max-width (string-width str))
467 (if (>= width max-width)
468 (setq width max-width))
469 (if (>= start-column width)
471 (while (< column start-column)
472 (setq ch (aref str from)
473 column (+ column (char-width ch))
474 from (+ from (char-bytes ch))))
475 (if (< width max-width)
478 (while (<= column width)
479 (setq ch (aref str to)
480 column (+ column (char-width ch))
482 to (+ to (char-bytes ch))))
484 (substring str from to))))
486 (defalias 'looking-at-as-unibyte 'looking-at)
494 ;;; poem-om.el ends here