1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
|
;;; emu-nemacs.el --- emu API implementation for NEmacs
;; Copyright (C) 1995,1996,1997 MORIOKA Tomohiko
;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
;; Version: $Id: emu-nemacs.el,v 7.53 1997/04/05 16:23:23 morioka Exp $
;; Keywords: emulation, compatibility, NEmacs, mule
;; This file is part of emu.
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Code:
(require 'emu-18)
;;; @ character set
;;;
(defconst charset-ascii 0 "Character set of ASCII")
(defconst charset-jisx0208 146 "Character set of JIS X0208-1983")
(defun charset-description (charset)
"Return description of CHARSET. [emu-nemacs.el]"
(if (< charset 128)
(documentation-property 'charset-ascii 'variable-documentation)
(documentation-property 'charset-jisx0208 'variable-documentation)
))
(defun charset-registry (charset)
"Return registry name of CHARSET. [emu-nemacs.el]"
(if (< charset 128)
"ASCII"
"JISX0208.1983"))
(defun charset-columns (charset)
"Return number of columns a CHARSET occupies when displayed.
\[emu-nemacs.el]"
(if (< charset 128)
1
2))
(defun charset-direction (charset)
"Return the direction of a character of CHARSET by
0 (left-to-right) or 1 (right-to-left). [emu-nemacs.el]"
0)
(defun find-charset-string (str)
"Return a list of charsets in the string.
\[emu-nemacs.el; Mule emulating function]"
(if (string-match "[\200-\377]" str)
(list lc-jp)
))
(defalias 'find-non-ascii-charset-string 'find-charset-string)
(defun find-charset-region (start end)
"Return a list of charsets in the region between START and END.
\[emu-nemacs.el; Mule emulating function]"
(if (save-excursion
(save-restriction
(narrow-to-region start end)
(goto-char start)
(re-search-forward "[\200-\377]" nil t)
))
(list lc-jp)
))
(defalias 'find-non-ascii-charset-region 'find-charset-region)
(defun check-ASCII-string (str)
(let ((i 0)
len)
(setq len (length str))
(catch 'label
(while (< i len)
(if (>= (elt str i) 128)
(throw 'label nil))
(setq i (+ i 1))
)
str)))
;;; @@ for old MULE emulation
;;;
(defconst lc-ascii 0)
(defconst lc-jp 146)
;;; @ coding system
;;;
(defconst *noconv* 0)
(defconst *sjis* 1)
(defconst *junet* 2)
(defconst *ctext* 2)
(defconst *internal* 3)
(defconst *euc-japan* 3)
(defun decode-coding-string (string coding-system)
"Decode the STRING which is encoded in CODING-SYSTEM.
\[emu-nemacs.el; EMACS 20 emulating function]"
(if (eq coding-system 3)
string
(convert-string-kanji-code string coding-system 3)
))
(defun encode-coding-string (string coding-system)
"Encode the STRING to CODING-SYSTEM.
\[emu-nemacs.el; EMACS 20 emulating function]"
(if (eq coding-system 3)
string
(convert-string-kanji-code string 3 coding-system)
))
(defun decode-coding-region (start end coding-system)
"Decode the text between START and END which is encoded in CODING-SYSTEM.
\[emu-nemacs.el; EMACS 20 emulating function]"
(if (/= ic oc)
(save-excursion
(save-restriction
(narrow-to-region start end)
(convert-region-kanji-code start end coding-system 3)
))))
(defun encode-coding-region (start end coding-system)
"Encode the text between START and END to CODING-SYSTEM.
\[emu-nemacs.el; EMACS 20 emulating function]"
(if (/= ic oc)
(save-excursion
(save-restriction
(narrow-to-region start end)
(convert-region-kanji-code start end 3 coding-system)
))))
(defun detect-coding-region (start end)
"Detect coding-system of the text in the region between START and END.
\[emu-nemacs.el; Emacs 20 emulating function]"
(if (save-excursion
(save-restriction
(narrow-to-region start end)
(goto-char start)
(re-search-forward "[\200-\377]" nil t)
))
*euc-japan*
))
(defalias 'set-buffer-file-coding-system 'set-kanji-fileio-code)
(defmacro as-binary-process (&rest body)
(` (let (selective-display ; Disable ^M to nl translation.
;; NEmacs
kanji-flag
(default-kanji-process-code 0)
program-kanji-code-alist)
(,@ body)
)))
(defmacro as-binary-input-file (&rest body)
(` (let (kanji-flag)
(,@ body)
)))
(defmacro as-binary-output-file (&rest body)
(` (let (kanji-flag)
(,@ body)
)))
;;; @@ for old MULE emulation
;;;
(defun code-convert-string (str ic oc)
"Convert code in STRING from SOURCE code to TARGET code,
On successful converion, returns the result string,
else returns nil. [emu-nemacs.el; Mule emulating function]"
(if (not (eq ic oc))
(convert-string-kanji-code str ic oc)
str))
(defun code-convert-region (beg end ic oc)
"Convert code of the text between BEGIN and END from SOURCE
to TARGET. On successful conversion returns t,
else returns nil. [emu-nemacs.el; Mule emulating function]"
(if (/= ic oc)
(save-excursion
(save-restriction
(narrow-to-region beg end)
(convert-region-kanji-code beg end ic oc)
))))
;;; @ binary access
;;;
(defun insert-binary-file-contents-literally
(filename &optional visit beg end replace)
"Like `insert-file-contents-literally', q.v., but don't code conversion.
A buffer may be modified in several ways after reading into the buffer due
to advanced Emacs features, such as file-name-handlers, format decoding,
find-file-hooks, etc.
This function ensures that none of these modifications will take place.
\[emu.el]"
(let (kanji-flag)
(insert-file-contents-literally filename visit beg end replace)
))
;;; @ MIME charset
;;;
(defvar charsets-mime-charset-alist
(list (cons (list charset-ascii) 'us-ascii)))
(defvar default-mime-charset 'iso-2022-jp)
(defvar mime-charset-coding-system-alist
'((iso-2022-jp . 2)
(shift_jis . 1)
))
(defun mime-charset-to-coding-system (charset)
(if (stringp charset)
(setq charset (intern (downcase charset)))
)
(cdr (assq charset mime-charset-coding-system-alist))
)
(defun detect-mime-charset-region (start end)
"Return MIME charset for region between START and END.
\[emu-nemacs.el]"
(if (save-excursion
(save-restriction
(narrow-to-region start end)
(goto-char start)
(re-search-forward "[\200-\377]" nil t)
))
default-mime-charset
'us-ascii))
(defun encode-mime-charset-region (start end charset)
"Encode the text between START and END as MIME CHARSET.
\[emu-nemacs.el]"
(let ((cs (mime-charset-to-coding-system charset)))
(and (numberp cs)
(or (= cs 3)
(save-excursion
(save-restriction
(narrow-to-region start end)
(convert-region-kanji-code start end 3 cs)
))
))))
(defun decode-mime-charset-region (start end charset)
"Decode the text between START and END as MIME CHARSET.
\[emu-nemacs.el]"
(let ((cs (mime-charset-to-coding-system charset)))
(and (numberp cs)
(or (= cs 3)
(save-excursion
(save-restriction
(narrow-to-region start end)
(convert-region-kanji-code start end cs 3)
))
))))
(defun encode-mime-charset-string (string charset)
"Encode the STRING as MIME CHARSET. [emu-nemacs.el]"
(let ((cs (mime-charset-to-coding-system charset)))
(if cs
(convert-string-kanji-code string 3 cs)
string)))
(defun decode-mime-charset-string (string charset)
"Decode the STRING as MIME CHARSET. [emu-nemacs.el]"
(let ((cs (mime-charset-to-coding-system charset)))
(if cs
(convert-string-kanji-code string cs 3)
string)))
;;; @ character
;;;
(defun char-charset (chr)
"Return the character set of char CHR.
\[emu-nemacs.el; XEmacs 20 emulating function]"
(if (< chr 128)
charset-ascii
charset-jisx0208))
(defun char-bytes (chr)
"Return number of bytes CHAR will occupy in a buffer.
\[emu-nemacs.el; Mule emulating function]"
(if (< chr 128) 1 2))
(defalias 'char-length 'char-bytes)
(defun char-columns (character)
"Return number of columns a CHARACTER occupies when displayed.
\[emu-nemacs.el]"
(if (< character 128)
1
2))
;;; @@ for Mule emulation
;;;
(defalias 'char-leading-char 'char-charset)
(defalias 'char-width 'char-columns)
;;; @ string
;;;
(defalias 'string-columns 'length)
(defun sref (str idx)
"Return the character in STR at index IDX.
\[emu-nemacs.el; Mule emulating function]"
(let ((chr (aref str idx)))
(if (< chr 128)
chr
(logior (lsh (aref str (1+ idx)) 8) chr)
)))
(defun string-to-char-list (str)
(let ((i 0)(len (length str)) dest chr)
(while (< i len)
(setq chr (aref str i))
(if (>= chr 128)
(setq i (1+ i)
chr (+ (lsh chr 8) (aref str i))
))
(setq dest (cons chr dest))
(setq i (1+ i))
)
(reverse dest)
))
(fset 'string-to-int-list (symbol-function 'string-to-char-list))
;;; Imported from Mule-2.3
(defun truncate-string (str width &optional start-column)
"Truncate STR to fit in WIDTH columns.
Optional non-nil arg START-COLUMN specifies the starting column.
\[emu-mule.el; Mule 2.3 emulating function]"
(or start-column
(setq start-column 0))
(let ((max-width (string-width str))
(len (length str))
(from 0)
(column 0)
to-prev to ch)
(if (>= width max-width)
(setq width max-width))
(if (>= start-column width)
""
(while (< column start-column)
(setq ch (aref str from)
column (+ column (char-columns ch))
from (+ from (char-bytes ch))))
(if (< width max-width)
(progn
(setq to from)
(while (<= column width)
(setq ch (aref str to)
column (+ column (char-columns ch))
to-prev to
to (+ to (char-bytes ch))))
(setq to to-prev)))
(substring str from to))))
;;; @@ for Mule emulation
;;;
(defalias 'string-width 'length)
;;; @ text property emulation
;;;
(defvar emu:available-face-attribute-alist
'(
;;(bold . inversed-region)
(italic . underlined-region)
(underline . underlined-region)
))
;; by YAMATE Keiichirou 1994/10/28
(defun attribute-add-narrow-attribute (attr from to)
(or (consp (symbol-value attr))
(set attr (list 1)))
(let* ((attr-value (symbol-value attr))
(len (car attr-value))
(posfrom 1)
posto)
(while (and (< posfrom len)
(> from (nth posfrom attr-value)))
(setq posfrom (1+ posfrom)))
(setq posto posfrom)
(while (and (< posto len)
(> to (nth posto attr-value)))
(setq posto (1+ posto)))
(if (= posto posfrom)
(if (= (% posto 2) 1)
(if (and (< to len)
(= to (nth posto attr-value)))
(set-marker (nth posto attr-value) from)
(setcdr (nthcdr (1- posfrom) attr-value)
(cons (set-marker-type (set-marker (make-marker)
from)
'point-type)
(cons (set-marker-type (set-marker (make-marker)
to)
nil)
(nthcdr posto attr-value))))
(setcar attr-value (+ len 2))))
(if (= (% posfrom 2) 0)
(setq posfrom (1- posfrom))
(set-marker (nth posfrom attr-value) from))
(if (= (% posto 2) 0)
nil
(setq posto (1- posto))
(set-marker (nth posto attr-value) to))
(setcdr (nthcdr posfrom attr-value)
(nthcdr posto attr-value)))))
(defalias 'make-overlay 'cons)
(defun overlay-put (overlay prop value)
(let ((ret (and (eq prop 'face)
(assq value emu:available-face-attribute-alist)
)))
(if ret
(attribute-add-narrow-attribute (cdr ret)
(car overlay)(cdr overlay))
)))
;;; @ end
;;;
(provide 'emu-nemacs)
;;; emu-nemacs.el ends here
|