(point-at-bol): New function.
[elisp/apel.git] / emu.el
1 ;;; emu.el --- Emulation module for each Emacs variants
2
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility, NEmacs, MULE, Emacs/mule, XEmacs
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 ;;; Code:
26
27 (require 'poe)
28
29 (defvar running-emacs-18 (<= emacs-major-version 18))
30 (defvar running-xemacs (string-match "XEmacs" emacs-version))
31
32 (defvar running-mule-merged-emacs (and (not (boundp 'MULE))
33                                        (not running-xemacs) (featurep 'mule)))
34 (defvar running-xemacs-with-mule (and running-xemacs (featurep 'mule)))
35
36 (defvar running-emacs-19 (and (not running-xemacs) (= emacs-major-version 19)))
37 (defvar running-emacs-19_29-or-later
38   (or (and running-emacs-19 (>= emacs-minor-version 29))
39       (and (not running-xemacs)(>= emacs-major-version 20))))
40
41 (defvar running-xemacs-19 (and running-xemacs
42                                (= emacs-major-version 19)))
43 (defvar running-xemacs-20-or-later (and running-xemacs
44                                         (>= emacs-major-version 20)))
45 (defvar running-xemacs-19_14-or-later
46   (or (and running-xemacs-19 (>= emacs-minor-version 14))
47       running-xemacs-20-or-later))
48
49 (cond (running-xemacs
50        ;; for XEmacs
51        (defvar mouse-button-1 'button1)
52        (defvar mouse-button-2 'button2)
53        (defvar mouse-button-3 'button3)
54        )
55       ((>= emacs-major-version 19)
56        ;; for tm-7.106
57        (defalias 'tl:make-overlay 'make-overlay)
58        (defalias 'tl:overlay-put 'overlay-put)
59        (defalias 'tl:overlay-buffer 'overlay-buffer)
60        
61        (make-obsolete 'tl:make-overlay 'make-overlay)
62        (make-obsolete 'tl:overlay-put 'overlay-put)
63        (make-obsolete 'tl:overlay-buffer 'overlay-buffer)
64        
65        ;; mouse
66        (defvar mouse-button-1 [mouse-1])
67        (defvar mouse-button-2 [mouse-2])
68        (defvar mouse-button-3 [down-mouse-3])
69        )
70       (t
71        ;; mouse
72        (defvar mouse-button-1 nil)
73        (defvar mouse-button-2 nil)
74        (defvar mouse-button-3 nil)
75        ))
76
77 (cond (running-xemacs
78        (if (featurep 'mule)
79            ;; for XEmacs with MULE
80            (require 'emu-x20)
81          ;; for XEmacs without MULE
82          (require 'emu-latin1)
83          ))
84       (running-mule-merged-emacs
85        ;; for Emacs 20.1 and 20.2
86        (require 'emu-e20)
87        )
88       ((boundp 'MULE)
89        ;; for MULE 1.* and 2.*
90        (require 'emu-mule)
91        )
92       ((boundp 'NEMACS)
93        ;; for NEmacs and NEpoch
94        (require 'emu-nemacs)
95        )
96       (t
97        ;; for Emacs 19
98        (require 'emu-latin1)
99        ))
100
101
102 ;;; @ MIME charset
103 ;;;
104
105 (defun charsets-to-mime-charset (charsets)
106   "Return MIME charset from list of charset CHARSETS.
107 This function refers variable `charsets-mime-charset-alist'
108 and `default-mime-charset'."
109   (if charsets
110       (or (catch 'tag
111             (let ((rest charsets-mime-charset-alist)
112                   cell)
113               (while (setq cell (car rest))
114                 (if (catch 'not-subset
115                       (let ((set1 charsets)
116                             (set2 (car cell))
117                             obj)
118                         (while set1
119                           (setq obj (car set1))
120                           (or (memq obj set2)
121                               (throw 'not-subset nil))
122                           (setq set1 (cdr set1)))
123                         t))
124                     (throw 'tag (cdr cell)))
125                 (setq rest (cdr rest)))))
126           default-mime-charset)))
127
128
129 ;;; @ Emacs 20.3 emulation
130 ;;;
131
132 (defmacro-maybe string-as-unibyte (string)
133   "Return a unibyte string with the same individual bytes as STRING.
134 If STRING is unibyte, the result is STRING itself.
135 \[Emacs 20.3 emulating macro]"
136   string)
137
138 (defmacro-maybe string-as-multibyte (string)
139   "Return a multibyte string with the same individual bytes as STRING.
140 If STRING is multibyte, the result is STRING itself.
141 \[Emacs 20.3 emulating macro]"
142   string)
143
144
145 ;;; @ XEmacs emulation
146 ;;;
147
148 (defun-maybe point-at-bol (&optional n buffer)
149   "Return the character position of the first character on the current line.
150 With argument N not nil or 1, move forward N - 1 lines first.
151 If scan reaches end of buffer, return that position.
152 This function does not move point. [XEmacs emulating function]"
153   (save-excursion
154     (if buffer
155         (set-buffer buffer)
156       )
157     (line-beginning-position n)
158     ))
159
160 (defun-maybe point-at-eol (&optional n buffer)
161   "Return the character position of the last character on the current line.
162 With argument N not nil or 1, move forward N - 1 lines first.
163 If scan reaches end of buffer, return that position.
164 This function does not move point. [XEmacs emulating function]"
165   (save-excursion
166     (if buffer
167         (set-buffer buffer)
168       )
169     (line-end-position n)
170     ))
171
172
173 ;;; @ for XEmacs 20
174 ;;;
175
176 (or (fboundp 'char-int)
177     (fset 'char-int (symbol-function 'identity))
178     )
179 (or (fboundp 'int-char)
180     (fset 'int-char (symbol-function 'identity))
181     )
182 (or (fboundp 'char-or-char-int-p)
183     (fset 'char-or-char-int-p (symbol-function 'integerp))
184     )
185
186
187 ;;; @ for text/richtext and text/enriched
188 ;;;
189
190 (cond ((fboundp 'richtext-decode)
191        ;; have richtext.el
192        )
193       ((or running-emacs-19_29-or-later running-xemacs-19_14-or-later)
194        ;; have enriched.el
195        (autoload 'richtext-decode "richtext")
196        (or (assq 'text/richtext format-alist)
197            (setq format-alist
198                  (cons
199                   (cons 'text/richtext
200                         '("Extended MIME text/richtext format."
201                           "Content-[Tt]ype:[ \t]*text/richtext"
202                           richtext-decode richtext-encode t enriched-mode))
203                   format-alist)))
204        )
205       (t
206        ;; don't have enriched.el
207        (autoload 'richtext-decode "tinyrich")
208        (autoload 'enriched-decode "tinyrich")
209        ))
210
211
212 ;;; @ end
213 ;;;
214
215 (provide 'emu)
216
217 ;;; emu.el ends here