annotate src/marker.c @ 388:aabb7f5b1c81 r21-2-9

Import from CVS: tag r21-2-9
author cvs
date Mon, 13 Aug 2007 11:09:42 +0200
parents 8626e4521993
children 74fd4e045ea6
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
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
78 marker_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
80 struct Lisp_Marker *marker1 = XMARKER (obj1);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
81 struct Lisp_Marker *marker2 = XMARKER (obj2);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
82
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
83 return ((marker1->buffer == marker2->buffer) &&
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
84 (marker1->memind == marker2->memind ||
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
85 /* All markers pointing nowhere are equal */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
86 !marker1->buffer));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 static unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 marker_hash (Lisp_Object obj, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 unsigned long hash = (unsigned long) XMARKER (obj)->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 if (hash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 hash = HASH2 (hash, XMARKER (obj)->memind);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 return hash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
98 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("marker", marker,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
99 mark_marker, print_marker, 0,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
100 marker_equal, marker_hash,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
101 struct Lisp_Marker);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 /* Operations on markers. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
105 DEFUN ("marker-buffer", Fmarker_buffer, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 Return the buffer that MARKER points into, or nil if none.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
107 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
108 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
109 (marker))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
111 struct buffer *buf;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 CHECK_MARKER (marker);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
113 /* Return marker's buffer only if it is not dead. */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
114 if ((buf = XMARKER (marker)->buffer) && BUFFER_LIVE_P (buf))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
116 Lisp_Object buffer;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
117 XSETBUFFER (buffer, buf);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
118 return buffer;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
123 DEFUN ("marker-position", Fmarker_position, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 Return the position MARKER points at, as a character number.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
125 Return `nil' if marker doesn't point anywhere.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
126 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
127 (marker))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 CHECK_MARKER (marker);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
130 return XMARKER (marker)->buffer ? make_int (marker_position (marker)) : Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 #if 0 /* useful debugging function */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 check_marker_circularities (struct buffer *buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 struct Lisp_Marker *tortoise, *hare;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 tortoise = BUF_MARKERS (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 hare = tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 if (!tortoise)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 assert (hare->buffer == buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 hare = hare->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 if (!hare)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 assert (hare->buffer == buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 hare = hare->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 if (!hare)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 tortoise = tortoise->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 assert (tortoise != hare);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 }
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 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 set_marker_internal (Lisp_Object marker, Lisp_Object pos, Lisp_Object buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 int restricted_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 Bufpos charno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 struct buffer *b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 struct Lisp_Marker *m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 int point_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 CHECK_MARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 point_p = POINT_MARKER_P (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 /* If position is nil or a marker that points nowhere,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 make this marker point nowhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 if (NILP (pos) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (MARKERP (pos) && !XMARKER (pos)->buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 if (point_p)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
182 signal_simple_error ("Can't make point-marker point nowhere",
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 if (XMARKER (marker)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 unchain_marker (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 return marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 CHECK_INT_COERCE_MARKER (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 if (NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 b = current_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 CHECK_BUFFER (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 b = XBUFFER (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 /* If buffer is dead, set marker to point nowhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 if (!BUFFER_LIVE_P (XBUFFER (buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 if (point_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 signal_simple_error
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
201 ("Can't move point-marker in a killed buffer", marker);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 if (XMARKER (marker)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 unchain_marker (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 return marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 }
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 charno = XINT (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 m = XMARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 if (restricted_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 if (charno < BUF_BEGV (b)) charno = BUF_BEGV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 if (charno > BUF_ZV (b)) charno = BUF_ZV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 if (charno < BUF_BEG (b)) charno = BUF_BEG (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 if (charno > BUF_Z (b)) charno = BUF_Z (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 if (point_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 #ifndef moving_point_by_moving_its_marker_is_a_bug
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 BUF_SET_PT (b, charno); /* this will move the marker */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 #else /* It's not a feature, so it must be a bug */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 signal_simple_error ("DEBUG: attempt to move point via point-marker",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 m->memind = bufpos_to_memind (b, charno);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 if (m->buffer != b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 if (point_p)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
239 signal_simple_error ("Can't change buffer of point-marker", marker);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 if (m->buffer != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 unchain_marker (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 m->buffer = b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 marker_next (m) = BUF_MARKERS (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 marker_prev (m) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 if (BUF_MARKERS (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 marker_prev (BUF_MARKERS (b)) = m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 BUF_MARKERS (b) = m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 }
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
249
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 return marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
254 DEFUN ("set-marker", Fset_marker, 2, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 Position MARKER before character number NUMBER in BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 BUFFER defaults to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 If NUMBER is nil, makes marker point nowhere.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 Then it no longer slows down editing in any buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 If this marker was returned by (point-marker t), then changing its position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 moves point. You cannot change its buffer or make it point nowhere.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 Returns MARKER.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
262 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
263 (marker, number, buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 return set_marker_internal (marker, number, buffer, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 }
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 /* This version of Fset_marker won't let the position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 be outside the visible part. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
271 Lisp_Object
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 set_marker_restricted (Lisp_Object marker, Lisp_Object pos, Lisp_Object buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 return set_marker_internal (marker, pos, buffer, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 }
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 /* This is called during garbage collection,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 so we must be careful to ignore and preserve mark bits,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 including those in chain fields of markers. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 unchain_marker (Lisp_Object m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 struct Lisp_Marker *marker = XMARKER (m);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 struct buffer *b = marker->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 if (b == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
291 #ifdef ERROR_CHECK_GC
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 assert (BUFFER_LIVE_P (b));
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
293 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 if (marker_next (marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 marker_prev (marker_next (marker)) = marker_prev (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 if (marker_prev (marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 marker_next (marker_prev (marker)) = marker_next (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 BUF_MARKERS (b) = marker_next (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
302 #ifdef ERROR_CHECK_GC
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 assert (marker != XMARKER (b->point_marker));
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
304 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 marker->buffer = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 bi_marker_position (Lisp_Object marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 struct Lisp_Marker *m = XMARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 struct buffer *buf = m->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 Bytind pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 if (!buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 error ("Marker does not point anywhere");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 /* FSF claims that marker indices could end up denormalized, i.e.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 in the gap. This is way bogus if it ever happens, and means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 something fucked up elsewhere. Since I've overhauled all this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 shit, I don't think this can happen. In any case, the following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 macro has an assert() in it that will catch these denormalized
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 positions. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 pos = memind_to_bytind (buf, m->memind);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
327 #ifdef ERROR_CHECK_BUFPOS
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 if (pos < BI_BUF_BEG (buf) || pos > BI_BUF_Z (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 abort ();
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
330 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 return pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 marker_position (Lisp_Object marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 struct buffer *buf = XMARKER (marker)->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 if (!buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 error ("Marker does not point anywhere");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 return bytind_to_bufpos (buf, bi_marker_position (marker));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 set_bi_marker_position (Lisp_Object marker, Bytind pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 struct Lisp_Marker *m = XMARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 struct buffer *buf = m->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 if (!buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 error ("Marker does not point anywhere");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
355 #ifdef ERROR_CHECK_BUFPOS
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 if (pos < BI_BUF_BEG (buf) || pos > BI_BUF_Z (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 abort ();
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 20
diff changeset
358 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 m->memind = bytind_to_memind (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 set_marker_position (Lisp_Object marker, Bufpos pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 struct buffer *buf = XMARKER (marker)->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 if (!buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 error ("Marker does not point anywhere");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 set_bi_marker_position (marker, bufpos_to_bytind (buf, pos));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 copy_marker_1 (Lisp_Object marker, Lisp_Object type, int noseeum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 REGISTER Lisp_Object new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 if (INTP (marker) || MARKERP (marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 if (noseeum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 new = noseeum_make_marker ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 new = Fmake_marker ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 Fset_marker (new, marker,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (MARKERP (marker) ? Fmarker_buffer (marker) : Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 XMARKER (new)->insertion_type = !NILP (type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 return new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 marker = wrong_type_argument (Qinteger_or_marker_p, marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 RETURN_NOT_REACHED (Qnil) /* not reached */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
399 DEFUN ("copy-marker", Fcopy_marker, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 Return a new marker pointing at the same place as MARKER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 If argument is a number, makes a new marker pointing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 at that position in the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 The optional argument TYPE specifies the insertion type of the new marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 see `marker-insertion-type'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
405 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
406 (marker, type))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 return copy_marker_1 (marker, type, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 noseeum_copy_marker (Lisp_Object marker, Lisp_Object type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 return copy_marker_1 (marker, type, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
417 DEFUN ("marker-insertion-type", Fmarker_insertion_type, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 Return insertion type of MARKER: t if it stays after inserted text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 nil means the marker stays before text inserted there.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
420 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
421 (marker))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 CHECK_MARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 return XMARKER (marker)->insertion_type ? Qt : Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
427 DEFUN ("set-marker-insertion-type", Fset_marker_insertion_type, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 Set the insertion-type of MARKER to TYPE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 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
430 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
431 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
432 (marker, type))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 CHECK_MARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 XMARKER (marker)->insertion_type = ! NILP (type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 return type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
440 /* #### What is the possible use of this? It looks quite useless to
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
441 me, because there is no way to find *which* markers are positioned
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
442 at POSITION. Additional bogosity bonus: (buffer-has-markers-at
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
443 (point)) will always return t because of the `point-marker'. The
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
444 same goes for the position of mark. Bletch!
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
445
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
446 Someone should discuss this with Stallman, but I don't have the
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
447 stomach. In fact, this function sucks so badly that I'm disabling
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
448 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
449 use extents instead. --hniksic */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
450 #if 0
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
451 xxDEFUN ("buffer-has-markers-at", Fbuffer_has_markers_at, 1, 1, 0, /*
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
452 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
453 */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
454 (position))
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
455 {
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
456 struct Lisp_Marker *marker;
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
457 Memind pos;
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
458
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
459 /* A small optimization trick: convert POS to memind now, rather
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
460 than converting every marker's memory index to bufpos. */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
461 pos = bytind_to_memind (current_buffer,
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
462 get_buffer_pos_byte (current_buffer, position,
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
463 GB_COERCE_RANGE));
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
464
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
465 for (marker = BUF_MARKERS (current_buffer);
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
466 marker;
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
467 marker = marker_next (marker))
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
468 {
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
469 /* 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
470 unwieldy operation of creating a Lisp_Object for
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
471 marker_position() every time around. */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
472 if (marker->memind == pos)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
473 return Qt;
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
474 }
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 return Qnil;
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
477 }
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
478 #endif /* 0 */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
479
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 #ifdef MEMORY_USAGE_STATS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 compute_buffer_marker_usage (struct buffer *b, struct overhead_stats *ovstats)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 struct Lisp_Marker *m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 int total = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 int overhead;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 for (m = BUF_MARKERS (b); m; m = m->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 total += sizeof (struct Lisp_Marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 ovstats->was_requested += total;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 overhead = fixed_type_block_overhead (total);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 /* #### claiming this is all malloc overhead is not really right,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 but it has to go somewhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 ovstats->malloc_overhead += overhead;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 return total + overhead;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 #endif /* MEMORY_USAGE_STATS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 syms_of_marker (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 {
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
505 DEFSUBR (Fmarker_position);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
506 DEFSUBR (Fmarker_buffer);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
507 DEFSUBR (Fset_marker);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
508 DEFSUBR (Fcopy_marker);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
509 DEFSUBR (Fmarker_insertion_type);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
510 DEFSUBR (Fset_marker_insertion_type);
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
511 #if 0 /* FSFmacs crock */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
512 DEFSUBR (Fbuffer_has_markers_at);
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 227
diff changeset
513 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 init_buffer_markers (struct buffer *b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
519 Lisp_Object buf;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 XSETBUFFER (buf, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 b->mark = Fmake_marker ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 BUF_MARKERS (b) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 b->point_marker = Fmake_marker ();
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 272
diff changeset
525 Fset_marker (b->point_marker,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 272
diff changeset
526 /* For indirect buffers, point is already set. */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 272
diff changeset
527 b->base_buffer ? make_int (BUF_PT (b)) : make_int (1),
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 272
diff changeset
528 buf);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 uninit_buffer_markers (struct buffer *b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 /* Unchain all markers of this buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 and leave them pointing nowhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 REGISTER struct Lisp_Marker *m, *next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 for (m = BUF_MARKERS (b); m; m = next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 m->buffer = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 next = marker_next (m);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 marker_next (m) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 marker_prev (m) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 BUF_MARKERS (b) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 }