annotate lisp/compat.el @ 5287:cd167465bf69

More permission consistency.
author Stephen J. Turnbull <stephen@xemacs.org>
date Mon, 14 Jun 2010 15:03:08 +0900
parents 2e528066e2fc
children 308d34e9f07d
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
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
14 ;; any later version.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
15
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
19 ;; General Public License for more details.
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
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
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 ;;; Synched up with: Not in FSF.
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 ;;; Authorship:
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 ; Written May 2000 by Ben Wing.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
31
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
32 ;;; Commentary:
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
33
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
34 ;; 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
35
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
36 ;; (defalias 'gnus-overlay-get 'extent-property)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
37
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
38 ; 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
39 ; 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
40 ; with each other.
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 ; The basic usage of compat is:
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 ; (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
45
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
46 ; (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
47 ; 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
48
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
49 ;(let ((compat-current-package 'Gnus))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
50 ; (require 'gnus-compat))
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 ; 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
53
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
54 ; (Gnus-compat-wrap '(overlays events)
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 ;;; Commentary
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 ;; blah
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 ;;; Code
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 ;(defun random-module-my-fun (bar baz)
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 ; (overlay-put overlay 'face 'bold)
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 ;)
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 ;(defun ...
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 ;
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 ;) ;; end of (Gnus-compat)
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 ;;;; random-module.el ends here
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
77
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
78 ; (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
79 ; 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
80 ; 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
81 ; `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
82 ; 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
83 ; 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
84 ; 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
85 ; `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
86 ; 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
87 ; 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
88 ; `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
89 ; 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
90
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
91 ;; Typical usage:
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
92
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 ;; 1. Wrap modules that define compatibility functions like this: ;;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
95 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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-group 'fsf-compat)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
98
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
99 ;(compat-define-functions 'fsf-compat
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
100
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
101 ;(defun overlay-put (overlay prop value)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
102 ; "Set property PROP to VALUE in overlay OVERLAY."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
103 ; (set-extent-property overlay prop value))
410
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 ;(defun make-overlay (beg end &optional buffer front-advance rear-advance)
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 ;...
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 ;) ;; end of (compat-define-group 'fsf-compat)
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 ;;;; overlay.el ends here
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
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 ;; 2. Wrap modules that use the compatibility functions like this: ;;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
117 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
118
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
119 ;(let ((compat-current-package 'gnus))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
120 ; (require 'gnus-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 ;(gnus-compat 'fsf-compat
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 ;; Code:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
125 ;;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
126 ;;
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
127 ;(defun random-module-my-fun (bar baz)
826
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 ; (overlay-put overlay 'face 'bold)
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 ;)
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 ;(defun ...
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 ;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
137 ;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
138 ;
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
139 ;) ;; end of (compat 'fsf-compat)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
140
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
141 ;;;; random-module.el ends here
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
142
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
143 (defvar compat-current-package)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
144
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
145 (eval-when-compile
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
146 (setq compat-current-package 'compat))
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 ;; #### not yet working
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
149 '(
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
150
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
151 (defmacro compat-define-compat-functions (&rest body)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
152 "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
153 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
154 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
155
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
156 \(defmacro compat-define-group (group)
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 )
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 then this turns into
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 \(defmacro foo-compat-define-group (group)
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 )
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 and all calls are replaced accordingly.
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
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
170
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
171 Functions such as
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
172 compatibility functions in GROUP.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
173 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
174 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
175 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
176 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
177 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
178 `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
179 necessary, for a single group.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
180
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
181 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
182 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
183 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
184 the function and macro calls appropriately."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
185 (let ((prefix (if (boundp 'compat-current-package)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
186 compat-current-package
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
187 (error
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
188 "`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
189 (defs-to-munge '(defun defmacro))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
190 mappings)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
191 (if (symbolp prefix) (setq prefix (symbol-name prefix)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
192 ;; first, note all defuns and defmacros
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
193 (let (fundef
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
194 (body-tail body))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
195 (while body-tail
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
196 (setq fundef (car body-tail))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
197 (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
198 (push (cons (second fundef) (third fundef)) mappings))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
199 (setq body-tail (cdr body-tail))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
200 ;; now, munge the definitions with the new names
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
201 (let (fundef
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
202 (body-tail body)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
203 result
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
204 defs)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
205 (while body-tail
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
206 (setq fundef (car body-tail))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
207 (push
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
208 (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
209 (nconc (list (car fundef)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
210 (intern (concat prefix "-"
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
211 (symbol-name (second fundef))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
212 (third fundef))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
213 (nthcdr 3 fundef)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
214 (t fundef))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
215 result)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
216 (setq body-tail (cdr body-tail)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
217 (setq result (nreverse result))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
218 ;; 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
219 ;; macroletted
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
220 (mapc
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
221 #'(lambda (acons)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
222 (let ((fun (car acons))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
223 (args (cdr acons)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
224 (push
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
225 (list fun args
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
226 (nconc
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
227 (list 'list
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
228 (list 'quote
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
229 (intern (concat prefix "-"
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
230 (symbol-name fun)))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
231 args))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
232 defs)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
233 mappings)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
234 ;; 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
235 ;; 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
236 ;; them. #### Move `lexical-let' into C!!!
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
237 `(macrolet ((compat-current-package () ,compat-current-package)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
238 ,@defs)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
239 ,@result))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
240
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
241 (compat-define-compat-functions
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
242
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
243 (defun compat-hash-table (group)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
244 (get group 'compat-table))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
245
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
246 (defun compat-make-hash-table (group)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
247 (put group 'compat-table (make-hash-table)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
248
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
249 (defmacro compat-define-group (group &rest body)
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
250 "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
251 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
252 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
253 `compat' macro.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
254
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
255 If GROUP is already defined, nothing happens."
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
256 (let ((group (eval group)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
257 (or (hash-table-p (compat-hash-table group))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
258 (compat-make-hash-table group))))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
259
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
260 (defmacro compat-clear-functions (group)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
261 "Clear all defined functions and macros out of GROUP."
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
262 (let ((group (eval group)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
263 (clrhash (compat-hash-table group))))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
264
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
265 (defmacro compat-defun (args &rest body)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
266
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
267 (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
268 "Define a compatibility function.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
269 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
270 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
271 Any functions and macros defined at top level using `defun' or `defmacro'
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
272 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
273 normally. All code and definitions in this group can safely reference any
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
274 other functions in this group -- the code is effectively wrapped in a
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
275 `compat' call. You can call `compat-define-functions' more than once, if
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
276 necessary, for a single group.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
277
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
278 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
279 fact defined using names prefixed with GROUP. To use these functions,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
280 wrap any calling code with the `compat' macro, which lexically renames
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
281 the function and macro calls appropriately."
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
282 (let ((group (eval group))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
283 (defs-to-munge '(defun defmacro))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
284 )
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
285 (let (fundef
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
286 (body-tail body))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
287 (while body-tail
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
288 (setq fundef (car body-tail))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
289 (when (and (consp fundef) (memq (car fundef) defs-to-munge))
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
290 (puthash (second fundef) (third fundef) (compat-hash-table group)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
291 (setq body-tail (cdr body-tail))))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
292 (let (fundef
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
293 (body-tail body)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
294 result)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
295 (while body-tail
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
296 (setq fundef (car body-tail))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
297 (push
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
298 (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
299 (nconc (list (car fundef)
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
300 (intern (concat (symbol-name group) "-"
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
301 (symbol-name (second fundef))))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
302 (third fundef))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
303 (nthcdr 3 fundef)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
304 (t fundef))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
305 result)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
306 (setq body-tail (cdr body-tail)))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
307 (nconc (list 'compat-wrap (list 'quote group)) (nreverse result)))))
410
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 (defvar compat-active-groups nil)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
310
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
311 (defun compat-fboundp (groups fun)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
312 "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
313 GROUPS is a list of compatibility groups as defined using
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
314 `compat-define-group'."
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
315 (or (fboundp fun)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
316 (block nil
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
317 (mapcar #'(lambda (group)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
318 (if (gethash fun (compat-hash-table group))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
319 (return t)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
320 groups))))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
321
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
322 (defmacro compat-wrap-runtime (groups &rest body))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
323
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
324 (defmacro compat-wrap (groups &rest body)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
325 "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
326 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
327 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
328 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
329 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
330 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
331 `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
332 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
333 package was loaded -- see discussion at top).
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
334
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
335 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
336 have to do a bit if setup.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
337
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
338 -- 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
339 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
340 packages).
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
341 -- 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
342 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
343 and similarly renamed.
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 To make use of the API's provided:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
346
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
347 -- 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
348 notices and comments:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
349
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
350 \(let ((compat-current-package 'Gnus))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
351 (require 'gnus-compat))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
352
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
353 -- 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
354 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
355
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
356 \(Gnus-compat-wrap '(overlays xem-events)
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 ...
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 \(defun gnus-random-fun (overlay baz)
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 (overlay-put overlay 'face 'bold)
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 ...
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
370
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
371 \(defun gnus-random-fun-2 (event)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
372 (interactive "e")
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
373 (let ((x (event-x event))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
374 (y (event-y event)))
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 )
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 ) ;; end of (Gnus-compat)
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 ;;;; random-module.el ends here
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
382
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
383 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
384 \(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
385 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
386 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
387 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
388 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
389 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
390 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
391
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
392 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
393 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
394 `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
395
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
396 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
397 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
398 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
399 `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
400 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
401 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
402 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
403 `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
404 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
405 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
406 `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
407 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
408
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
409 Before using `compat'
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
410
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
411 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
412 `compat', first do 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 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
415
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
416 ;; 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
417 ;; 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
418 ;; 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
419 ;; 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
420
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
421 \(let ((current-compat-package 'Gnus))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
422 (require 'gnus-compat))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
423
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
424 ;; 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
425 ;; 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
426 ;; 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
427 ;; 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
428
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
429 \(Gnus-compat-wrap '(overlays xem-events)
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
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
433 )
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
434
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
435 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
436 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
437 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
438 bottom; use this in place of a `require' statement. Wrapped code can
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
439 be either function or macro definitions or other ELisp code, and
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
440 wrapped function or macro definitions need not be at top level. All
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
441 calls to the compatibility functions or macros will be noticed anywhere
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
442 within the wrapped code. Calls to `fboundp' within the wrapped code
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
443 will also behave correctly when called on compatibility functions and
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
444 macros, even though they would return nil elsewhere (including in code
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
445 in other modules called dynamically from the wrapped code).
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
446
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
447 The functions and macros define in GROUP are actually defined under
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
448 prefixed names, to avoid namespace clashes and bad interactions with
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
449 other code that calls `fboundp'. All calls inside of the wrapped code
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
450 to the compatibility functions and macros in GROUP are lexically
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
451 mapped to the prefixed names. Since this is a lexical mapping, code
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
452 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
453 be affected."
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
454 (let ((group (eval group))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
455 defs)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
456 (maphash
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
457 #'(lambda (fun args)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
458 (push
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
459 (list fun args
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
460 (nconc
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
461 (list 'list
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
462 (list 'quote
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
463 (intern (concat (symbol-name group) "-"
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
464 (symbol-name fun)))))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
465 args))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
466 defs))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
467 (compat-hash-table group))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
468 ;; 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
469 ;; causes function definitions to have obnoxious, unreadable junk in
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
470 ;; them. #### Move `lexical-let' into C!!!
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
471 `(let ((compat-active-groups (cons ',group compat-active-groups)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
472 (macrolet ((fboundp (fun) `(compat-fboundp ',compat-active-groups ,fun))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
473 ,@defs)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents:
diff changeset
474 ,@body))))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
475
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 ;; Define the compat groups ;;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
478 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 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 (compat-define-group 'overlays
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
483
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
484 (defun-compat overlayp (object)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
485 "Return t if OBJECT is an overlay."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
486 (and (extentp object)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
487 (extent-property object 'overlay)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
488
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
489 (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
490 "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
491 If omitted, BUFFER defaults to the current buffer.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
492 BEG and END may be integers or markers.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
493 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
494 front delimiter advance when text is inserted there.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
495 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
496 rear delimiter advance when text is inserted there."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
497 (if (null buffer)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
498 (setq buffer (current-buffer))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
499 (check-argument-type 'bufferp buffer))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
500 (when (> beg end)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
501 (setq beg (prog1 end (setq end beg))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
502
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
503 (let ((overlay (make-extent beg end buffer)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
504 (set-extent-property overlay 'overlay t)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
505 (if front-advance
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
506 (set-extent-property overlay 'start-open t)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
507 (set-extent-property overlay 'start-closed t))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
508 (if rear-advance
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
509 (set-extent-property overlay 'end-closed t)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
510 (set-extent-property overlay 'end-open t))
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 overlay))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
513
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
514 (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
515 "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
516 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
517 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
518 buffer."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
519 (check-argument-type 'overlayp 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 (extent-object overlay)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
522 (if (null buffer)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
523 (setq buffer (current-buffer)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
524 (check-argument-type 'bufferp buffer)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
525 (and (= beg end)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
526 (extent-property overlay 'evaporate)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
527 (delete-overlay overlay))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
528 (when (> beg end)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
529 (setq beg (prog1 end (setq end beg))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
530 (set-extent-endpoints overlay beg end buffer)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
531 overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
532
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
533 (defun-compat delete-overlay (overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
534 "Delete the overlay OVERLAY from its buffer."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
535 (check-argument-type 'overlayp overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
536 (detach-extent overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
537 nil)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
538
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
539 (defun-compat overlay-start (overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
540 "Return the position at which OVERLAY starts."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
541 (check-argument-type 'overlayp overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
542 (extent-start-position overlay))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
543
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
544 (defun-compat overlay-end (overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
545 "Return the position at which OVERLAY ends."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
546 (check-argument-type 'overlayp overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
547 (extent-end-position overlay))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
548
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
549 (defun-compat overlay-buffer (overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
550 "Return the buffer OVERLAY belongs to."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
551 (check-argument-type 'overlayp overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
552 (extent-object overlay))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
553
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
554 (defun-compat overlay-properties (overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
555 "Return a list of the properties on OVERLAY.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
556 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
557 OVERLAY."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
558 (check-argument-type 'overlayp overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
559 (extent-properties overlay))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
560
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
561 (defun-compat overlays-at (pos)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
562 "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
563 (overlays-in pos pos))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
564
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
565 (defun-compat overlays-in (beg end)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
566 "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
567 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
568 and also contained within the specified region.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
569 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
570 or between BEG and END."
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
571 (if (featurep 'xemacs)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
572 (mapcar-extents #'identity nil nil beg end
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
573 'all-extents-closed-open 'overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
574 (let ((ovls (overlay-lists))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
575 tmp retval)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
576 (if (< end beg)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
577 (setq tmp end
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
578 end beg
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
579 beg tmp))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
580 (setq ovls (nconc (car ovls) (cdr ovls)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
581 (while ovls
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
582 (setq tmp (car ovls)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
583 ovls (cdr ovls))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
584 (if (or (and (<= (overlay-start tmp) end)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
585 (>= (overlay-start tmp) beg))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
586 (and (<= (overlay-end tmp) end)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
587 (>= (overlay-end tmp) beg)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
588 (setq retval (cons tmp retval))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
589 retval)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
590
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
591 (defun-compat next-overlay-change (pos)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
592 "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
593 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
594 (let ((next (point-max))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
595 tmp)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
596 (map-extents
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
597 (lambda (overlay ignore)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
598 (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
599 (> tmp pos))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
600 (and (< (setq tmp (extent-end-position overlay)) next)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
601 (> tmp pos)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
602 (setq next tmp))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
603 nil)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
604 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
605 next))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
606
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
607 (defun-compat previous-overlay-change (pos)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
608 "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
609 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
610 (let ((prev (point-min))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
611 tmp)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
612 (map-extents
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
613 (lambda (overlay ignore)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
614 (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
615 (< tmp pos))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
616 (and (> (setq tmp (extent-start-position overlay)) prev)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
617 (< tmp pos)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
618 (setq prev tmp))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
619 nil)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
620 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
621 prev))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
622
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
623 (defun-compat overlay-lists ()
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
624 "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
625 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
626 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
627 Recentering overlays moves overlays between these lists.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
628 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
629 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
630 (or (boundp 'xemacs-internal-overlay-center-pos)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
631 (overlay-recenter (1+ (/ (- (point-max) (point-min)) 2))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
632 (let ((pos xemacs-internal-overlay-center-pos)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
633 before after)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
634 (map-extents (lambda (overlay ignore)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
635 (if (> pos (extent-end-position overlay))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
636 (push overlay before)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
637 (push overlay after))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
638 nil)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
639 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
640 (cons (nreverse before) (nreverse after))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
641
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
642 (defun-compat overlay-recenter (pos)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
643 "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
644 (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
645
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
646 (defun-compat overlay-get (overlay prop)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
647 "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
648 (check-argument-type 'overlayp overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
649 (let ((value (extent-property overlay prop))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
650 category)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
651 (if (and (null value)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
652 (setq category (extent-property overlay 'category)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
653 (get category prop)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
654 value)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
655
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
656 (defun-compat overlay-put (overlay prop value)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
657 "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
658 (check-argument-type 'overlayp overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
659 (cond ((eq prop 'evaporate)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
660 (set-extent-property overlay 'detachable value))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
661 ((eq prop 'before-string)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
662 (set-extent-property overlay 'begin-glyph
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
663 (make-glyph (vector 'string :data value))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
664 ((eq prop 'after-string)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
665 (set-extent-property overlay 'end-glyph
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
666 (make-glyph (vector 'string :data value))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
667 ((eq prop 'local-map)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
668 (set-extent-property overlay 'keymap value))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
669 ((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
670 modification-hooks))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
671 (error "cannot support overlay '%s property under XEmacs"
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
672 prop)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
673 (set-extent-property overlay prop value))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
674 )
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; extents ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
677
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
678 (defalias-compat 'delete-extent 'delete-overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
679 (defalias-compat 'extent-end-position 'overlay-end)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
680 (defalias-compat 'extent-start-position 'overlay-start)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
681 (defalias-compat 'set-extent-endpoints 'move-overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
682 (defalias-compat 'set-extent-property 'overlay-put)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
683 (defalias-compat 'make-extent 'make-overlay)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
684
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
685 (defun-compat extent-property (extent property &optional default)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
686 (or (overlay-get extent property) default))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
687
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
688 (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
689 (let ((tmp (overlays-at (point)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
690 ovls)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
691 (if property
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
692 (while tmp
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
693 (if (extent-property (car tmp) property)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
694 (setq ovls (cons (car tmp) ovls)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
695 (setq tmp (cdr tmp)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
696 (setq ovls tmp
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
697 tmp nil))
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 826
diff changeset
698 (car (sort* ovls #'< :key #'extent-length))))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
699
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
700 (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
701 maparg flags property value)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
702 (let ((tmp (overlays-in (or from (point-min))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
703 (or to (point-max))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
704 ovls)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
705 (if property
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
706 (while tmp
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
707 (if (extent-property (car tmp) property)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
708 (setq ovls (cons (car tmp) ovls)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
709 (setq tmp (cdr tmp)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
710 (setq ovls tmp
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
711 tmp nil))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
712 (catch 'done
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
713 (while ovls
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
714 (setq tmp (funcall function (car ovls) maparg)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
715 ovls (cdr ovls))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
716 (if tmp
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
717 (throw 'done tmp))))))
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; extents ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
720
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; events ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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 ) ;; group overlays
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 ) ;; compat-define-compat-functions
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
727
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
728 (fmakunbound 'compat-define-compat-functions)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
729
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 410
diff changeset
730 )