annotate src/marker.c @ 272:c5d627a313b1 r21-0b34

Import from CVS: tag r21-0b34
author cvs
date Mon, 13 Aug 2007 10:28:48 +0200
parents 8efd647ea9ca
children 6240c7796c7a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Markers: examining, setting and killing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Synched up with: FSF 19.30. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 /* This file has been Mule-ized. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 /* Note that markers are currently kept in an unordered list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 This means that marker operations may be inefficient if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 there are a bunch of markers in the buffer. This probably
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 won't have a significant impact on redisplay (which uses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 markers), but if it does, it wouldn't be too hard to change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 to an ordered gap array. (Just copy the code from extents.c.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 mark_marker (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 struct Lisp_Marker *marker = XMARKER (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 Lisp_Object buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 /* DO NOT mark through the marker's chain.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 The buffer's markers chain does not preserve markers from gc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 Instead, markers are removed from the chain when they are freed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 by gc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 if (!marker->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 return (Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 XSETBUFFER (buf, marker->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 return (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 print_marker (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 {
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
58 struct Lisp_Marker *marker = XMARKER (obj);
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
59 char buf[200];
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
60
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 if (print_readably)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
62 error ("printing unreadable object #<marker 0x%lx>", (long) marker);
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
63
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 write_c_string (GETTEXT ("#<marker "), printcharfun);
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
65 if (!marker->buffer)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 write_c_string (GETTEXT ("in no buffer"), printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 {
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
69 sprintf (buf, "at %d in ", marker_position (obj));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 write_c_string (buf, printcharfun);
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
71 print_internal (marker->buffer->name, printcharfun, 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
73 sprintf (buf, " 0x%lx>", (long) marker);
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
74 write_c_string (buf, printcharfun);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 marker_equal (Lisp_Object o1, Lisp_Object o2, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 struct buffer *b1 = XMARKER (o1)->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 if (b1 != XMARKER (o2)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 else if (!b1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 /* All markers pointing nowhere are equal */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 return (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 return ((XMARKER (o1)->memind == XMARKER (o2)->memind));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 static unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 marker_hash (Lisp_Object obj, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 unsigned long hash = (unsigned long) XMARKER (obj)->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 if (hash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 hash = HASH2 (hash, XMARKER (obj)->memind);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 return hash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
99 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("marker", marker,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
100 mark_marker, print_marker, 0,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
101 marker_equal, marker_hash,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
102 struct Lisp_Marker);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 /* Operations on markers. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
106 DEFUN ("marker-buffer", Fmarker_buffer, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 Return the buffer that MARKER points into, or nil if none.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
108 Return nil if MARKER points into a dead buffer or doesn't point anywhere.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
109 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
110 (marker))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
112 struct buffer *buf;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 CHECK_MARKER (marker);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
114 /* Return marker's buffer only if it is not dead. */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
115 if ((buf = XMARKER (marker)->buffer) && BUFFER_LIVE_P (buf))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
117 Lisp_Object buffer;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
118 XSETBUFFER (buffer, buf);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
119 return buffer;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
124 DEFUN ("marker-position", Fmarker_position, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 Return the position MARKER points at, as a character number.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
126 Return `nil' if marker doesn't point anywhere.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
127 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
128 (marker))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 CHECK_MARKER (marker);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
131 return XMARKER (marker)->buffer ? make_int (marker_position (marker)) : Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 #if 0 /* useful debugging function */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 check_marker_circularities (struct buffer *buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 struct Lisp_Marker *tortoise, *hare;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 tortoise = BUF_MARKERS (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 hare = tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 if (!tortoise)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 assert (hare->buffer == buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 hare = hare->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 if (!hare)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 assert (hare->buffer == buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 hare = hare->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 if (!hare)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 tortoise = tortoise->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 assert (tortoise != hare);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 set_marker_internal (Lisp_Object marker, Lisp_Object pos, Lisp_Object buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 int restricted_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 Bufpos charno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 struct buffer *b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 struct Lisp_Marker *m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 int point_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 CHECK_MARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 point_p = POINT_MARKER_P (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 /* If position is nil or a marker that points nowhere,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 make this marker point nowhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 if (NILP (pos) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (MARKERP (pos) && !XMARKER (pos)->buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 if (point_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 signal_simple_error ("can't make point-marker point nowhere",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 if (XMARKER (marker)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 unchain_marker (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 return marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 CHECK_INT_COERCE_MARKER (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 if (NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 b = current_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 CHECK_BUFFER (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 b = XBUFFER (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 /* If buffer is dead, set marker to point nowhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 if (!BUFFER_LIVE_P (XBUFFER (buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 if (point_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 signal_simple_error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ("can't move point-marker in a killed buffer", marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 if (XMARKER (marker)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 unchain_marker (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 return marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 charno = XINT (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 m = XMARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 if (restricted_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 if (charno < BUF_BEGV (b)) charno = BUF_BEGV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 if (charno > BUF_ZV (b)) charno = BUF_ZV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 if (charno < BUF_BEG (b)) charno = BUF_BEG (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 if (charno > BUF_Z (b)) charno = BUF_Z (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 if (point_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 #ifndef moving_point_by_moving_its_marker_is_a_bug
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 BUF_SET_PT (b, charno); /* this will move the marker */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 #else /* It's not a feature, so it must be a bug */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 signal_simple_error ("DEBUG: attempt to move point via point-marker",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 m->memind = bufpos_to_memind (b, charno);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 if (m->buffer != b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 if (point_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 signal_simple_error ("can't change buffer of point-marker", marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 if (m->buffer != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 unchain_marker (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 m->buffer = b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 marker_next (m) = BUF_MARKERS (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 marker_prev (m) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 if (BUF_MARKERS (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 marker_prev (BUF_MARKERS (b)) = m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 BUF_MARKERS (b) = m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 }
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
250
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 return marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
255 DEFUN ("set-marker", Fset_marker, 2, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 Position MARKER before character number NUMBER in BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 BUFFER defaults to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 If NUMBER is nil, makes marker point nowhere.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 Then it no longer slows down editing in any buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 If this marker was returned by (point-marker t), then changing its position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 moves point. You cannot change its buffer or make it point nowhere.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 Returns MARKER.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
263 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
264 (marker, number, buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 return set_marker_internal (marker, number, buffer, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 /* This version of Fset_marker won't let the position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 be outside the visible part. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
272 Lisp_Object
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 set_marker_restricted (Lisp_Object marker, Lisp_Object pos, Lisp_Object buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 return set_marker_internal (marker, pos, buffer, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 /* This is called during garbage collection,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 so we must be careful to ignore and preserve mark bits,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 including those in chain fields of markers. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 unchain_marker (Lisp_Object m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 struct Lisp_Marker *marker = XMARKER (m);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 struct buffer *b = marker->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 if (b == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
292 #ifdef ERROR_CHECK_GC
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 assert (BUFFER_LIVE_P (b));
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
294 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 if (marker_next (marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 marker_prev (marker_next (marker)) = marker_prev (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 if (marker_prev (marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 marker_next (marker_prev (marker)) = marker_next (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 BUF_MARKERS (b) = marker_next (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
303 #ifdef ERROR_CHECK_GC
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 assert (marker != XMARKER (b->point_marker));
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
305 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 marker->buffer = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 bi_marker_position (Lisp_Object marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 struct Lisp_Marker *m = XMARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 struct buffer *buf = m->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 Bytind pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 if (!buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 error ("Marker does not point anywhere");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 /* FSF claims that marker indices could end up denormalized, i.e.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 in the gap. This is way bogus if it ever happens, and means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 something fucked up elsewhere. Since I've overhauled all this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 shit, I don't think this can happen. In any case, the following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 macro has an assert() in it that will catch these denormalized
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 positions. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 pos = memind_to_bytind (buf, m->memind);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
328 #ifdef ERROR_CHECK_BUFPOS
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 if (pos < BI_BUF_BEG (buf) || pos > BI_BUF_Z (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 abort ();
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
331 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 return pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 marker_position (Lisp_Object marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 struct buffer *buf = XMARKER (marker)->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 if (!buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 error ("Marker does not point anywhere");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 return bytind_to_bufpos (buf, bi_marker_position (marker));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 set_bi_marker_position (Lisp_Object marker, Bytind pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 struct Lisp_Marker *m = XMARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 struct buffer *buf = m->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 if (!buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 error ("Marker does not point anywhere");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
356 #ifdef ERROR_CHECK_BUFPOS
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 if (pos < BI_BUF_BEG (buf) || pos > BI_BUF_Z (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 abort ();
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
359 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 m->memind = bytind_to_memind (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 set_marker_position (Lisp_Object marker, Bufpos pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 struct buffer *buf = XMARKER (marker)->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 if (!buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 error ("Marker does not point anywhere");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 set_bi_marker_position (marker, bufpos_to_bytind (buf, pos));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 copy_marker_1 (Lisp_Object marker, Lisp_Object type, int noseeum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 REGISTER Lisp_Object new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 if (INTP (marker) || MARKERP (marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 if (noseeum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 new = noseeum_make_marker ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 new = Fmake_marker ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 Fset_marker (new, marker,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (MARKERP (marker) ? Fmarker_buffer (marker) : Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 XMARKER (new)->insertion_type = !NILP (type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 return new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 marker = wrong_type_argument (Qinteger_or_marker_p, marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 RETURN_NOT_REACHED (Qnil) /* not reached */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
400 DEFUN ("copy-marker", Fcopy_marker, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 Return a new marker pointing at the same place as MARKER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 If argument is a number, makes a new marker pointing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 at that position in the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 The optional argument TYPE specifies the insertion type of the new marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 see `marker-insertion-type'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
406 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
407 (marker, type))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 return copy_marker_1 (marker, type, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 noseeum_copy_marker (Lisp_Object marker, Lisp_Object type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 return copy_marker_1 (marker, type, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
418 DEFUN ("marker-insertion-type", Fmarker_insertion_type, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 Return insertion type of MARKER: t if it stays after inserted text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 nil means the marker stays before text inserted there.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
421 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
422 (marker))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 CHECK_MARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 return XMARKER (marker)->insertion_type ? Qt : Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
428 DEFUN ("set-marker-insertion-type", Fset_marker_insertion_type, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 Set the insertion-type of MARKER to TYPE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 If TYPE is t, it means the marker advances when you insert text at it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 If TYPE is nil, it means the marker stays behind when you insert text at it.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
432 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
433 (marker, type))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 CHECK_MARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 XMARKER (marker)->insertion_type = ! NILP (type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 return type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
441 /* #### What is the possible use of this? It looks quite useless to
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
442 me, because there is no way to find *which* markers are positioned
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
443 at POSITION. Additional bogosity bonus: (buffer-has-markers-at
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
444 (point)) will always return t because of the `point-marker'. The
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
445 same goes for the position of mark. Bletch!
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
446
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
447 Someone should discuss this with Stallman, but I don't have the
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
448 stomach. In fact, this function sucks so badly that I'm disabling
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
449 it by default (although I've debugged it). If you want to use it,
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
450 use extents instead. --hniksic */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
451 #if 0
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
452 xxDEFUN ("buffer-has-markers-at", Fbuffer_has_markers_at, 1, 1, 0, /*
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
453 Return t if there are markers pointing at POSITION in the current buffer.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
454 */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
455 (position))
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
456 {
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
457 struct Lisp_Marker *marker;
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
458 Memind pos;
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
459
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
460 /* A small optimization trick: convert POS to memind now, rather
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
461 than converting every marker's memory index to bufpos. */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
462 pos = bytind_to_memind (current_buffer,
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
463 get_buffer_pos_byte (current_buffer, position,
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
464 GB_COERCE_RANGE));
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
465
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
466 for (marker = BUF_MARKERS (current_buffer);
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
467 marker;
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
468 marker = marker_next (marker))
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
469 {
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
470 /* We use marker->memind, so we don't have to go through the
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
471 unwieldy operation of creating a Lisp_Object for
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
472 marker_position() every time around. */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
473 if (marker->memind == pos)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
474 return Qt;
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
475 }
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
476
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
477 return Qnil;
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
478 }
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
479 #endif /* 0 */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
480
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 #ifdef MEMORY_USAGE_STATS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 compute_buffer_marker_usage (struct buffer *b, struct overhead_stats *ovstats)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 struct Lisp_Marker *m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 int total = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 int overhead;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 for (m = BUF_MARKERS (b); m; m = m->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 total += sizeof (struct Lisp_Marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 ovstats->was_requested += total;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 overhead = fixed_type_block_overhead (total);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 /* #### claiming this is all malloc overhead is not really right,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 but it has to go somewhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 ovstats->malloc_overhead += overhead;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 return total + overhead;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 #endif /* MEMORY_USAGE_STATS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 syms_of_marker (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 {
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
506 DEFSUBR (Fmarker_position);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
507 DEFSUBR (Fmarker_buffer);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
508 DEFSUBR (Fset_marker);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
509 DEFSUBR (Fcopy_marker);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
510 DEFSUBR (Fmarker_insertion_type);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
511 DEFSUBR (Fset_marker_insertion_type);
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
512 #if 0 /* FSFmacs crock */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
513 DEFSUBR (Fbuffer_has_markers_at);
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
514 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 init_buffer_markers (struct buffer *b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
520 Lisp_Object buf;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 XSETBUFFER (buf, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 b->mark = Fmake_marker ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 BUF_MARKERS (b) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 b->point_marker = Fmake_marker ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 Fset_marker (b->point_marker, make_int (1), buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 uninit_buffer_markers (struct buffer *b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 /* Unchain all markers of this buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 and leave them pointing nowhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 REGISTER struct Lisp_Marker *m, *next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 for (m = BUF_MARKERS (b); m; m = next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 m->buffer = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 next = marker_next (m);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 marker_next (m) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 marker_prev (m) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 BUF_MARKERS (b) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 }