1 ;;; tinylibxe.el --- Compatibility library for both Emacs and XEmacs
3 ;; This file is not part of Emacs
7 ;; Copyright (C) 1997-2007 Jari Aalto
8 ;; Keywords: extensions
10 ;; Maintainer: Jari Aalto
12 ;; To get information on this program, call M-x tilibxe-version.
13 ;; Look at the code with folding.el
17 ;; This program is free software; you can redistribute it and/or modify it
18 ;; under the terms of the GNU General Public License as published by the Free
19 ;; Software Foundation; either version 2 of the License, or (at your option)
22 ;; This program is distributed in the hope that it will be useful, but
23 ;; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 ;; You should have received a copy of the GNU General Public License
28 ;; along with program; see the file COPYING. If not, write to the
29 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
30 ;; Boston, MA 02110-1301, USA.
32 ;; Visit <http://www.gnu.org/copyleft/gpl.html> for more information
37 ;; ........................................................ &t-install ...
38 ;; Put this file on your Emacs-Lisp load path, add following into your
39 ;; package that you're currently developing. This ensures compatibility
40 ;; for some extent to XEmacs and Emacs.
42 ;; (require 'tinylibxe)
47 ;; ..................................................... &t-commentary ...
53 ;; o This is library, package itself does nothing.
54 ;; o Compatibility for both Emacsen, XEmacs and Emacs
55 ;; o Compatibility for older Emacsen. Code written using later Emacs
56 ;; versions can be run under lower Emacs version. (e.g.
57 ;; `require' includes extra parameters in later Emacs versions.
59 ;; There are incompatibilities between XEmacs and Emacs which
60 ;; prevent writing portable code. The bigger problematic things
61 ;; have been collected here. The trivial ones have been implemented
62 ;; in lower level libraries like in backward compatibility
63 ;; library *tinylibb.el*.
65 ;; Overlay.el in XEmacs 19.15+
67 ;; Good news; Latest XEmacs includes package that emulates
68 ;; Emacs overlay functions. Load it under XEmacs, if you run code
69 ;; written using Emacs.
71 ;; What you should know -- keep this in mind
73 ;; This library's intention is to make it possible to use some package
74 ;; that is written only for Emacs. Normally it is not possible to use
75 ;; package under another Emacs, because there may be function calls
76 ;; that depend on Emacs flavor.
78 ;; When this file is loaded, it emulates unknown functions as much as
79 ;; it can. However, it may not be possible to reproduce exactly the
80 ;; same behavior that was not the primary target for the package. The
81 ;; emulation may at worst case be only so, that you are able to load
82 ;; the package without errors, but the functionality of the package
83 ;; doesn't correspond to the original's.
96 ;;{{{ setup: -- version
98 (defconst tinylibxe-version
100 "Latest version number.")
102 (defconst tinylibxe-version-id
103 "$Id: tinylibxe.el,v 2.49 2007/05/07 10:50:08 jaalto Exp $"
104 "Latest modification time and version number.")
106 (defun tinylibxe-version (&optional arg)
107 "version information."
109 (ti::package-version-info "tinylibxe.el" arg))
111 (defun tinylibxe-submit-bug-report ()
114 (ti::package-submit-bug-report
117 '(tinylibxe-version-id)))
120 ;;{{{ events, window, frames, misc
124 (defalias 'event-window 'posn-window)
125 (defalias 'event-point 'posn-point)
126 (defalias 'event-timestamp 'posn-timestamp)
127 (defalias 'window-pixel-edges 'window-edges))
129 (defalias 'posn-window 'event-window)
130 (defalias 'posn-window 'event-window)
131 (defalias 'posn-point 'event-point)
132 (defalias 'posn-timestamp 'event-timestamp)
133 ;;; (defalias 'posn-col-row ')
134 (defalias 'window-edges 'window-pixel-edges)))
138 (ti::fboundp-check-autoload 'button-release-event-p "tinylibxe"
139 ;; XEmacs function missing from Emacs.
140 (defun button-release-event-p (event)
141 "Non-nil if EVENT is a mouse-button-release event object."
143 (memq (ti::funcall 'event-basic-type event)
144 '(mouse-1 mouse-2 mouse-3))
145 (or (memq 'click (event-modifiers event))
146 (memq 'drag (event-modifiers event))))))
148 (ti::fboundp-check-autoload 'event-start "tinylibxe"
149 (defun event-start (event)
151 ;; In Emacs (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
153 (ti::funcall 'event-window event)
154 (ti::funcall 'event-point event)
155 (ti::funcall 'posn-x-y event)
156 (ti::funcall 'event-timestamp event))))
158 (ti::fboundp-check-autoload 'event-x "tinylibxe"
159 (defun event-x (event)
161 (let* ((data (ti::funcall 'event-start event)))
164 (ti::fboundp-check-autoload 'event-y "tinylibxe"
165 (defun event-y (event)
167 (let* ((data (ti::funcall 'event-start event)))
170 (ti::fboundp-check-autoload 'posn-x-y "tinylibxe"
171 (defun posn-x-y (event)
173 (cons (ti::funcall 'event-x event) (ti::funcall 'event-y event))))
175 (when (and (not (fboundp 'frame-parameters)) ;obsolete in 19.14
176 (boundp 'frame-properties))
177 (defun frame-parameters (&optional frame)
178 "Return FRAME parameters."
179 ;; Emacs ((arg1 . val) (arg2 . val) ..)
180 ;; XEmacs (arg val arg2 val)
181 (ti::list-to-cons (ti::funcall 'frame-properties))))
186 ;;; XEmacs /Emacs don't have compatible faces
188 (and (not (fboundp 'x-display-color-p))
189 (fboundp 'device-class)
190 (defalias 'x-display-color-p 'device-class))
192 (unless (ti::compat-face-p 'region)
194 (set-face-foreground 'region "white")
195 (set-face-background 'region "black"))
197 (ti::fboundp-check-autoload 'set-background-color "tinylibxe"
198 (defun set-background-color (colour)
199 "Tinylibxe. Emacs emulation"
200 (ti::funcall 'set-face-background 'default colour)))
202 (ti::fboundp-check-autoload 'set-foreground-color "tinylibxe"
203 (defun set-foreground-color (colour)
204 "Tinylibxe. Emacs emulation"
205 (ti::funcall 'set-face-foreground 'default colour)))
207 (ti::fboundp-check-autoload 'set-cursor-color "tinylibxe"
208 (defun set-cursor-color (colour)
209 "Tinylibxe. Emacs emulation"
210 (ti::funcall 'set-face-foreground 'text-cursor colour)))
212 (ti::fboundp-check-autoload 'transient-mark-mode "tinylibxe"
213 (defun transient-mark-mode (&optional mode)
214 "Tinylibxe. Emacs emulation"
216 (set 'zmacs-regions (ti::bool-toggle mode))))
223 (defalias 'dired-unmark-subdir-or-file 'dired-unmark)
224 (defalias 'dired-mark-subdir-or-file 'dired-mark)
225 (defalias 'dired-mark-get-files 'dired-get-marked-files)
226 (defalias 'dired-mark-map 'dired-map-over-marks))
228 (defalias 'dired-unmark 'dired-unmark-subdir-or-file)
229 (defalias 'dired-mark 'dired-mark-subdir-or-file)
230 (defalias 'dired-get-marked-files 'dired-mark-get-files)
231 (defalias 'dired-map-over-marks 'dired-mark-map)))
236 ;;; Thanks to Kyle Jone, kyle@wonderworks.com, in setnu.el
238 (when (and nil (ti::emacs-p)) ;; disabled now
239 (defalias 'extent-live-p 'overlayp)
240 (defalias 'extentp 'overlayp)
241 (defalias 'make-extent 'make-overlay)
242 (defalias 'delete-extent 'delete-overlay)
243 (defalias 'extent-property 'overlay-get)
244 (defalias 'set-extent-property 'overlay-put)
245 (defalias 'set-extent-endpoints 'move-overlay)
246 (defalias 'extent-end-position 'overlay-end)
247 (defalias 'extent-start-position 'overlay-start)
248 (defalias 'extent-start-position 'overlay-buffer)
249 (defalias 'extent-start-position 'overlay-buffer)
250 (defalias 'next-extent-change 'next-overlay-change)
251 (defalias 'extent-properties 'overlay-properties)
253 (defun extent-list (buffer point)
254 "tinylibxe.el -- arg3 not supported."
258 (ti::funcall 'overlays-at point)))
260 (defun extent-length (e)
261 "tinylibxe.el -- return overlay length."
262 (- (ti::funcall 'overlay-end e) (ti::funcall 'overlay-start e))))
264 (defvar ti:xe-begin-glyph-property (if (fboundp 'extent-property)
267 "Property name to use to set teh begin glyph of an extent.")
269 (ti::fboundp-check-autoload 'set-overlay-begin-glyph "tinylibxe"
270 (defun set-overlay-begin-glyph (e g)
271 "tinylibxe -- Set glyph G in overlay E."
272 (ti::funcall 'overlay-put e ti:xe-begin-glyph-property g)))
274 (ti::fboundp-check-autoload 'make-glyph "tinylibxe"
275 (defalias 'make-glyph 'identity))
279 (unless (fboundp 'set-glyph-face)
280 (defun set-glyph-face (g face)
281 "tinylibxe -- Set glyph G to FACE"
282 (put-text-property 0 (length g) 'face face g))))
285 ;;(defalias 'set-glyph-face 'ignore)
291 (when (and nil ;Idea only...
292 (not (fboundp 'easy-menu-add-item))
293 (fboundp 'add-menu-button))
294 (defun easy-menu-add-item ()
296 ((fboundp 'easy-menu-add-item) ;XEmacs 21.x
297 (easy-menu-add-item 'rest-of-the-args))
298 ((fboundp 'add-menu-button) ;XEmacs
301 ;; ["List Ediff Sessions" ediff-show-registry t] "OO-Browser...")
305 ;; support for pre FSF 20.3
309 ;;; From wid-edit.el by Per Abrahamsen <abraham@dina.kvl.dk>
310 (when (and (not (fboundp 'error-message-string))
311 (fboundp 'display-error))
312 ;; Emacs function missing in XEmacs.
313 (defun error-message-string (obj)
314 "Convert an error value to an error message."
315 (let ((buffer (get-buffer-create " *error-message*")))
316 (with-current-buffer buffer
318 ;; Only exist in new emacs release
319 (ti::funcall 'display-error obj buffer)
322 ;; XEmacs doesn't have 'timer package; but 'itimer
323 (ti::fboundp-check-autoload 'run-at-time "tinylibxe"
324 (defun run-at-time (time repeat function &rest args)
325 "tinylibxe -- XEmacs and Emacs Compatibility."
327 ;; start-itimer: (name function value &optional restart)
328 ;; start-itimer: (NAME FUNCTION VALUE &optional RESTART IS-IDLE WITH-ARGS
329 ;; &rest FUNCTION-ARGUMENTS)
330 ;; We can't use following Emacs arguments: ARGS
331 ;; (run-at-time TIME REPEAT FUNCTION &rest ARGS)
336 (symbol-name function))
338 "itimer-with-no-name"))
339 function ;ARG2 FUNCTION
340 (if (integerp repeat) ;ARG3 VALUE
342 (if (integerp repeat) ;ARG4 &optional RESTART
345 (ti::fboundp-check-autoload 'cancel-timer "tinylibxe"
346 (defun cancel-timer (timer)
347 "tinylibxe -- XEmacs & Emacs Compatibility."
348 (ti::funcall 'delete-itimer timer)))
351 ;;{{{ advice: code from XEmacs --> Emacs
356 ;; This is same as 'beep'
357 ;; Emacs, subr.el:(defalias 'beep 'ding) ;preserve lingual purity
359 (defadvice ding (around tinylibxe (&optional arg &rest args) act)
360 "tinylibxe -- Define Xemacs compatible ding comamnd. Ignores arg 2."
363 (defadvice make-sparse-keymap (before tinylibxe (&optional no-op) act)
364 "tinylibxe -- This advice does nothing except adding an optional argument
365 to keep the byte compiler happy when compiling Emacs specific code
372 ;;; tinylibxe.el ends here