annotate lisp/prim/overlay.el @ 163:0132846995bd r20-3b8

Import from CVS: tag r20-3b8
author cvs
date Mon, 13 Aug 2007 09:43:35 +0200
parents 56c54cf7c5b6
children 85ec50267440
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1 ;;; overlay.el --- overlay support.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3 ;;;; Copyright (C) 1997 Free Software Foundation, Inc.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
5 ;; Author: Joe Nuspl <nuspl@sequent.com>
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
6 ;; Maintainer: XEmacs Development Team (in <hniksic@srce.hr> incarnation)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
7 ;; Keywords: internal
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
8
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
10
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
14 ;; any later version.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
15
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
19 ;; General Public License for more details.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
20
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
25
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
26 ;;; Synched up with: Not in FSF.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
27
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
28 ;;; Commentary:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
29
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
30 ;; Unlike the text-properties interface, these functions are in fact
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
31 ;; totally useless in XEmacs. They are a more or less straightforward
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
32 ;; interface to the much better extent API, provided exclusively for
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
33 ;; GNU Emacs compatibility. If you notice an incompatibility not
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
34 ;; mentioned below, be sure to mention it. Anyways, you should really
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
35 ;; not use this.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
36
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
37 ;; Known incompatibilities with the FSF interface:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
38
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
39 ;; 1. There is not an `overlay' type. Any extent with non-nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
40 ;; 'overlay property is considered an "overlay".
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
41 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
42 ;; 2. Some features of FSF overlays have not been implemented in
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
43 ;; extents (or are unneeded). Specifically, those are the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
44 ;; following special properties: window, insert-in-front-hooks,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
45 ;; insert-behind-hooks, and modification-hooks. Some of these will
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
46 ;; probably be implemented for extents in the future.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
47 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
48 ;; 3. In FSF, beginning and end of an overlay are markers, which means
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
49 ;; that you can use `insert-before-markers' to change insertion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
50 ;; property of overlay. It will not work in this emulation, and we
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
51 ;; have no plans of providing it.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
52 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
53 ;; 4. The `overlays-in' and `overlays-at' functions in some cases
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
54 ;; don't work as they should. To be fixed RSN.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
55 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
56 ;; 5. Finally, setting or modification of overlay properties specific
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
57 ;; to extents will have unusual results. While (overlay-put
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
58 ;; overlay 'start-open t) does nothing under FSF, it has a definite
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
59 ;; effect under XEmacs. This is solved by simply avoiding such
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
60 ;; names (see `set-extent-property' for a list).
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
61
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
62 ;; Some functions were broken; fixed-up by Hrvoje Niksic, June 1997.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
63
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
64
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
65 ;;; Code:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
66
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
67 (defun overlayp (object)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
68 "Return t if OBJECT is an overlay."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
69 (and (extentp object)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
70 (extent-property object 'overlay)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
71
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
72 (defun make-overlay (beg end &optional buffer front-advance rear-advance)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
73 "Create a new overlay with range BEG to END in BUFFER.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
74 If omitted, BUFFER defaults to the current buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
75 BEG and END may be integers or markers.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
76 The fourth arg FRONT-ADVANCE, if non-nil, makes the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
77 front delimiter advance when text is inserted there.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
78 The fifth arg REAR-ADVANCE, if non-nil, makes the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
79 rear delimiter advance when text is inserted there."
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
80 (if (null buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
81 (setq buffer (current-buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
82 (check-argument-type 'bufferp buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
83 (when (> beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
84 (setq beg (prog1 end (setq end beg))))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
85
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
86 (let ((overlay (make-extent beg end buffer)))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
87 (set-extent-property overlay 'overlay t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
88 (if front-advance
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
89 (set-extent-property overlay 'start-open t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
90 (set-extent-property overlay 'start-closed t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
91 (if rear-advance
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
92 (set-extent-property overlay 'end-closed t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
93 (set-extent-property overlay 'end-open t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
94
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
95 overlay))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
96
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
97 (defun move-overlay (overlay beg end &optional buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
98 "Set the endpoints of OVERLAY to BEG and END in BUFFER.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
99 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
100 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
101 buffer."
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
102 (check-argument-type 'overlayp overlay)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
103 (if (null buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
104 (setq buffer (extent-object overlay)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
105 (if (null buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
106 (setq buffer (current-buffer)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
107 (check-argument-type 'bufferp buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
108 (and (= beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
109 (extent-property overlay 'evaporate)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
110 (delete-overlay overlay))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
111 (when (> beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
112 (setq beg (prog1 end (setq end beg))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
113 (set-extent-endpoints overlay beg end buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
114 overlay)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
115
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
116 (defun delete-overlay (overlay)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
117 "Delete the overlay OVERLAY from its buffer."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
118 (check-argument-type 'overlayp overlay)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
119 (detach-extent overlay)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
120 nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
121
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
122 (defun overlay-start (overlay)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
123 "Return the position at which OVERLAY starts."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
124 (check-argument-type 'overlayp overlay)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
125 (extent-start-position overlay))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
126
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
127 (defun overlay-end (overlay)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
128 "Return the position at which OVERLAY ends."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
129 (check-argument-type 'overlayp overlay)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
130 (extent-end-position overlay))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
131
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
132 (defun overlay-buffer (overlay)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
133 "Return the buffer OVERLAY belongs to."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
134 (check-argument-type 'overlayp overlay)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
135 (extent-object overlay))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
136
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
137 (defun overlay-properties (overlay)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
138 "Return a list of the properties on OVERLAY.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
139 This is a copy of OVERLAY's plist; modifying its conses has no effect on
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
140 OVERLAY."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
141 (check-argument-type 'overlayp overlay)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
142 (extent-properties overlay))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
143
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
144 (defun overlays-at (pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
145 "Return a list of the overlays that contain position POS."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
146 (overlays-in pos pos))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
147
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
148 (defun overlays-in (beg end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
149 "Return a list of the overlays that overlap the region BEG ... END.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
150 Overlap means that at least one character is contained within the overlay
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
151 and also contained within the specified region.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
152 Empty overlays are included in the result if they are located at BEG
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
153 or between BEG and END."
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
154 (mapcar-extents #'identity nil nil beg end nil 'overlay))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
155
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
156 (defun next-overlay-change (pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
157 "Return the next position after POS where an overlay starts or ends.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
158 If there are no more overlay boundaries after POS, return (point-max)."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
159 (let ((next (point-max))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
160 tmp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
161 (map-extents
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
162 (lambda (overlay ignore)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
163 (when (or (and (< (setq tmp (extent-start-position overlay)) next)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
164 (> tmp pos))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
165 (and (< (setq tmp (extent-end-position overlay)) next)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
166 (> tmp pos)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
167 (setq next tmp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
168 nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
169 nil pos nil nil nil 'overlay)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
170 next))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
171
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
172 (defun previous-overlay-change (pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
173 "Return the previous position before POS where an overlay starts or ends.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
174 If there are no more overlay boundaries before POS, return (point-min)."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
175 (let ((prev (point-min))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
176 tmp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
177 (map-extents
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
178 (lambda (overlay ignore)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
179 (when (or (and (> (setq tmp (extent-end-position overlay)) prev)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
180 (< tmp pos))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
181 (and (> (setq tmp (extent-start-position overlay)) prev)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
182 (< tmp pos)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
183 (setq prev tmp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
184 nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
185 nil nil pos nil nil 'overlay)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
186 prev))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
187
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
188 (defun overlay-lists ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
189 "Return a pair of lists giving all the overlays of the current buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
190 The car has all the overlays before the overlay center;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
191 the cdr has all the overlays after the overlay center.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
192 Recentering overlays moves overlays between these lists.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
193 The lists you get are copies, so that changing them has no effect.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
194 However, the overlays you get are the real objects that the buffer uses."
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
195 (or (boundp 'xemacs-internal-overlay-center-pos)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
196 (overlay-recenter (1+ (/ (- (point-max) (point-min)) 2))))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
197 (let ((pos xemacs-internal-overlay-center-pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
198 before after)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
199 (map-extents (lambda (overlay ignore)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
200 (if (> pos (extent-end-position overlay))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
201 (push overlay before)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
202 (push overlay after))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
203 nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
204 nil nil nil nil nil 'overlay)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
205 (cons (nreverse before) (nreverse after))))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
206
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
207 (defun overlay-recenter (pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
208 "Recenter the overlays of the current buffer around position POS."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
209 (set (make-local-variable 'xemacs-internal-overlay-center-pos) pos))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
210
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
211 (defun overlay-get (overlay prop)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
212 "Get the property of overlay OVERLAY with property name PROP."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
213 (check-argument-type 'overlayp overlay)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
214 (let ((value (extent-property overlay prop))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
215 category)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
216 (if (and (null value)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
217 (setq category (extent-property overlay 'category)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
218 (get category prop)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
219 value)))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
220
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
221 (defun overlay-put (overlay prop value)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
222 "Set one property of overlay OVERLAY: give property PROP value VALUE."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
223 (check-argument-type 'overlayp overlay)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
224 (cond ((eq prop 'evaporate)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
225 (set-extent-property overlay 'detachable value))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
226 ((eq prop 'before-string)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
227 (set-extent-property overlay 'begin-glyph
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
228 (make-glyph (vector 'string :data value))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
229 ((eq prop 'after-string)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
230 (set-extent-property overlay 'end-glyph
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
231 (make-glyph (vector 'string :data value))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
232 ((eq prop 'local-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 48
diff changeset
233 (set-extent-property overlay 'keymap value))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
234 ((memq prop '(window insert-in-front-hooks insert-behind-hooks
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
235 modification-hooks))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
236 (error "cannot support overlay '%s property under XEmacs"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
237 prop)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
238 (set-extent-property overlay prop value))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
239
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
240 (provide 'overlay)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
241
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
242 ;;; overlay.el ends here