annotate src/marker.c @ 94:1040fe1366ac xemacs-20-0f2

Import from CVS: tag xemacs-20-0f2
author cvs
date Mon, 13 Aug 2007 09:12:09 +0200
parents 859a2309aef8
children 0e522484dd2a
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 mark_marker (Lisp_Object, void (*) (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 static void print_marker (Lisp_Object, Lisp_Object, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 static int marker_equal (Lisp_Object, Lisp_Object, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 static unsigned long marker_hash (Lisp_Object obj, int depth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("marker", marker,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 mark_marker, print_marker, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 marker_equal, marker_hash,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 struct Lisp_Marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 mark_marker (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 struct Lisp_Marker *marker = XMARKER (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 Lisp_Object buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 /* DO NOT mark through the marker's chain.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 The buffer's markers chain does not preserve markers from gc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 Instead, markers are removed from the chain when they are freed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 by gc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 if (!marker->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 return (Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 XSETBUFFER (buf, marker->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 return (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 print_marker (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 if (print_readably)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 error ("printing unreadable object #<marker>");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 write_c_string (GETTEXT ("#<marker "), printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 if (!(XMARKER (obj)->buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 write_c_string (GETTEXT ("in no buffer"), printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 char buf[200];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 sprintf (buf, "at %d", marker_position (obj));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 write_c_string (buf, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 write_c_string (" in ", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 print_internal (XMARKER (obj)->buffer->name, printcharfun, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 write_c_string (">", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 marker_equal (Lisp_Object o1, Lisp_Object o2, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 struct buffer *b1 = XMARKER (o1)->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 if (b1 != XMARKER (o2)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 else if (!b1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 /* All markers pointing nowhere are equal */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 return (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 return ((XMARKER (o1)->memind == XMARKER (o2)->memind));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 static unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 marker_hash (Lisp_Object obj, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 unsigned long hash = (unsigned long) XMARKER (obj)->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 if (hash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 hash = HASH2 (hash, XMARKER (obj)->memind);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 return hash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 /* Operations on markers. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
109 DEFUN ("marker-buffer", Fmarker_buffer, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 Return the buffer that MARKER points into, or nil if none.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 Returns nil if MARKER points into a dead buffer.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
112 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
113 (marker))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 Lisp_Object buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 CHECK_MARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 if (XMARKER (marker)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 XSETBUFFER (buf, XMARKER (marker)->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 /* Return marker's buffer only if it is not dead. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 if (BUFFER_LIVE_P (XBUFFER (buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 return buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
127 DEFUN ("marker-position", Fmarker_position, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 Return the position MARKER points at, as a character number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 Returns `nil' if marker doesn't point anywhere.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
130 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
131 (marker))
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 CHECK_MARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 if (XMARKER (marker)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 return (make_int (marker_position (marker)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 #if 0 /* useful debugging function */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 check_marker_circularities (struct buffer *buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 struct Lisp_Marker *tortoise, *hare;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 tortoise = BUF_MARKERS (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 hare = tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 if (!tortoise)
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 assert (hare->buffer == buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 hare = hare->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 if (!hare)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 assert (hare->buffer == buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 hare = hare->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 if (!hare)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 tortoise = tortoise->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 assert (tortoise != hare);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 set_marker_internal (Lisp_Object marker, Lisp_Object pos, Lisp_Object buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 int restricted_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 Bufpos charno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 struct buffer *b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 struct Lisp_Marker *m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 int point_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 CHECK_MARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 point_p = POINT_MARKER_P (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 /* If position is nil or a marker that points nowhere,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 make this marker point nowhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 if (NILP (pos) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (MARKERP (pos) && !XMARKER (pos)->buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 if (point_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 signal_simple_error ("can't make point-marker point nowhere",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 if (XMARKER (marker)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 unchain_marker (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 return marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 CHECK_INT_COERCE_MARKER (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 if (NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 b = current_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 CHECK_BUFFER (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 b = XBUFFER (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 /* If buffer is dead, set marker to point nowhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 if (!BUFFER_LIVE_P (XBUFFER (buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 if (point_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 signal_simple_error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ("can't move point-marker in a killed buffer", marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 if (XMARKER (marker)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 unchain_marker (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 return marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 charno = XINT (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 m = XMARKER (marker);
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 (restricted_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 if (charno < BUF_BEGV (b)) charno = BUF_BEGV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 if (charno > BUF_ZV (b)) charno = BUF_ZV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 if (charno < BUF_BEG (b)) charno = BUF_BEG (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 if (charno > BUF_Z (b)) charno = BUF_Z (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 if (point_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 #ifndef moving_point_by_moving_its_marker_is_a_bug
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 BUF_SET_PT (b, charno); /* this will move the marker */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 #else /* It's not a feature, so it must be a bug */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 signal_simple_error ("DEBUG: attempt to move point via point-marker",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 m->memind = bufpos_to_memind (b, charno);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 if (m->buffer != b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 if (point_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 signal_simple_error ("can't change buffer of point-marker", marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 if (m->buffer != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 unchain_marker (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 m->buffer = b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 marker_next (m) = BUF_MARKERS (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 marker_prev (m) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 if (BUF_MARKERS (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 marker_prev (BUF_MARKERS (b)) = m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 BUF_MARKERS (b) = m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 return marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
262 DEFUN ("set-marker", Fset_marker, 2, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 Position MARKER before character number NUMBER in BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 BUFFER defaults to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 If NUMBER is nil, makes marker point nowhere.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 Then it no longer slows down editing in any buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 If this marker was returned by (point-marker t), then changing its position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 moves point. You cannot change its buffer or make it point nowhere.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 Returns MARKER.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
270 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
271 (marker, number, buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 return set_marker_internal (marker, number, buffer, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 }
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 /* This version of Fset_marker won't let the position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 be outside the visible part. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 set_marker_restricted (Lisp_Object marker, Lisp_Object pos, Lisp_Object buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 return set_marker_internal (marker, pos, buffer, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 /* This is called during garbage collection,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 so we must be careful to ignore and preserve mark bits,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 including those in chain fields of markers. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 unchain_marker (Lisp_Object m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 struct Lisp_Marker *marker = XMARKER (m);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 struct buffer *b = marker->buffer;
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 (b == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 assert (BUFFER_LIVE_P (b));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 if (marker_next (marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 marker_prev (marker_next (marker)) = marker_prev (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 if (marker_prev (marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 marker_next (marker_prev (marker)) = marker_next (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 BUF_MARKERS (b) = marker_next (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 assert (marker != XMARKER (b->point_marker));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 marker->buffer = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 bi_marker_position (Lisp_Object marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 struct Lisp_Marker *m = XMARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 struct buffer *buf = m->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 Bytind pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 if (!buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 error ("Marker does not point anywhere");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 /* FSF claims that marker indices could end up denormalized, i.e.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 in the gap. This is way bogus if it ever happens, and means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 something fucked up elsewhere. Since I've overhauled all this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 shit, I don't think this can happen. In any case, the following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 macro has an assert() in it that will catch these denormalized
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 positions. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 pos = memind_to_bytind (buf, m->memind);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 if (pos < BI_BUF_BEG (buf) || pos > BI_BUF_Z (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 return pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 marker_position (Lisp_Object marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 struct buffer *buf = XMARKER (marker)->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 if (!buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 error ("Marker does not point anywhere");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 return bytind_to_bufpos (buf, bi_marker_position (marker));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 set_bi_marker_position (Lisp_Object marker, Bytind pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 struct Lisp_Marker *m = XMARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 struct buffer *buf = m->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 if (!buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 error ("Marker does not point anywhere");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
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 ();
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 #ifdef MEMORY_USAGE_STATS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 compute_buffer_marker_usage (struct buffer *b, struct overhead_stats *ovstats)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 struct Lisp_Marker *m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 int total = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 int overhead;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 for (m = BUF_MARKERS (b); m; m = m->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 total += sizeof (struct Lisp_Marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 ovstats->was_requested += total;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 overhead = fixed_type_block_overhead (total);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 /* #### claiming this is all malloc overhead is not really right,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 but it has to go somewhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 ovstats->malloc_overhead += overhead;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 return total + overhead;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 #endif /* MEMORY_USAGE_STATS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 syms_of_marker (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 {
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
465 DEFSUBR (Fmarker_position);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
466 DEFSUBR (Fmarker_buffer);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
467 DEFSUBR (Fset_marker);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
468 DEFSUBR (Fcopy_marker);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
469 DEFSUBR (Fmarker_insertion_type);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
470 DEFSUBR (Fset_marker_insertion_type);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 void init_buffer_markers (struct buffer *b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 init_buffer_markers (struct buffer *b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 Lisp_Object buf = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 XSETBUFFER (buf, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 b->mark = Fmake_marker ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 BUF_MARKERS (b) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 b->point_marker = Fmake_marker ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 Fset_marker (b->point_marker, make_int (1), buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 void uninit_buffer_markers (struct buffer *b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 uninit_buffer_markers (struct buffer *b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 /* Unchain all markers of this buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 and leave them pointing nowhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 REGISTER struct Lisp_Marker *m, *next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 for (m = BUF_MARKERS (b); m; m = next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 m->buffer = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 next = marker_next (m);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 marker_next (m) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 marker_prev (m) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 BUF_MARKERS (b) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 }