1 ;;; poem-nemacs.el --- poem implementation for Nemacs
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.
31 'charset-description "Character set of ASCII")
33 'charset-registry "ASCII")
35 (put 'japanese-jisx0208
36 'charset-description "Character set of JIS X0208-1983")
37 (put 'japanese-jisx0208
38 'charset-registry "JISX0208.1983")
40 (defun charset-description (charset)
41 "Return description of CHARSET. [emu-nemacs.el]"
42 (get charset 'charset-description))
44 (defun charset-registry (charset)
45 "Return registry name of CHARSET. [emu-nemacs.el]"
46 (get charset 'charset-registry))
48 (defun charset-width (charset)
49 "Return number of columns a CHARSET occupies when displayed.
51 (if (eq charset 'ascii)
55 (defun charset-direction (charset)
56 "Return the direction of a character of CHARSET by
57 0 (left-to-right) or 1 (right-to-left). [emu-nemacs.el]"
60 (defun find-charset-string (str)
61 "Return a list of charsets in the string.
62 \[emu-nemacs.el; Mule emulating function]"
63 (if (string-match "[\200-\377]" str)
67 (defalias 'find-non-ascii-charset-string 'find-charset-string)
69 (defun find-charset-region (start end)
70 "Return a list of charsets in the region between START and END.
71 \[emu-nemacs.el; Mule emulating function]"
74 (narrow-to-region start end)
76 (re-search-forward "[\200-\377]" nil t)))
80 (defalias 'find-non-ascii-charset-region 'find-charset-region)
82 (defun check-ASCII-string (str)
85 (setq len (length str))
88 (if (>= (elt str i) 128)
93 ;;; @@ for old MULE emulation
96 ;;(defconst lc-ascii 0)
97 ;;(defconst lc-jp 146)
103 (defvar coding-system-kanji-code-alist
112 (defun decode-coding-string (string coding-system)
113 "Decode the STRING which is encoded in CODING-SYSTEM.
114 \[emu-nemacs.el; EMACS 20 emulating function]"
115 (let ((code (cdr (assq coding-system coding-system-kanji-code-alist))))
118 (convert-string-kanji-code string code 3)
121 (defun encode-coding-string (string coding-system)
122 "Encode the STRING to CODING-SYSTEM.
123 \[emu-nemacs.el; EMACS 20 emulating function]"
124 (let ((code (cdr (assq coding-system coding-system-kanji-code-alist))))
127 (convert-string-kanji-code string 3 code)
130 (defun decode-coding-region (start end coding-system)
131 "Decode the text between START and END which is encoded in CODING-SYSTEM.
132 \[emu-nemacs.el; EMACS 20 emulating function]"
133 (let ((code (cdr (assq coding-system coding-system-kanji-code-alist))))
136 (narrow-to-region start end)
137 (convert-region-kanji-code start end code 3)
140 (defun encode-coding-region (start end coding-system)
141 "Encode the text between START and END to CODING-SYSTEM.
142 \[emu-nemacs.el; EMACS 20 emulating function]"
143 (let ((code (cdr (assq coding-system coding-system-kanji-code-alist))))
146 (narrow-to-region start end)
147 (convert-region-kanji-code start end 3 code)
150 (defun detect-coding-region (start end)
151 "Detect coding-system of the text in the region between START and END.
152 \[emu-nemacs.el; Emacs 20 emulating function]"
155 (narrow-to-region start end)
157 (re-search-forward "[\200-\377]" nil t)))
161 (defalias 'set-buffer-file-coding-system 'set-kanji-fileio-code)
164 ;;; @ without code-conversion
167 (defmacro as-binary-process (&rest body)
168 (` (let (selective-display ; Disable ^M to nl translation.
171 (default-kanji-process-code 0)
172 program-kanji-code-alist)
175 (defmacro as-binary-input-file (&rest body)
179 (defmacro as-binary-output-file (&rest body)
183 (defun write-region-as-binary (start end filename
184 &optional append visit lockname)
185 "Like `write-region', q.v., but don't code conversion. [emu-nemacs.el]"
186 (as-binary-output-file
187 (write-region start end filename append visit)))
189 (defun insert-file-contents-as-binary (filename
190 &optional visit beg end replace)
191 "Like `insert-file-contents', q.v., but don't character code conversion.
193 (as-binary-input-file
194 ;; Returns list absolute file name and length of data inserted.
195 (insert-file-contents filename visit beg end replace)))
197 (defun insert-file-contents-as-raw-text (filename
198 &optional visit beg end replace)
199 "Like `insert-file-contents', q.v., but don't character code conversion.
201 (as-binary-input-file
202 ;; Returns list absolute file name and length of data inserted.
203 (insert-file-contents filename visit beg end replace)))
205 (defun write-region-as-raw-text-CRLF (start end filename
206 &optional append visit lockname)
207 "Like `write-region', q.v., but don't code conversion. [emu-nemacs.el]"
208 (let ((the-buf (current-buffer)))
210 (insert-buffer-substring the-buf start end)
211 (goto-char (point-min))
212 (while (re-search-forward "\\(\\=\\|[^\r]\\)\n" nil t)
213 (replace-match "\\1\r\n"))
214 (write-region-as-binary (point-min)(point-max)
215 filename append visit))))
218 ;;; @ buffer representation
221 (defsubst-maybe set-buffer-multibyte (flag)
222 "Set the multibyte flag of the current buffer to FLAG.
223 If FLAG is t, this makes the buffer a multibyte buffer.
224 If FLAG is nil, this makes the buffer a single-byte buffer.
225 The buffer contents remain unchanged as a sequence of bytes
226 but the contents viewed as characters do change.
227 \[Emacs 20.3 emulating function]"
228 (setq kanji-flag flag)
235 (defun char-charset (chr)
236 "Return the character set of char CHR.
237 \[emu-nemacs.el; MULE emulating function]"
242 (defun char-bytes (chr)
243 "Return number of bytes CHAR will occupy in a buffer.
244 \[emu-nemacs.el; Mule emulating function]"
249 (defun char-width (char)
250 "Return number of columns a CHAR occupies when displayed.
256 (defalias 'char-length 'char-bytes)
258 (defmacro char-next-index (char index)
259 "Return index of character succeeding CHAR whose index is INDEX."
260 (` (+ (, index) (char-bytes (, char)))))
266 (defalias 'string-width 'length)
268 (defun sref (str idx)
269 "Return the character in STR at index IDX.
270 \[emu-nemacs.el; Mule emulating function]"
271 (let ((chr (aref str idx)))
274 (logior (lsh (aref str (1+ idx)) 8) chr))))
276 (defun string-to-char-list (str)
277 (let ((i 0)(len (length str)) dest chr)
279 (setq chr (aref str i))
282 chr (+ (lsh chr 8) (aref str i)))
284 (setq dest (cons chr dest))
288 (fset 'string-to-int-list (symbol-function 'string-to-char-list))
290 ;;; Imported from Mule-2.3
291 (defun truncate-string (str width &optional start-column)
292 "Truncate STR to fit in WIDTH columns.
293 Optional non-nil arg START-COLUMN specifies the starting column.
294 \[emu-mule.el; Mule 2.3 emulating function]"
296 (setq start-column 0))
297 (let ((max-width (string-width str))
302 (if (>= width max-width)
303 (setq width max-width))
304 (if (>= start-column width)
306 (while (< column start-column)
307 (setq ch (aref str from)
308 column (+ column (char-columns ch))
309 from (+ from (char-bytes ch))))
310 (if (< width max-width)
313 (while (<= column width)
314 (setq ch (aref str to)
315 column (+ column (char-columns ch))
317 to (+ to (char-bytes ch))))
319 (substring str from to))))
321 (defalias 'looking-at-as-unibyte 'looking-at)
323 ;;; @@ obsoleted aliases
325 ;;; You should not use them.
327 (defalias 'string-columns 'length)
333 (provide 'poem-nemacs)
335 ;;; poem-nemacs.el ends here