(write-region-as-raw-text-CRLF): Use `write-region-as-binary' to
[elisp/apel.git] / emu-e20_2.el
1 ;;; emu-e20_2.el --- emu API implementation for Emacs 20.1 and 20.2
2
3 ;; Copyright (C) 1996,1997,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 emu.
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 ;;; Commentary:
26
27 ;;    This module requires Emacs 20.1 and 20.2.
28
29 ;;; Code:
30
31 ;;; @ buffer representation
32 ;;;
33
34 (defsubst-maybe set-buffer-multibyte (flag)
35   "Set the multibyte flag of the current buffer to FLAG.
36 If FLAG is t, this makes the buffer a multibyte buffer.
37 If FLAG is nil, this makes the buffer a single-byte buffer.
38 The buffer contents remain unchanged as a sequence of bytes
39 but the contents viewed as characters do change.
40 \[Emacs 20.3 emulating function]"
41   (setq enable-multibyte-characters flag)
42   )
43
44
45 ;;; @ character
46 ;;;
47
48 (defalias 'char-length 'char-bytes)
49
50 (defmacro char-next-index (char index)
51   "Return index of character succeeding CHAR whose index is INDEX."
52   `(+ ,index (char-bytes ,char)))
53
54
55 ;;; @ string
56 ;;;
57
58 (defalias 'sset 'store-substring)
59
60 (defun string-to-char-list (string)
61   "Return a list of which elements are characters in the STRING."
62   (let* ((len (length string))
63          (i 0)
64          l chr)
65     (while (< i len)
66       (setq chr (sref string i))
67       (setq l (cons chr l))
68       (setq i (+ i (char-bytes chr)))
69       )
70     (nreverse l)
71     ))
72
73 (defalias 'string-to-int-list 'string-to-char-list)
74
75 (defun looking-at-as-unibyte (regexp)
76   "Like `looking-at', but string is regarded as unibyte sequence."
77   (let (enable-multibyte-characters)
78     (looking-at regexp)
79     ))
80
81 ;;; @@ obsoleted aliases
82 ;;;
83 ;;; You should not use them.
84
85 (defalias 'string-columns 'string-width)
86 (make-obsolete 'string-columns 'string-width)
87
88
89 ;;; @ without code-conversion
90 ;;;
91
92 (defun insert-file-contents-as-binary (filename
93                                        &optional visit beg end replace)
94   "Like `insert-file-contents', q.v., but don't code and format conversion.
95 Like `insert-file-contents-literary', but it allows find-file-hooks,
96 automatic uncompression, etc.
97
98 Namely this function ensures that only format decoding and character
99 code conversion will not take place."
100   (let ((flag enable-multibyte-characters)
101         (coding-system-for-read 'binary)
102         format-alist)
103     (insert-file-contents filename visit beg end replace)
104     (set-buffer-multibyte flag)
105     ))
106
107 (defun insert-file-contents-as-raw-text (filename
108                                          &optional visit beg end replace)
109   "Like `insert-file-contents', q.v., but don't code and format conversion.
110 Like `insert-file-contents-literary', but it allows find-file-hooks,
111 automatic uncompression, etc.
112 Like `insert-file-contents-as-binary', but it converts line-break
113 code."
114   (let ((flag enable-multibyte-characters)
115         (coding-system-for-read 'raw-text)
116         format-alist)
117     (insert-file-contents filename visit beg end replace)
118     (set-buffer-multibyte flag)
119     ))
120
121
122 ;;; @ end
123 ;;;
124
125 (provide 'emu-e20_2)
126
127 ;;; emu-e20_2.el ends here