1 ;;; emu-nemacs.el --- emu API implementation for NEmacs
3 ;; Copyright (C) 1995,1996,1997,1998 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility, NEmacs, mule
8 ;; This file is part of emu.
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.
34 'charset-description "Character set of ASCII")
36 'charset-registry "ASCII")
38 (put 'japanese-jisx0208
39 'charset-description "Character set of JIS X0208-1983")
40 (put 'japanese-jisx0208
41 'charset-registry "JISX0208.1983")
43 (defun charset-description (charset)
44 "Return description of CHARSET. [emu-nemacs.el]"
45 (get charset 'charset-description)
48 (defun charset-registry (charset)
49 "Return registry name of CHARSET. [emu-nemacs.el]"
50 (get charset 'charset-registry)
53 (defun charset-width (charset)
54 "Return number of columns a CHARSET occupies when displayed.
56 (if (eq charset 'ascii)
60 (defun charset-direction (charset)
61 "Return the direction of a character of CHARSET by
62 0 (left-to-right) or 1 (right-to-left). [emu-nemacs.el]"
65 (defun find-charset-string (str)
66 "Return a list of charsets in the string.
67 \[emu-nemacs.el; Mule emulating function]"
68 (if (string-match "[\200-\377]" str)
72 (defalias 'find-non-ascii-charset-string 'find-charset-string)
74 (defun find-charset-region (start end)
75 "Return a list of charsets in the region between START and END.
76 \[emu-nemacs.el; Mule emulating function]"
79 (narrow-to-region start end)
81 (re-search-forward "[\200-\377]" nil t)
86 (defalias 'find-non-ascii-charset-region 'find-charset-region)
88 (defun check-ASCII-string (str)
91 (setq len (length str))
94 (if (>= (elt str i) 128)
100 ;;; @@ for old MULE emulation
103 ;;(defconst lc-ascii 0)
104 ;;(defconst lc-jp 146)
110 (defconst *noconv* 0)
114 (defconst *internal* 3)
115 (defconst *euc-japan* 3)
117 (defun decode-coding-string (string coding-system)
118 "Decode the STRING which is encoded in CODING-SYSTEM.
119 \[emu-nemacs.el; EMACS 20 emulating function]"
120 (if (eq coding-system 3)
122 (convert-string-kanji-code string coding-system 3)
125 (defun encode-coding-string (string coding-system)
126 "Encode the STRING to CODING-SYSTEM.
127 \[emu-nemacs.el; EMACS 20 emulating function]"
128 (if (eq coding-system 3)
130 (convert-string-kanji-code string 3 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 \[emu-nemacs.el; EMACS 20 emulating function]"
139 (narrow-to-region start end)
140 (convert-region-kanji-code start end coding-system 3)
143 (defun encode-coding-region (start end coding-system)
144 "Encode the text between START and END to CODING-SYSTEM.
145 \[emu-nemacs.el; EMACS 20 emulating function]"
149 (narrow-to-region start end)
150 (convert-region-kanji-code start end 3 coding-system)
153 (defun detect-coding-region (start end)
154 "Detect coding-system of the text in the region between START and END.
155 \[emu-nemacs.el; Emacs 20 emulating function]"
158 (narrow-to-region start end)
160 (re-search-forward "[\200-\377]" nil t)
165 (defalias 'set-buffer-file-coding-system 'set-kanji-fileio-code)
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)
176 (defmacro as-binary-input-file (&rest body)
181 (defmacro as-binary-output-file (&rest body)
187 ;;; @@ for old MULE emulation
190 (defun code-convert-string (str ic oc)
191 "Convert code in STRING from SOURCE code to TARGET code,
192 On successful converion, returns the result string,
193 else returns nil. [emu-nemacs.el; Mule emulating function]"
195 (convert-string-kanji-code str ic oc)
198 (defun code-convert-region (beg end ic oc)
199 "Convert code of the text between BEGIN and END from SOURCE
200 to TARGET. On successful conversion returns t,
201 else returns nil. [emu-nemacs.el; Mule emulating function]"
205 (narrow-to-region beg end)
206 (convert-region-kanji-code beg end ic oc)
213 (defun insert-file-contents-as-binary (filename
214 &optional visit beg end replace)
215 "Like `insert-file-contents', q.v., but don't character code conversion.
218 (insert-file-contents filename visit beg end replace)
221 (fset 'insert-binary-file-contents 'insert-file-contents-as-binary)
223 (defun insert-file-contents-as-raw-text (filename
224 &optional visit beg end replace)
225 "Like `insert-file-contents', q.v., but don't character code conversion.
228 (insert-file-contents filename visit beg end replace)
231 (defun insert-binary-file-contents-literally (filename
232 &optional visit beg end replace)
233 "Like `insert-file-contents-literally', q.v., but don't code conversion.
234 A buffer may be modified in several ways after reading into the buffer due
235 to advanced Emacs features, such as file-name-handlers, format decoding,
236 find-file-hooks, etc.
237 This function ensures that none of these modifications will take place.
240 (insert-file-contents-literally filename visit beg end replace)
243 (defun write-region-as-binary (start end filename
244 &optional append visit lockname)
245 "Like `write-region', q.v., but don't code conversion. [emu-nemacs.el]"
247 (write-region start end filename append visit)
254 (defvar charsets-mime-charset-alist
255 '(((ascii) . us-ascii)))
257 (defvar default-mime-charset 'iso-2022-jp)
259 (defvar mime-charset-coding-system-alist
264 (defun mime-charset-to-coding-system (charset)
265 (if (stringp charset)
266 (setq charset (intern (downcase charset)))
268 (cdr (assq charset mime-charset-coding-system-alist))
271 (defun detect-mime-charset-region (start end)
272 "Return MIME charset for region between START and END.
276 (narrow-to-region start end)
278 (re-search-forward "[\200-\377]" nil t)
283 (defun encode-mime-charset-region (start end charset)
284 "Encode the text between START and END as MIME CHARSET.
286 (let ((cs (mime-charset-to-coding-system charset)))
291 (narrow-to-region start end)
292 (convert-region-kanji-code start end 3 cs)
296 (defun decode-mime-charset-region (start end charset)
297 "Decode the text between START and END as MIME CHARSET.
299 (let ((cs (mime-charset-to-coding-system charset)))
304 (narrow-to-region start end)
305 (convert-region-kanji-code start end cs 3)
309 (defun encode-mime-charset-string (string charset)
310 "Encode the STRING as MIME CHARSET. [emu-nemacs.el]"
311 (let ((cs (mime-charset-to-coding-system charset)))
313 (convert-string-kanji-code string 3 cs)
316 (defun decode-mime-charset-string (string charset)
317 "Decode the STRING as MIME CHARSET. [emu-nemacs.el]"
318 (let ((cs (mime-charset-to-coding-system charset)))
320 (convert-string-kanji-code string cs 3)
323 (defun write-region-as-mime-charset (charset start end filename)
324 "Like `write-region', q.v., but code-convert by MIME CHARSET.
326 (let ((kanji-fileio-code
327 (or (mime-charset-to-coding-system charset)
329 (write-region start end filename)
333 ;;; @ buffer representation
336 (defsubst-maybe set-buffer-multibyte (flag)
337 "Set the multibyte flag of the current buffer to FLAG.
338 If FLAG is t, this makes the buffer a multibyte buffer.
339 If FLAG is nil, this makes the buffer a single-byte buffer.
340 The buffer contents remain unchanged as a sequence of bytes
341 but the contents viewed as characters do change.
342 \[Emacs 20.3 emulating function]"
343 (setq kanji-flag flag)
350 (defun char-charset (chr)
351 "Return the character set of char CHR.
352 \[emu-nemacs.el; MULE emulating function]"
357 (defun char-bytes (chr)
358 "Return number of bytes CHAR will occupy in a buffer.
359 \[emu-nemacs.el; Mule emulating function]"
360 (if (< chr 128) 1 2))
362 (defun char-width (char)
363 "Return number of columns a CHAR occupies when displayed.
369 (defalias 'char-length 'char-bytes)
371 (defmacro char-next-index (char index)
372 "Return index of character succeeding CHAR whose index is INDEX."
373 (` (+ (, index) (char-bytes (, char)))))
379 (defalias 'string-width 'length)
381 (defun sref (str idx)
382 "Return the character in STR at index IDX.
383 \[emu-nemacs.el; Mule emulating function]"
384 (let ((chr (aref str idx)))
387 (logior (lsh (aref str (1+ idx)) 8) chr)
390 (defun string-to-char-list (str)
391 (let ((i 0)(len (length str)) dest chr)
393 (setq chr (aref str i))
396 chr (+ (lsh chr 8) (aref str i))
398 (setq dest (cons chr dest))
404 (fset 'string-to-int-list (symbol-function 'string-to-char-list))
406 ;;; Imported from Mule-2.3
407 (defun truncate-string (str width &optional start-column)
408 "Truncate STR to fit in WIDTH columns.
409 Optional non-nil arg START-COLUMN specifies the starting column.
410 \[emu-mule.el; Mule 2.3 emulating function]"
412 (setq start-column 0))
413 (let ((max-width (string-width str))
418 (if (>= width max-width)
419 (setq width max-width))
420 (if (>= start-column width)
422 (while (< column start-column)
423 (setq ch (aref str from)
424 column (+ column (char-columns ch))
425 from (+ from (char-bytes ch))))
426 (if (< width max-width)
429 (while (<= column width)
430 (setq ch (aref str to)
431 column (+ column (char-columns ch))
433 to (+ to (char-bytes ch))))
435 (substring str from to))))
437 (defalias 'looking-at-as-unibyte 'looking-at)
439 ;;; @@ obsoleted aliases
441 ;;; You should not use them.
443 (defalias 'string-columns 'length)
446 ;;; @ text property emulation
449 (defvar emu:available-face-attribute-alist
451 ;;(bold . inversed-region)
452 (italic . underlined-region)
453 (underline . underlined-region)
456 ;; by YAMATE Keiichirou 1994/10/28
457 (defun attribute-add-narrow-attribute (attr from to)
458 (or (consp (symbol-value attr))
460 (let* ((attr-value (symbol-value attr))
461 (len (car attr-value))
464 (while (and (< posfrom len)
465 (> from (nth posfrom attr-value)))
466 (setq posfrom (1+ posfrom)))
468 (while (and (< posto len)
469 (> to (nth posto attr-value)))
470 (setq posto (1+ posto)))
471 (if (= posto posfrom)
472 (if (= (% posto 2) 1)
474 (= to (nth posto attr-value)))
475 (set-marker (nth posto attr-value) from)
476 (setcdr (nthcdr (1- posfrom) attr-value)
477 (cons (set-marker-type (set-marker (make-marker)
480 (cons (set-marker-type (set-marker (make-marker)
483 (nthcdr posto attr-value))))
484 (setcar attr-value (+ len 2))))
485 (if (= (% posfrom 2) 0)
486 (setq posfrom (1- posfrom))
487 (set-marker (nth posfrom attr-value) from))
488 (if (= (% posto 2) 0)
490 (setq posto (1- posto))
491 (set-marker (nth posto attr-value) to))
492 (setcdr (nthcdr posfrom attr-value)
493 (nthcdr posto attr-value)))))
495 (defalias 'make-overlay 'cons)
497 (defun overlay-put (overlay prop value)
498 (let ((ret (and (eq prop 'face)
499 (assq value emu:available-face-attribute-alist)
502 (attribute-add-narrow-attribute (cdr ret)
503 (car overlay)(cdr overlay))
510 (provide 'emu-nemacs)
512 ;;; emu-nemacs.el ends here