annotate lisp/compat.el @ 5794:2d20d57d4e7b

Do not build or ship the texinfo info files. They are available from the texinfo distribution, and break the build for some versions of makeinfo. See xemacs-patches message with ID <CAHCOHQ=EERhpe14cMzWjp286TzNHuw8ez-L-uy6kjoRPZE3b3A@mail.gmail.com>.
author Jerry James <james@xemacs.org>
date Wed, 07 May 2014 13:33:50 -0600
parents 91b3aa59f49b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
1 ;;; compat.el --- Mechanism for non-intrusively providing compatibility funs.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
2
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
3 ;; Copyright (C) 2000, 2002 Ben Wing.
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
4
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
5 ;; Author: Ben Wing <ben@xemacs.org>
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
6 ;; Maintainer: Ben Wing
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
7 ;; Keywords: internal
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
8
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
10
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5182
diff changeset
11 ;; XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5182
diff changeset
12 ;; under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5182
diff changeset
13 ;; Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5182
diff changeset
14 ;; option) any later version.
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
15
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5182
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5182
diff changeset
17 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5182
diff changeset
18 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5182
diff changeset
19 ;; for more details.
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
20
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5182
diff changeset
22 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
23
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
24 ;;; Synched up with: Not in FSF.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
25
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
26 ;;; Authorship:
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
27
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
28 ; Written May 2000 by Ben Wing.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
29
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
30 ;;; Commentary:
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
31
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
32 ;; The idea is to provide emulation of API's in a namespace-clean way. Lots of packages are filled with declarations such as
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
33
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
34 ;; (defalias 'gnus-overlay-get 'extent-property)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
35
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
36 ; There should be a single package to provide such compatibility code. The
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
37 ; tricky part is how to do it in a clean way, without packages interfering
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
38 ; with each other.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
39
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
40 ; The basic usage of compat is:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
41
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
42 ; (1) Each package copies compat.el and renames it, e.g. gnus-compat.el.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
43
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
44 ; (2) `compat' defines various API's that can be activated. To use them in a
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
45 ; file, first place code like this at the top of the file:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
46
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
47 ;(let ((compat-current-package 'Gnus))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
48 ; (require 'gnus-compat))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
49
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
50 ; then wrap the rest of the code like this:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
51
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
52 ; (Gnus-compat-wrap '(overlays events)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
53
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
54 ;;; Commentary
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
55
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
56 ;; blah
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
57
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
58 ;;; Code
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
59
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
60 ;(defun random-module-my-fun (bar baz)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
61 ; ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
62 ; (overlay-put overlay 'face 'bold)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
63 ; ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
64 ;)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
65 ;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
66 ;(defun ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
67 ;)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
68 ;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
69 ;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
70 ;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
71 ;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
72 ;) ;; end of (Gnus-compat)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
73
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
74 ;;;; random-module.el ends here
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
75
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
76 ; (3) What this does is implement the requested API's (in this case, the
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
77 ; overlay API from GNU Emacs and event API from XEmacs) in whichever
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
78 ; version of Emacs is running, with names such as
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
79 ; `Gnus-compat-overlay-put', and then it uses `macrolet' to map the
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
80 ; generic names in the wrapped code into namespace-clean names. The
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
81 ; result of loading `gnus-compat' leaves around only functions beginning
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
82 ; with `Gnus-compat' (or whatever prefix was specified in
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
83 ; `compat-current-package'). This way, various packages, with various
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
84 ; versions of `compat' as part of them, can coexist, with each package
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
85 ; running the version of `compat' that it's been tested with. The use of
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
86 ; `macrolet' ensures that only code that's lexically wrapped -- not code
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
87 ; that's called from that code -- is affected by the API mapping.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
88
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
89 ;; Typical usage:
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
90
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
91 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
92 ;; 1. Wrap modules that define compatibility functions like this: ;;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
93 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
94
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
95 ;(compat-define-group 'fsf-compat)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
96
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
97 ;(compat-define-functions 'fsf-compat
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
98
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
99 ;(defun overlay-put (overlay prop value)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
100 ; "Set property PROP to VALUE in overlay OVERLAY."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
101 ; (set-extent-property overlay prop value))
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
102
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
103 ;(defun make-overlay (beg end &optional buffer front-advance rear-advance)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
104 ; ...)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
105
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
106 ;...
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
107
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
108 ;) ;; end of (compat-define-group 'fsf-compat)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
109
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
110 ;;;; overlay.el ends here
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
111
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
112
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
114 ;; 2. Wrap modules that use the compatibility functions like this: ;;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
115 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
116
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
117 ;(let ((compat-current-package 'gnus))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
118 ; (require 'gnus-compat))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
119 ;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
120 ;(gnus-compat 'fsf-compat
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
121 ;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
122 ;; Code:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
123 ;;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
124 ;;
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
125 ;(defun random-module-my-fun (bar baz)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
126 ; ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
127 ; (overlay-put overlay 'face 'bold)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
128 ; ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
129 ;)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
130 ;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
131 ;(defun ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
132 ;)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
133 ;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
134 ;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
135 ;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
136 ;
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
137 ;) ;; end of (compat 'fsf-compat)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
138
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
139 ;;;; random-module.el ends here
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
140
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
141 (defvar compat-current-package)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
142
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
143 (eval-when-compile
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
144 (setq compat-current-package 'compat))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
145
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
146 ;; #### not yet working
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
147 '(
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
148
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
149 (defmacro compat-define-compat-functions (&rest body)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
150 "Define the functions of the `compat' package in a namespace-clean way.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
151 This relies on `compat-current-package' being set. If `compat-current-package'
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
152 is equal to the symbol `foo', and within BODY is something like
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
153
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
154 \(defmacro compat-define-group (group)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
155 ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
156 )
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
157
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
158 then this turns into
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
159
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
160 \(defmacro foo-compat-define-group (group)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
161 ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
162 )
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
163
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
164 and all calls are replaced accordingly.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
165
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
166
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
167
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
168
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
169 Functions such as
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
170 compatibility functions in GROUP.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
171 You should simply wrap this around the code that defines the functions.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
172 Any functions and macros defined at top level using `defun' or `defmacro'
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
173 will be noticed and added to GROUP. Other top-level code will be executed
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
174 normally. All code and definitions in this group can safely reference any
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
175 other functions in this group -- the code is effectively wrapped in a
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
176 `compat' call. You can call `compat-define-functions' more than once, if
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
177 necessary, for a single group.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
178
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
179 What actually happens is that the functions and macros defined here are in
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
180 fact defined using names prefixed with GROUP. To use these functions,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
181 wrap any calling code with the `compat' macro, which lexically renames
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
182 the function and macro calls appropriately."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
183 (let ((prefix (if (boundp 'compat-current-package)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
184 compat-current-package
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
185 (error
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
186 "`compat-current-package' must be defined when loading this module")))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
187 (defs-to-munge '(defun defmacro))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
188 mappings)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
189 (if (symbolp prefix) (setq prefix (symbol-name prefix)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
190 ;; first, note all defuns and defmacros
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
191 (let (fundef
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
192 (body-tail body))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
193 (while body-tail
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
194 (setq fundef (car body-tail))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
195 (when (and (consp fundef) (memq (car fundef) defs-to-munge))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
196 (push (cons (second fundef) (third fundef)) mappings))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
197 (setq body-tail (cdr body-tail))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
198 ;; now, munge the definitions with the new names
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
199 (let (fundef
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
200 (body-tail body)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
201 result
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
202 defs)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
203 (while body-tail
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
204 (setq fundef (car body-tail))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
205 (push
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
206 (cond ((and (consp fundef) (memq (car fundef) defs-to-munge))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
207 (nconc (list (car fundef)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
208 (intern (concat prefix "-"
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
209 (symbol-name (second fundef))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
210 (third fundef))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
211 (nthcdr 3 fundef)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
212 (t fundef))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
213 result)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
214 (setq body-tail (cdr body-tail)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
215 (setq result (nreverse result))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
216 ;; now, generate the munged code, with the references to the functions
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
217 ;; macroletted
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
218 (mapc
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
219 #'(lambda (acons)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
220 (let ((fun (car acons))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
221 (args (cdr acons)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
222 (push
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
223 (list fun args
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
224 (nconc
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
225 (list 'list
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
226 (list 'quote
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
227 (intern (concat prefix "-"
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
228 (symbol-name fun)))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
229 args))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
230 defs)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
231 mappings)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
232 ;; it would be cleaner to use `lexical-let' instead of `let', but that
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
233 ;; causes function definitions to have obnoxious, unreadable junk in
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
234 ;; them. #### Move `lexical-let' into C!!!
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
235 `(macrolet ((compat-current-package () ,compat-current-package)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
236 ,@defs)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
237 ,@result))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
238
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
239 (compat-define-compat-functions
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
240
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
241 (defun compat-hash-table (group)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
242 (get group 'compat-table))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
243
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
244 (defun compat-make-hash-table (group)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
245 (put group 'compat-table (make-hash-table)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
246
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
247 (defmacro compat-define-group (group &rest body)
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
248 "Define GROUP as a group of compatibility functions.
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
249 This macro should wrap individual Individual functions are defined using `compat-define-functions'.
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
250 Once defined, the functions can be used by wrapping your code in the
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
251 `compat' macro.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
252
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
253 If GROUP is already defined, nothing happens."
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
254 (let ((group (eval group)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
255 (or (hash-table-p (compat-hash-table group))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
256 (compat-make-hash-table group))))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
257
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
258 (defmacro compat-clear-functions (group)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
259 "Clear all defined functions and macros out of GROUP."
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
260 (let ((group (eval group)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
261 (clrhash (compat-hash-table group))))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
262
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
263 (defmacro compat-defun (args &rest body)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
264
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
265 (defmacro compat-define-function (props name arglist &rest body)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
266 "Define a compatibility function.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
267 PROPS are properties controlling how the function should be defined.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
268 control how the should simply wrap this around the code that defines the functions.
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
269 Any functions and macros defined at top level using `defun' or `defmacro'
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
270 will be noticed and added to GROUP. Other top-level code will be executed
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
271 normally. All code and definitions in this group can safely reference any
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
272 other functions in this group -- the code is effectively wrapped in a
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
273 `compat' call. You can call `compat-define-functions' more than once, if
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
274 necessary, for a single group.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
275
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
276 What actually happens is that the functions and macros defined here are in
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
277 fact defined using names prefixed with GROUP. To use these functions,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
278 wrap any calling code with the `compat' macro, which lexically renames
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
279 the function and macro calls appropriately."
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
280 (let ((group (eval group))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
281 (defs-to-munge '(defun defmacro))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
282 )
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
283 (let (fundef
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
284 (body-tail body))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
285 (while body-tail
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
286 (setq fundef (car body-tail))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
287 (when (and (consp fundef) (memq (car fundef) defs-to-munge))
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
288 (puthash (second fundef) (third fundef) (compat-hash-table group)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
289 (setq body-tail (cdr body-tail))))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
290 (let (fundef
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
291 (body-tail body)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
292 result)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
293 (while body-tail
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
294 (setq fundef (car body-tail))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
295 (push
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
296 (cond ((and (consp fundef) (memq (car fundef) defs-to-munge))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
297 (nconc (list (car fundef)
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
298 (intern (concat (symbol-name group) "-"
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
299 (symbol-name (second fundef))))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
300 (third fundef))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
301 (nthcdr 3 fundef)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
302 (t fundef))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
303 result)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
304 (setq body-tail (cdr body-tail)))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
305 (nconc (list 'compat-wrap (list 'quote group)) (nreverse result)))))
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
306
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
307 (defvar compat-active-groups nil)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
308
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
309 (defun compat-fboundp (groups fun)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
310 "T if FUN is either `fboundp' or one of the compatibility funs in GROUPS.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
311 GROUPS is a list of compatibility groups as defined using
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
312 `compat-define-group'."
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
313 (or (fboundp fun)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
314 (block nil
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
315 (mapcar #'(lambda (group)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
316 (if (gethash fun (compat-hash-table group))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
317 (return t)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
318 groups))))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
319
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
320 (defmacro compat-wrap-runtime (groups &rest body))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
321
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
322 (defmacro compat-wrap (groups &rest body)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
323 "Make use of compatibility functions and macros in GROUPS.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
324 GROUPS is a symbol, an API group, or list of API groups. Each API group
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
325 defines a set of functions, macros, variables, etc. and that will (or
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
326 should ideally) work on all recent versions of both GNU Emacs and XEmacs,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
327 and (to some extent, depending on how the functions were designed) on older
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
328 version. When this function is used, it will generally not be named
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
329 `compat-wrap', but have some name such as `Gnus-compat-wrap', if this is
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
330 wrapping something in `gnus'. (The renaming happened when the `compat'
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
331 package was loaded -- see discussion at top).
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
332
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
333 To use `compat' in your package (assume your package is `gnus'), you first
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
334 have to do a bit if setup.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
335
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
336 -- Copy and rename compat.el, e.g. to `gnus-compat.el'. The name must be
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
337 globally unique across everything on the load path (that means all
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
338 packages).
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
339 -- Incude this file in your package. It will not interfere with any other
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
340 versions of compat (earlier, later, etc.) provided in other packages
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
341 and similarly renamed.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
342
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
343 To make use of the API's provided:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
344
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
345 -- First place code like this at the top of the file, after the copyright
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
346 notices and comments:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
347
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
348 \(let ((compat-current-package 'Gnus))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
349 (require 'gnus-compat))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
350
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
351 -- then wrap the rest of the code like this, assuming you want access to
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
352 the GNU Emacs overlays API, and the XEmacs events API:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
353
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
354 \(Gnus-compat-wrap '(overlays xem-events)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
355
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
356 ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
357 ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
358 ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
359
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
360 \(defun gnus-random-fun (overlay baz)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
361 ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
362 (overlay-put overlay 'face 'bold)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
363 ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
364 )
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
365
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
366 ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
367 ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
368
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
369 \(defun gnus-random-fun-2 (event)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
370 (interactive "e")
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
371 (let ((x (event-x event))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
372 (y (event-y event)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
373 ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
374 )
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
375 )
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
376
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
377 ) ;; end of (Gnus-compat)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
378
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
379 ;;;; random-module.el ends here
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
380
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
381 Both the requested API's will be implemented whichever version of Emacs
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
382 \(GNU Emacs, XEmacs, etc.) is running, and (with limitations) on older
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
383 versions as well. Furthermore, the API's are provided *ONLY* to code
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
384 that's actually, lexically wrapped by `compat-wrap' (or its renamed
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
385 version). All other code, including code that's called by the wrapped
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
386 code, is not affected -- e.g. if we're on XEmacs, and `overlay-put' isn't
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
387 normally defined, then it won't be defined in code other than the wrapped
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
388 code, even if the wrapped code calls that code. Clever, huh?
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
389
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
390 What happens is that the `compat-wrap' actually uses `macrolet' to
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
391 inline-substitute calls to `overlay-put' to (in this case)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
392 `Gnus-compat-overlay-put', which was defined when `gnus-compat' was loaded.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
393
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
394 What happens is that is implement the requested API's (in this case, the
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
395 overlay API from GNU Emacs and event API from XEmacs) in whichever
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
396 version of Emacs is running, with names such as
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
397 `Gnus-compat-overlay-put', and then it uses `macrolet' to map the
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
398 generic names in the wrapped code into namespace-clean names. The
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
399 result of loading `gnus-compat' leaves around only functions beginning
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
400 with `Gnus-compat' (or whatever prefix was specified in
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
401 `compat-current-package'). This way, various packages, with various
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
402 versions of `compat' as part of them, can coexist, with each package
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
403 running the version of `compat' that it's been tested with. The use of
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
404 `macrolet' ensures that only code that's lexically wrapped -- not code
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
405 that's called from that code -- is affected by the API mapping.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
406
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
407 Before using `compat'
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
408
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
409 For any file where you want to make use of one or more API's provided by
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
410 `compat', first do this:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
411
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
412 Wrap a call to `compat-wrap' around your entire file, like this:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
413
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
414 ;; First, you copied compat.el into your package -- we're assuming \"gnus\" --
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
415 ;; and renamed it, e.g. gnus-compat.el. Now we load it and tell it to
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
416 ;; use `Gnus' as the prefix for all stuff it defines. (Use a capital letter
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
417 ;; or some similar convention so that these names are not so easy to see.)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
418
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
419 \(let ((current-compat-package 'Gnus))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
420 (require 'gnus-compat))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
421
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
422 ;; The function `compat-wrap' was mapped to `Gnus-compat-wrap'. The idea
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
423 ;; is that the raw functions beginning with `compat-' are never actually
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
424 ;; defined. They may appear as function calls inside of functions, but
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
425 ;; they will always be mapped to something beginning with the given prefix.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
426
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
427 \(Gnus-compat-wrap '(overlays xem-events)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
428
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
429 ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
430
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
431 )
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
432
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
433 You should simply wrap this around the code that uses the functions
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
434 and macros in GROUPS. Typically, a call to `compat' should be placed
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
435 at the top of an ELisp module, with the closing parenthesis at the
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
436 bottom; use this in place of a `require' statement. Wrapped code can
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
437 be either function or macro definitions or other ELisp code, and
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
438 wrapped function or macro definitions need not be at top level. All
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
439 calls to the compatibility functions or macros will be noticed anywhere
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
440 within the wrapped code. Calls to `fboundp' within the wrapped code
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
441 will also behave correctly when called on compatibility functions and
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
442 macros, even though they would return nil elsewhere (including in code
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
443 in other modules called dynamically from the wrapped code).
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
444
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
445 The functions and macros define in GROUP are actually defined under
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
446 prefixed names, to avoid namespace clashes and bad interactions with
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
447 other code that calls `fboundp'. All calls inside of the wrapped code
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
448 to the compatibility functions and macros in GROUP are lexically
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
449 mapped to the prefixed names. Since this is a lexical mapping, code
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
450 in other modules that is called by functions in this module will not
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
451 be affected."
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
452 (let ((group (eval group))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
453 defs)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
454 (maphash
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
455 #'(lambda (fun args)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
456 (push
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
457 (list fun args
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
458 (nconc
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
459 (list 'list
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
460 (list 'quote
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
461 (intern (concat (symbol-name group) "-"
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
462 (symbol-name fun)))))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
463 args))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
464 defs))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
465 (compat-hash-table group))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
466 ;; it would be cleaner to use `lexical-let' instead of `let', but that
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
467 ;; causes function definitions to have obnoxious, unreadable junk in
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
468 ;; them. #### Move `lexical-let' into C!!!
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
469 `(let ((compat-active-groups (cons ',group compat-active-groups)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
470 (macrolet ((fboundp (fun) `(compat-fboundp ',compat-active-groups ,fun))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
471 ,@defs)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
472 ,@body))))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
473
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
474 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
475 ;; Define the compat groups ;;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
476 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
477
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
478 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; overlays ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
479
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
480 (compat-define-group 'overlays
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
481
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
482 (defun-compat overlayp (object)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
483 "Return t if OBJECT is an overlay."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
484 (and (extentp object)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
485 (extent-property object 'overlay)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
486
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
487 (defun-compat make-overlay (beg end &optional buffer front-advance rear-advance)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
488 "Create a new overlay with range BEG to END in BUFFER.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
489 If omitted, BUFFER defaults to the current buffer.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
490 BEG and END may be integers or markers.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
491 The fourth arg FRONT-ADVANCE, if non-nil, makes the
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
492 front delimiter advance when text is inserted there.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
493 The fifth arg REAR-ADVANCE, if non-nil, makes the
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
494 rear delimiter advance when text is inserted there."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
495 (if (null buffer)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
496 (setq buffer (current-buffer))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
497 (check-argument-type 'bufferp buffer))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
498 (when (> beg end)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
499 (setq beg (prog1 end (setq end beg))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
500
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
501 (let ((overlay (make-extent beg end buffer)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
502 (set-extent-property overlay 'overlay t)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
503 (if front-advance
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
504 (set-extent-property overlay 'start-open t)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
505 (set-extent-property overlay 'start-closed t))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
506 (if rear-advance
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
507 (set-extent-property overlay 'end-closed t)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
508 (set-extent-property overlay 'end-open t))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
509
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
510 overlay))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
511
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
512 (defun-compat move-overlay (overlay beg end &optional buffer)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
513 "Set the endpoints of OVERLAY to BEG and END in BUFFER.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
514 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
515 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
516 buffer."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
517 (check-argument-type 'overlayp overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
518 (if (null buffer)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
519 (setq buffer (extent-object overlay)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
520 (if (null buffer)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
521 (setq buffer (current-buffer)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
522 (check-argument-type 'bufferp buffer)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
523 (and (= beg end)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
524 (extent-property overlay 'evaporate)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
525 (delete-overlay overlay))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
526 (when (> beg end)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
527 (setq beg (prog1 end (setq end beg))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
528 (set-extent-endpoints overlay beg end buffer)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
529 overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
530
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
531 (defun-compat delete-overlay (overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
532 "Delete the overlay OVERLAY from its buffer."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
533 (check-argument-type 'overlayp overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
534 (detach-extent overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
535 nil)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
536
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
537 (defun-compat overlay-start (overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
538 "Return the position at which OVERLAY starts."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
539 (check-argument-type 'overlayp overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
540 (extent-start-position overlay))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
541
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
542 (defun-compat overlay-end (overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
543 "Return the position at which OVERLAY ends."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
544 (check-argument-type 'overlayp overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
545 (extent-end-position overlay))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
546
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
547 (defun-compat overlay-buffer (overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
548 "Return the buffer OVERLAY belongs to."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
549 (check-argument-type 'overlayp overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
550 (extent-object overlay))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
551
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
552 (defun-compat overlay-properties (overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
553 "Return a list of the properties on OVERLAY.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
554 This is a copy of OVERLAY's plist; modifying its conses has no effect on
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
555 OVERLAY."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
556 (check-argument-type 'overlayp overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
557 (extent-properties overlay))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
558
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
559 (defun-compat overlays-at (pos)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
560 "Return a list of the overlays that contain position POS."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
561 (overlays-in pos pos))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
562
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
563 (defun-compat overlays-in (beg end)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
564 "Return a list of the overlays that overlap the region BEG ... END.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
565 Overlap means that at least one character is contained within the overlay
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
566 and also contained within the specified region.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
567 Empty overlays are included in the result if they are located at BEG
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
568 or between BEG and END."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
569 (if (featurep 'xemacs)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
570 (mapcar-extents #'identity nil nil beg end
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
571 'all-extents-closed-open 'overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
572 (let ((ovls (overlay-lists))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
573 tmp retval)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
574 (if (< end beg)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
575 (setq tmp end
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
576 end beg
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
577 beg tmp))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
578 (setq ovls (nconc (car ovls) (cdr ovls)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
579 (while ovls
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
580 (setq tmp (car ovls)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
581 ovls (cdr ovls))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
582 (if (or (and (<= (overlay-start tmp) end)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
583 (>= (overlay-start tmp) beg))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
584 (and (<= (overlay-end tmp) end)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
585 (>= (overlay-end tmp) beg)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
586 (setq retval (cons tmp retval))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
587 retval)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
588
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
589 (defun-compat next-overlay-change (pos)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
590 "Return the next position after POS where an overlay starts or ends.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
591 If there are no more overlay boundaries after POS, return (point-max)."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
592 (let ((next (point-max))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
593 tmp)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
594 (map-extents
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
595 (lambda (overlay ignore)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
596 (when (or (and (< (setq tmp (extent-start-position overlay)) next)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
597 (> tmp pos))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
598 (and (< (setq tmp (extent-end-position overlay)) next)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
599 (> tmp pos)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
600 (setq next tmp))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
601 nil)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
602 nil pos nil nil 'all-extents-closed-open 'overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
603 next))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
604
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
605 (defun-compat previous-overlay-change (pos)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
606 "Return the previous position before POS where an overlay starts or ends.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
607 If there are no more overlay boundaries before POS, return (point-min)."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
608 (let ((prev (point-min))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
609 tmp)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
610 (map-extents
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
611 (lambda (overlay ignore)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
612 (when (or (and (> (setq tmp (extent-end-position overlay)) prev)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
613 (< tmp pos))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
614 (and (> (setq tmp (extent-start-position overlay)) prev)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
615 (< tmp pos)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
616 (setq prev tmp))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
617 nil)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
618 nil nil pos nil 'all-extents-closed-open 'overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
619 prev))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
620
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
621 (defun-compat overlay-lists ()
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
622 "Return a pair of lists giving all the overlays of the current buffer.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
623 The car has all the overlays before the overlay center;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
624 the cdr has all the overlays after the overlay center.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
625 Recentering overlays moves overlays between these lists.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
626 The lists you get are copies, so that changing them has no effect.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
627 However, the overlays you get are the real objects that the buffer uses."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
628 (or (boundp 'xemacs-internal-overlay-center-pos)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
629 (overlay-recenter (1+ (/ (- (point-max) (point-min)) 2))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
630 (let ((pos xemacs-internal-overlay-center-pos)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
631 before after)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
632 (map-extents (lambda (overlay ignore)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
633 (if (> pos (extent-end-position overlay))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
634 (push overlay before)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
635 (push overlay after))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
636 nil)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
637 nil nil nil nil 'all-extents-closed-open 'overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
638 (cons (nreverse before) (nreverse after))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
639
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
640 (defun-compat overlay-recenter (pos)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
641 "Recenter the overlays of the current buffer around position POS."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
642 (set (make-local-variable 'xemacs-internal-overlay-center-pos) pos))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
643
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
644 (defun-compat overlay-get (overlay prop)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
645 "Get the property of overlay OVERLAY with property name PROP."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
646 (check-argument-type 'overlayp overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
647 (let ((value (extent-property overlay prop))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
648 category)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
649 (if (and (null value)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
650 (setq category (extent-property overlay 'category)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
651 (get category prop)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
652 value)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
653
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
654 (defun-compat overlay-put (overlay prop value)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
655 "Set one property of overlay OVERLAY: give property PROP value VALUE."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
656 (check-argument-type 'overlayp overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
657 (cond ((eq prop 'evaporate)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
658 (set-extent-property overlay 'detachable value))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
659 ((eq prop 'before-string)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
660 (set-extent-property overlay 'begin-glyph
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
661 (make-glyph (vector 'string :data value))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
662 ((eq prop 'after-string)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
663 (set-extent-property overlay 'end-glyph
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
664 (make-glyph (vector 'string :data value))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
665 ((eq prop 'local-map)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
666 (set-extent-property overlay 'keymap value))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
667 ((memq prop '(window insert-in-front-hooks insert-behind-hooks
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
668 modification-hooks))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
669 (error "cannot support overlay '%s property under XEmacs"
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
670 prop)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
671 (set-extent-property overlay prop value))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
672 )
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
673
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
674 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; extents ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
675
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
676 (defalias-compat 'delete-extent 'delete-overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
677 (defalias-compat 'extent-end-position 'overlay-end)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
678 (defalias-compat 'extent-start-position 'overlay-start)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
679 (defalias-compat 'set-extent-endpoints 'move-overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
680 (defalias-compat 'set-extent-property 'overlay-put)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
681 (defalias-compat 'make-extent 'make-overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
682
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
683 (defun-compat extent-property (extent property &optional default)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
684 (or (overlay-get extent property) default))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
685
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
686 (defun-compat extent-at (pos &optional object property before at-flag)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
687 (let ((tmp (overlays-at (point)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
688 ovls)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
689 (if property
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
690 (while tmp
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
691 (if (extent-property (car tmp) property)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
692 (setq ovls (cons (car tmp) ovls)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
693 (setq tmp (cdr tmp)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
694 (setq ovls tmp
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
695 tmp nil))
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 826
diff changeset
696 (car (sort* ovls #'< :key #'extent-length))))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
697
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
698 (defun-compat map-extents (function &optional object from to
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
699 maparg flags property value)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
700 (let ((tmp (overlays-in (or from (point-min))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
701 (or to (point-max))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
702 ovls)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
703 (if property
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
704 (while tmp
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
705 (if (extent-property (car tmp) property)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
706 (setq ovls (cons (car tmp) ovls)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
707 (setq tmp (cdr tmp)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
708 (setq ovls tmp
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
709 tmp nil))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
710 (catch 'done
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
711 (while ovls
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
712 (setq tmp (funcall function (car ovls) maparg)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
713 ovls (cdr ovls))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
714 (if tmp
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
715 (throw 'done tmp))))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
716
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
717 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; extents ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
718
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
719
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
720 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; events ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
721
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
722 ) ;; group overlays
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
723
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
724 ) ;; compat-define-compat-functions
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
725
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
726 (fmakunbound 'compat-define-compat-functions)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
727
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5182
diff changeset
728
5404
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5402
diff changeset
729 )