(MAKEIT.BAT): Modify for apel-ja@lists.chise.org.
[elisp/apel.git] / poe-xemacs.el
1 ;;; poe-xemacs.el --- poe submodule for XEmacs
2
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995,1996,1997,1998 MORIOKA Tomohiko
5
6 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Keywords: emulation, compatibility, XEmacs
8
9 ;; This file is part of APEL (A Portable Emacs Library).
10
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
15
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
23 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 ;; MA 02110-1301, USA.
25
26 ;;; Code:
27
28 (require 'pym)
29
30
31 ;;; @ color
32 ;;;
33
34 (defun-maybe set-cursor-color (color-name)
35   "Set the text cursor color of the selected frame to COLOR.
36 When called interactively, prompt for the name of the color to use."
37   (interactive "sColor: ")
38   (set-frame-property (selected-frame) 'cursor-color
39                       (if (color-instance-p color-name)
40                           color-name
41                         (make-color-instance color-name))))
42
43
44 ;;; @ face
45 ;;;
46
47 (defalias-maybe 'face-list 'list-faces)
48
49 (or (memq 'underline (face-list))
50     (and (fboundp 'make-face)
51          (make-face 'underline)))
52
53 (or (face-differs-from-default-p 'underline)
54     (set-face-underline-p 'underline t))
55
56
57 ;;; @ overlay
58 ;;;
59
60 (condition-case nil
61     (require 'overlay)
62   (error
63    (defalias 'make-overlay 'make-extent)
64    (defalias 'overlayp 'extentp)
65    (defalias 'overlay-put 'set-extent-property)
66    (defalias 'overlay-buffer 'extent-buffer)
67    (defun move-overlay (extent start end &optional buffer)
68      (set-extent-endpoints extent start end))
69    (defalias 'delete-overlay 'detach-extent)))
70
71
72 ;;; @ dired
73 ;;;
74
75 (defun-maybe dired-other-frame (dirname &optional switches)
76   "\"Edit\" directory DIRNAME.  Like `dired' but makes a new frame."
77   (interactive (dired-read-dir-and-switches "in other frame "))
78   (switch-to-buffer-other-frame (dired-noselect dirname switches)))
79
80
81 ;;; @ timer
82 ;;;
83
84 (condition-case nil
85     (require 'timer-funcs)
86   (error nil))
87 (condition-case nil
88     (require 'timer)
89   (error nil))
90 (or
91  (or (featurep 'timer-funcs) (featurep 'timer))
92  (progn
93    (require 'itimer)
94    (if (and (= emacs-major-version 19) (<= emacs-minor-version 14))
95        (defun-maybe run-at-time (time repeat function &rest args)
96          (start-itimer (make-temp-name "rat")
97                        `(lambda ()
98                           (,function ,@args))
99                        time repeat))
100      (defun-maybe run-at-time (time repeat function &rest args)
101        "Function emulating the function of the same name of Emacs.
102 TIME should be nil meaning now, or a number of seconds from now.
103 Return an itimer object which can be used in either `delete-itimer'
104 or `cancel-timer'."
105        (apply #'start-itimer "run-at-time"
106               function (if time (max time 1e-9) 1e-9)
107               repeat nil t args)))
108    (defalias 'cancel-timer 'delete-itimer)
109    (defun with-timeout-handler (tag)
110      (throw tag 'timeout))
111    (defmacro-maybe with-timeout (list &rest body)
112      (let ((seconds (car list))
113            (timeout-forms (cdr list)))
114        `(let ((with-timeout-tag (cons nil nil))
115               with-timeout-value with-timeout-timer)
116           (if (catch with-timeout-tag
117                 (progn
118                   (setq with-timeout-timer
119                         (run-at-time ,seconds nil
120                                      'with-timeout-handler
121                                      with-timeout-tag))
122                   (setq with-timeout-value (progn . ,body))
123                   nil))
124               (progn . ,timeout-forms)
125             (cancel-timer with-timeout-timer)
126             with-timeout-value))))))
127
128 (require 'broken)
129
130 (broken-facility run-at-time-tick-tock
131   "`run-at-time' is not punctual."
132   ;; Note that it doesn't support XEmacsen prior to the version 19.15
133   ;; since `start-itimer' doesn't pass arguments to a timer function.
134   (or (and (= emacs-major-version 19) (<= emacs-minor-version 14))
135       (condition-case nil
136           (progn
137             (unless (or itimer-process itimer-timer)
138               (itimer-driver-start))
139             ;; Check whether there is a bug to which the difference of
140             ;; the present time and the time when the itimer driver was
141             ;; woken up is subtracted from the initial itimer value.
142             (let* ((inhibit-quit t)
143                    (ctime (current-time))
144                    (itimer-timer-last-wakeup
145                     (prog1
146                         ctime
147                       (setcar ctime (1- (car ctime)))))
148                    (itimer-list nil)
149                    (itimer (start-itimer "run-at-time" 'ignore 5)))
150               (sleep-for 0.1) ;; Accept the timeout interrupt.
151               (prog1
152                   (> (itimer-value itimer) 0)
153                 (delete-itimer itimer))))
154         (error nil))))
155
156 (when-broken run-at-time-tick-tock
157   (defalias 'run-at-time
158     (lambda (time repeat function &rest args)
159       "Function emulating the function of the same name of Emacs.
160 It works correctly for TIME even if there is a bug in the XEmacs core.
161 TIME should be nil meaning now, or a number of seconds from now.
162 Return an itimer object which can be used in either `delete-itimer'
163 or `cancel-timer'."
164       (let ((itimers (list nil)))
165         (setcar
166          itimers
167          (apply #'start-itimer "fixed-run-at-time"
168                 (lambda (itimers repeat function &rest args)
169                   (let ((itimer (car itimers)))
170                     (if repeat
171                         (progn
172                           (set-itimer-function
173                            itimer
174                            (lambda (itimer repeat function &rest args)
175                              (set-itimer-restart itimer repeat)
176                              (set-itimer-function itimer function)
177                              (set-itimer-function-arguments itimer args)
178                              (apply function args)))
179                           (set-itimer-function-arguments
180                            itimer
181                            (append (list itimer repeat function) args)))
182                       (set-itimer-function
183                        itimer
184                        (lambda (itimer function &rest args)
185                          (delete-itimer itimer)
186                          (apply function args)))
187                       (set-itimer-function-arguments
188                        itimer
189                        (append (list itimer function) args)))))
190                 1e-9 (if time (max time 1e-9) 1e-9)
191                 nil t itimers repeat function args))))))
192
193
194 ;;; @ to avoid bug of XEmacs 19.14
195 ;;;
196
197 (or (string-match "^../"
198                   (file-relative-name "/usr/local/share" "/usr/local/lib"))
199     ;; This function was imported from Emacs 19.33.
200     (defun file-relative-name (filename &optional directory)
201       "Convert FILENAME to be relative to DIRECTORY
202 (default: default-directory)."
203       (setq filename (expand-file-name filename)
204             directory (file-name-as-directory
205                        (expand-file-name
206                         (or directory default-directory))))
207       (let ((ancestor ""))
208         (while (not (string-match (concat "^" (regexp-quote directory))
209                                   filename))
210           (setq directory (file-name-directory (substring directory 0 -1))
211                 ancestor (concat "../" ancestor)))
212         (concat ancestor (substring filename (match-end 0))))))
213
214
215 ;;; @ Emacs 20.3 emulation
216 ;;;
217
218 (defalias-maybe 'line-beginning-position 'point-at-bol)
219 (defalias-maybe 'line-end-position 'point-at-eol)
220
221 ;;; @ XEmacs 21 emulation
222 ;;;
223
224 ;; XEmacs 20.5 and later: (set-extent-properties EXTENT PLIST)
225 (defun-maybe set-extent-properties (extent plist)
226   "Change some properties of EXTENT.
227 PLIST is a property list.
228 For a list of built-in properties, see `set-extent-property'."
229   (while plist
230     (set-extent-property extent (car plist) (cadr plist))
231     (setq plist (cddr plist))))  
232
233 ;;; @ end
234 ;;;
235
236 (require 'product)
237 (product-provide (provide 'poe-xemacs) (require 'apel-ver))
238
239 ;;; poe-xemacs.el ends here