update.
[elisp/apel.git] / poem-xm.el
1 ;;; poem-xm.el --- poem module for XEmacs-mule; -*-byte-compile-dynamic: t;-*-
2
3 ;; Copyright (C) 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 (require 'poem-20)
28
29
30 ;;; @ fix coding-system definition
31 ;;;
32
33 ;; It seems not bug, but I can not permit it...
34 (and (coding-system-property 'iso-2022-jp 'input-charset-conversion)
35      (copy-coding-system 'iso-2022-7bit 'iso-2022-jp))
36
37 (and (coding-system-property 'iso-2022-jp-dos 'input-charset-conversion)
38      (copy-coding-system 'iso-2022-7bit-dos 'iso-2022-jp-dos))
39
40 ;; Redefine if -{dos|mac|unix} is not found.
41 (or (find-coding-system 'raw-text-dos)
42     (copy-coding-system 'no-conversion-dos 'raw-text-dos))
43 (or (find-coding-system 'raw-text-mac)
44     (copy-coding-system 'no-conversion-mac 'raw-text-mac))
45 (or (find-coding-system 'raw-text-unix)
46     (copy-coding-system 'no-conversion-unix 'raw-text-unix))
47
48 (or (find-coding-system 'ctext-dos)
49     (make-coding-system
50      'ctext 'iso2022
51      "Coding-system used in X as Compound Text Encoding."
52      '(charset-g0 ascii charset-g1 latin-iso8859-1
53                   eol-type nil
54                   mnemonic "CText")))
55
56 (or (find-coding-system 'iso-2022-jp-2-dos)
57     (make-coding-system
58      'iso-2022-jp-2 'iso2022
59      "ISO-2022 coding system using SS2 for 96-charset in 7-bit code."
60      '(charset-g0 ascii
61        charset-g2 t ;; unspecified but can be used later.
62        seven t
63        short t
64        mnemonic "ISO7/SS2"
65        eol-type nil)))
66
67 (or (find-coding-system 'gb2312-dos)
68     (copy-coding-system 'cn-gb-2312-dos 'gb2312-dos))
69 (or (find-coding-system 'gb2312-mac)
70     (copy-coding-system 'cn-gb-2312-mac 'gb2312-mac))
71 (or (find-coding-system 'gb2312-unix)
72     (copy-coding-system 'cn-gb-2312-unix 'gb2312-unix))
73
74 (or (find-coding-system 'euc-kr-dos)
75     (make-coding-system
76      'euc-kr 'iso2022
77      "Coding-system of Korean EUC (Extended Unix Code)."
78      '(charset-g0 ascii charset-g1 korean-ksc5601
79                   mnemonic "ko/EUC"
80                   eol-type nil)))
81
82 ;; (when (= (function-max-args 'coding-system-list) 0)
83 ;;   (or (fboundp 'coding-system-list-internal)
84 ;;       (fset 'coding-system-list-internal
85 ;;             (symbol-function 'coding-system-list)))
86 ;;   (defun coding-system-list (&optional base-only)
87 ;;     "Return a list of all existing coding systems.
88 ;; If optional arg BASE-ONLY is non-nil, only base coding systems are listed."
89 ;;     (if base-only
90 ;;         (let (dest
91 ;;               (rest (coding-system-list-internal))
92 ;;               cs)
93 ;;           (while rest
94 ;;             (setq cs (coding-system-name (coding-system-base (pop rest))))
95 ;;             (or (memq cs dest)
96 ;;                 (push cs dest))
97 ;;             )
98 ;;           dest)
99 ;;       (coding-system-list-internal)))
100 ;;   )
101
102
103 ;;; @ without code-conversion
104 ;;;
105
106 (defun insert-file-contents-as-binary (filename
107                                        &optional visit beg end replace)
108   "Like `insert-file-contents', but only reads in the file literally.
109 A buffer may be modified in several ways after reading into the buffer,
110 to Emacs features such as format decoding, character code
111 conversion, find-file-hooks, automatic uncompression, etc.
112
113 This function ensures that none of these modifications will take place."
114   (let ((format-alist nil)
115         (after-insert-file-functions nil)
116         (coding-system-for-read 'binary)
117         (coding-system-for-write 'binary)
118         (jka-compr-compression-info-list nil)
119         (jam-zcat-filename-list nil)
120         (find-buffer-file-type-function
121          (if (fboundp 'find-buffer-file-type)
122              (symbol-function 'find-buffer-file-type)
123            nil)))
124     (unwind-protect
125         (progn
126           (fset 'find-buffer-file-type (lambda (filename) t))
127           (insert-file-contents filename visit beg end replace))
128       (if find-buffer-file-type-function
129           (fset 'find-buffer-file-type find-buffer-file-type-function)
130         (fmakunbound 'find-buffer-file-type)))))
131
132
133 ;;; @ buffer representation
134 ;;;
135
136 (defsubst-maybe set-buffer-multibyte (flag)
137   "Set the multibyte flag of the current buffer to FLAG.
138 If FLAG is t, this makes the buffer a multibyte buffer.
139 If FLAG is nil, this makes the buffer a single-byte buffer.
140 The buffer contents remain unchanged as a sequence of bytes
141 but the contents viewed as characters do change.
142 \[Emacs 20.3 emulating function]"
143   flag)
144
145
146 ;;; @ character
147 ;;;
148
149 ;; avoid bug of XEmacs
150 (or (integerp (cdr (split-char ?a)))
151     (defun split-char (char)
152       "Return list of charset and one or two position-codes of CHAR."
153       (let ((charset (char-charset char)))
154         (if (eq charset 'ascii)
155             (list charset (char-int char))
156           (let ((i 0)
157                 (len (charset-dimension charset))
158                 (code (if (integerp char)
159                           char
160                         (char-int char)))
161                 dest)
162             (while (< i len)
163               (setq dest (cons (logand code 127) dest)
164                     code (lsh code -7)
165                     i (1+ i)))
166             (cons charset dest)))))
167     )
168
169 (defmacro char-next-index (char index)
170   "Return index of character succeeding CHAR whose index is INDEX."
171   `(1+ ,index))
172
173
174 ;;; @ string
175 ;;;
176
177 (defun-maybe string-to-int-list (str)
178   (mapcar #'char-int str))
179
180 (defalias 'looking-at-as-unibyte 'looking-at)
181
182
183 ;;; @ end
184 ;;;
185
186 (provide 'poem-xm)
187
188 ;;; poem-xm.el ends here