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 (if (integerp coding-system)
117 (cdr (assq coding-system coding-system-kanji-code-alist)))))
120 (convert-string-kanji-code string code 3)
123 (defun encode-coding-string (string coding-system)
124 "Encode the STRING to CODING-SYSTEM.
125 \[emu-nemacs.el; EMACS 20 emulating function]"
126 (let ((code (if (integerp coding-system)
128 (cdr (assq coding-system coding-system-kanji-code-alist)))))
131 (convert-string-kanji-code string 3 code)
134 (defun decode-coding-region (start end coding-system)
135 "Decode the text between START and END which is encoded in CODING-SYSTEM.
136 \[emu-nemacs.el; EMACS 20 emulating function]"
137 (let ((code (if (integerp coding-system)
139 (cdr (assq coding-system coding-system-kanji-code-alist)))))
142 (narrow-to-region start end)
143 (convert-region-kanji-code start end code 3)
146 (defun encode-coding-region (start end coding-system)
147 "Encode the text between START and END to CODING-SYSTEM.
148 \[emu-nemacs.el; EMACS 20 emulating function]"
149 (let ((code (if (integerp coding-system)
151 (cdr (assq coding-system coding-system-kanji-code-alist)))))
154 (narrow-to-region start end)
155 (convert-region-kanji-code start end 3 code)
158 (defun detect-coding-region (start end)
159 "Detect coding-system of the text in the region between START and END.
160 \[emu-nemacs.el; Emacs 20 emulating function]"
163 (narrow-to-region start end)
165 (re-search-forward "[\200-\377]" nil t)))
169 (defalias 'set-buffer-file-coding-system 'set-kanji-fileio-code)
172 ;;; @ without code-conversion
175 (defmacro as-binary-process (&rest body)
176 (` (let (selective-display ; Disable ^M to nl translation.
179 (default-kanji-process-code 0)
180 program-kanji-code-alist)
183 (defmacro as-binary-input-file (&rest body)
184 (` (let (kanji-flag default-kanji-flag)
187 (defmacro as-binary-output-file (&rest body)
191 (defun write-region-as-binary (start end filename
192 &optional append visit lockname)
193 "Like `write-region', q.v., but don't code conversion. [emu-nemacs.el]"
194 (as-binary-output-file
195 (write-region start end filename append visit)))
197 (defun insert-file-contents-as-binary (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)))
205 (defun insert-file-contents-as-raw-text (filename
206 &optional visit beg end replace)
207 "Like `insert-file-contents', q.v., but don't character code conversion.
208 It converts line-break code from CRLF to LF. [emu-nemacs.el]"
210 (narrow-to-region (point) (point))
211 (let ((return (as-binary-input-file
212 (insert-file-contents filename visit))))
213 (while (search-forward "\r\n" nil t)
214 (replace-match "\n"))
215 (goto-char (point-min))
216 ;; Returns list absolute file name and length of data inserted.
217 (list (car return) (- (point-max) (point-min))))))
219 (defalias 'insert-file-contents-as-raw-text-CRLF
220 'insert-file-contents-as-raw-text)
222 (defun write-region-as-raw-text-CRLF (start end filename
223 &optional append visit lockname)
224 "Like `write-region', q.v., but don't code conversion. [emu-nemacs.el]"
225 (let ((the-buf (current-buffer)))
227 (insert-buffer-substring the-buf start end)
228 (goto-char (point-min))
229 (while (re-search-forward "\\(\\=\\|[^\r]\\)\n" nil t)
230 (replace-match "\\1\r\n"))
231 (write-region-as-binary (point-min)(point-max)
232 filename append visit))))
234 (defun find-file-noselect-as-binary (filename &optional nowarn rawfile)
235 "Like `find-file-noselect', q.v., but don't code conversion.
237 (as-binary-input-file (find-file-noselect filename nowarn)))
239 (defun find-file-noselect-as-raw-text (filename &optional nowarn rawfile)
240 "Like `find-file-noselect', q.v., but it does not code conversion
241 except for line-break code. [emu-nemacs.el]"
242 (let ((buf (get-file-buffer filename))
248 (verify-visited-file-modtime buf)
249 (cond ((not (file-exists-p filename))
250 (error "File %s no longer exists!" filename))
252 (if (buffer-modified-p buf)
253 "File has changed since last visited or saved. Flush your changes? "
254 "File has changed since last visited or saved. Read from disk? "))
255 (setq cur (current-buffer))
259 (goto-char (point-min))
260 (while (search-forward "\r\n" nil t)
261 (replace-match "\n")))
262 (set-buffer-modified-p nil)
267 (find-file-noselect-as-binary filename nowarn rawfile))
268 (while (search-forward "\r\n" nil t)
269 (replace-match "\n"))
270 (goto-char (point-min))
271 (set-buffer-modified-p nil))))))
273 (defalias 'find-file-noselect-as-raw-text-CRLF
274 'find-file-noselect-as-raw-text)
276 (defun open-network-stream-as-binary (name buffer host service)
277 "Like `open-network-stream', q.v., but don't code conversion.
279 (let ((process (open-network-stream name buffer host service)))
280 (set-process-kanji-code process 0)
283 (defun save-buffer-as-binary (&optional args)
284 "Like `save-buffer', q.v., but don't encode. [emu-nemacs.el]"
285 (as-binary-output-file
288 (defun save-buffer-as-raw-text-CRLF (&optional args)
289 "Like `save-buffer', q.v., but save as network representation.
291 (if (buffer-modified-p)
294 (let ((the-buf (current-buffer))
295 (filename (buffer-file-name)))
299 (insert-buffer the-buf)
300 (goto-char (point-min))
301 (while (re-search-forward "\\(\\=\\|[^\r]\\)\n" nil t)
302 (replace-match "\\1\r\n"))
303 (setq buffer-file-name filename)
304 (save-buffer-as-binary args))
305 (set-buffer-modified-p nil)
306 (clear-visited-file-modtime)))))))
309 ;;; @ with code-conversion
312 (defun insert-file-contents-as-coding-system
313 (coding-system filename &optional visit beg end replace)
314 "Like `insert-file-contents', q.v., but CODING-SYSTEM the first arg will
315 be applied to `kanji-fileio-code'. [emu-nemacs.el]"
316 (let ((kanji-fileio-code coding-system)
318 (insert-file-contents filename visit)))
320 (defun write-region-as-coding-system
321 (coding-system start end filename &optional append visit lockname)
322 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
323 applied to `kanji-fileio-code'. [emu-nemacs.el]"
324 (let ((kanji-fileio-code coding-system)
325 jka-compr-compression-info-list jam-zcat-filename-list)
326 (write-region start end filename append visit)))
328 (defun find-file-noselect-as-coding-system
329 (coding-system filename &optional nowarn rawfile)
330 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
331 be applied to `kanji-fileio-code'. [emu-nemacs.el]"
332 (let ((default-kanji-fileio-code coding-system)
333 kanji-fileio-code kanji-expected-code)
334 (find-file-noselect filename nowarn)))
336 (defun save-buffer-as-coding-system (coding-system &optional args)
337 "Like `save-buffer', q.v., but CODING-SYSTEM the first arg will be
338 applied to `kanji-fileio-code'. [emu-nemacs.el]"
339 (let ((kanji-fileio-code coding-system))
343 ;;; @ buffer representation
346 (defsubst-maybe set-buffer-multibyte (flag)
347 "Set the multibyte flag of the current buffer to FLAG.
348 If FLAG is t, this makes the buffer a multibyte buffer.
349 If FLAG is nil, this makes the buffer a single-byte buffer.
350 The buffer contents remain unchanged as a sequence of bytes
351 but the contents viewed as characters do change.
352 \[Emacs 20.3 emulating function]"
353 (setq kanji-flag flag)
360 (defun char-charset (chr)
361 "Return the character set of char CHR.
362 \[emu-nemacs.el; MULE emulating function]"
367 (defun char-bytes (chr)
368 "Return number of bytes CHAR will occupy in a buffer.
369 \[emu-nemacs.el; Mule emulating function]"
374 (defun char-width (char)
375 "Return number of columns a CHAR occupies when displayed.
381 (defalias 'char-length 'char-bytes)
383 (defmacro char-next-index (char index)
384 "Return index of character succeeding CHAR whose index is INDEX.
386 (` (+ (, index) (char-bytes (, char)))))
392 (defalias 'string-width 'length)
394 (defun sref (str idx)
395 "Return the character in STR at index IDX.
396 \[emu-nemacs.el; Mule emulating function]"
397 (let ((chr (aref str idx)))
400 (logior (lsh (aref str (1+ idx)) 8) chr))))
402 (defun string-to-char-list (str)
403 (let ((i 0)(len (length str)) dest chr)
405 (setq chr (aref str i))
408 chr (+ (lsh chr 8) (aref str i)))
410 (setq dest (cons chr dest))
414 (fset 'string-to-int-list (symbol-function 'string-to-char-list))
416 ;;; Imported from Mule-2.3
417 (defun truncate-string (str width &optional start-column)
418 "Truncate STR to fit in WIDTH columns.
419 Optional non-nil arg START-COLUMN specifies the starting column.
420 \[emu-mule.el; Mule 2.3 emulating function]"
422 (setq start-column 0))
423 (let ((max-width (string-width str))
428 (if (>= width max-width)
429 (setq width max-width))
430 (if (>= start-column width)
432 (while (< column start-column)
433 (setq ch (aref str from)
434 column (+ column (char-columns ch))
435 from (+ from (char-bytes ch))))
436 (if (< width max-width)
439 (while (<= column width)
440 (setq ch (aref str to)
441 column (+ column (char-columns ch))
443 to (+ to (char-bytes ch))))
445 (substring str from to))))
447 (defalias 'looking-at-as-unibyte 'looking-at)
449 ;;; @@ obsoleted aliases
451 ;;; You should not use them.
453 (defalias 'string-columns 'length)
459 (provide 'poem-nemacs)
461 ;;; poem-nemacs.el ends here