annotate src/marker.c @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 859a2309aef8
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 DEFUN ("marker-buffer", Fmarker_buffer, Smarker_buffer, 1, 1, 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.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 Lisp_Object marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 Lisp_Object buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 CHECK_MARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 if (XMARKER (marker)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 XSETBUFFER (buf, XMARKER (marker)->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 /* Return marker's buffer only if it is not dead. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 if (BUFFER_LIVE_P (XBUFFER (buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 return buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 DEFUN ("marker-position", Fmarker_position, Smarker_position, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 Return the position MARKER points at, as a character number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 Returns `nil' if marker doesn't point anywhere.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 Lisp_Object marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 CHECK_MARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 if (XMARKER (marker)->buffer)
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 (make_int (marker_position (marker)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 }
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 0 /* useful debugging function */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 check_marker_circularities (struct buffer *buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 struct Lisp_Marker *tortoise, *hare;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 tortoise = BUF_MARKERS (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 hare = tortoise;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 if (!tortoise)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 assert (hare->buffer == buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 hare = hare->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 if (!hare)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 assert (hare->buffer == buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 hare = hare->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 if (!hare)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 tortoise = tortoise->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 assert (tortoise != hare);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 set_marker_internal (Lisp_Object marker, Lisp_Object pos, Lisp_Object buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 int restricted_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 Bufpos charno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 struct buffer *b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 struct Lisp_Marker *m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 int point_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 CHECK_MARKER (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 point_p = POINT_MARKER_P (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 /* If position is nil or a marker that points nowhere,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 make this marker point nowhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 if (NILP (pos) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (MARKERP (pos) && !XMARKER (pos)->buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 if (point_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 signal_simple_error ("can't make point-marker point nowhere",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 if (XMARKER (marker)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 unchain_marker (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 return marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 CHECK_INT_COERCE_MARKER (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 if (NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 b = current_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 CHECK_BUFFER (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 b = XBUFFER (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 /* If buffer is dead, set marker to point nowhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 if (!BUFFER_LIVE_P (XBUFFER (buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 if (point_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 signal_simple_error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ("can't move point-marker in a killed buffer", marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 if (XMARKER (marker)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 unchain_marker (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 return marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 charno = XINT (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 m = XMARKER (marker);
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 (restricted_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 if (charno < BUF_BEGV (b)) charno = BUF_BEGV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 if (charno > BUF_ZV (b)) charno = BUF_ZV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 if (charno < BUF_BEG (b)) charno = BUF_BEG (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 if (charno > BUF_Z (b)) charno = BUF_Z (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 if (point_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 #ifndef moving_point_by_moving_its_marker_is_a_bug
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 BUF_SET_PT (b, charno); /* this will move the marker */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 #else /* It's not a feature, so it must be a bug */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 signal_simple_error ("DEBUG: attempt to move point via point-marker",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 m->memind = bufpos_to_memind (b, charno);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 }
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 (m->buffer != b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 if (point_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 signal_simple_error ("can't change buffer of point-marker", marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 if (m->buffer != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 unchain_marker (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 m->buffer = b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 marker_next (m) = BUF_MARKERS (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 marker_prev (m) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 if (BUF_MARKERS (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 marker_prev (BUF_MARKERS (b)) = m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 BUF_MARKERS (b) = m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 return marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 DEFUN ("set-marker", Fset_marker, Sset_marker, 2, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 Position MARKER before character number NUMBER in BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 BUFFER defaults to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 If NUMBER is nil, makes marker point nowhere.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 Then it no longer slows down editing in any buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 If this marker was returned by (point-marker t), then changing its position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 moves point. You cannot change its buffer or make it point nowhere.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 Returns MARKER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (marker, number, buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 Lisp_Object marker, number, buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 return set_marker_internal (marker, number, buffer, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 /* This version of Fset_marker won't let the position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 be outside the visible part. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 set_marker_restricted (Lisp_Object marker, Lisp_Object pos, Lisp_Object buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 return set_marker_internal (marker, pos, buffer, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 /* This is called during garbage collection,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 so we must be careful to ignore and preserve mark bits,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 including those in chain fields of markers. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 unchain_marker (Lisp_Object m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 struct Lisp_Marker *marker = XMARKER (m);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 struct buffer *b = marker->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 if (b == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 assert (BUFFER_LIVE_P (b));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 if (marker_next (marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 marker_prev (marker_next (marker)) = marker_prev (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 if (marker_prev (marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 marker_next (marker_prev (marker)) = marker_next (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 BUF_MARKERS (b) = marker_next (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 assert (marker != XMARKER (b->point_marker));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 marker->buffer = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 bi_marker_position (Lisp_Object marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 struct Lisp_Marker *m = XMARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 struct buffer *buf = m->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 Bytind pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 if (!buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 error ("Marker does not point anywhere");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 /* FSF claims that marker indices could end up denormalized, i.e.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 in the gap. This is way bogus if it ever happens, and means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 something fucked up elsewhere. Since I've overhauled all this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 shit, I don't think this can happen. In any case, the following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 macro has an assert() in it that will catch these denormalized
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 positions. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 pos = memind_to_bytind (buf, m->memind);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 if (pos < BI_BUF_BEG (buf) || pos > BI_BUF_Z (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 return pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 marker_position (Lisp_Object marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 struct buffer *buf = XMARKER (marker)->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 if (!buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 error ("Marker does not point anywhere");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 return bytind_to_bufpos (buf, bi_marker_position (marker));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 set_bi_marker_position (Lisp_Object marker, Bytind pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 struct Lisp_Marker *m = XMARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 struct buffer *buf = m->buffer;
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 (!buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 error ("Marker does not point anywhere");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 if (pos < BI_BUF_BEG (buf) || pos > BI_BUF_Z (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 m->memind = bytind_to_memind (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 set_marker_position (Lisp_Object marker, Bufpos pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 struct buffer *buf = XMARKER (marker)->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 if (!buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 error ("Marker does not point anywhere");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 set_bi_marker_position (marker, bufpos_to_bytind (buf, pos));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 copy_marker_1 (Lisp_Object marker, Lisp_Object type, int noseeum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 REGISTER Lisp_Object new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 if (INTP (marker) || MARKERP (marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 if (noseeum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 new = noseeum_make_marker ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 new = Fmake_marker ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 Fset_marker (new, marker,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (MARKERP (marker) ? Fmarker_buffer (marker) : Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 XMARKER (new)->insertion_type = !NILP (type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 return new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 marker = wrong_type_argument (Qinteger_or_marker_p, marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 RETURN_NOT_REACHED (Qnil) /* not reached */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 DEFUN ("copy-marker", Fcopy_marker, Scopy_marker, 1, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 Return a new marker pointing at the same place as MARKER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 If argument is a number, makes a new marker pointing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 at that position in the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 The optional argument TYPE specifies the insertion type of the new marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 see `marker-insertion-type'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (marker, type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 Lisp_Object marker, type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 return copy_marker_1 (marker, type, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 noseeum_copy_marker (Lisp_Object marker, Lisp_Object type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 return copy_marker_1 (marker, type, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 DEFUN ("marker-insertion-type", Fmarker_insertion_type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 Smarker_insertion_type, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 Return insertion type of MARKER: t if it stays after inserted text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 nil means the marker stays before text inserted there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 register Lisp_Object marker;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 CHECK_MARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 return XMARKER (marker)->insertion_type ? Qt : Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 DEFUN ("set-marker-insertion-type", Fset_marker_insertion_type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 Sset_marker_insertion_type, 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 Set the insertion-type of MARKER to TYPE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 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
437 If TYPE is nil, it means the marker stays behind when you insert text at it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (marker, type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 Lisp_Object marker, type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 CHECK_MARKER (marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 XMARKER (marker)->insertion_type = ! NILP (type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 return type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 #ifdef MEMORY_USAGE_STATS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 compute_buffer_marker_usage (struct buffer *b, struct overhead_stats *ovstats)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 struct Lisp_Marker *m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 int total = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 int overhead;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 for (m = BUF_MARKERS (b); m; m = m->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 total += sizeof (struct Lisp_Marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 ovstats->was_requested += total;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 overhead = fixed_type_block_overhead (total);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 /* #### claiming this is all malloc overhead is not really right,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 but it has to go somewhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 ovstats->malloc_overhead += overhead;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 return total + overhead;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 #endif /* MEMORY_USAGE_STATS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 syms_of_marker (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 defsubr (&Smarker_position);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 defsubr (&Smarker_buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 defsubr (&Sset_marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 defsubr (&Scopy_marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 defsubr (&Smarker_insertion_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 defsubr (&Sset_marker_insertion_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 void init_buffer_markers (struct buffer *b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 init_buffer_markers (struct buffer *b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 Lisp_Object buf = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 XSETBUFFER (buf, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 b->mark = Fmake_marker ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 BUF_MARKERS (b) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 b->point_marker = Fmake_marker ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 Fset_marker (b->point_marker, make_int (1), buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 void uninit_buffer_markers (struct buffer *b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 uninit_buffer_markers (struct buffer *b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 /* Unchain all markers of this buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 and leave them pointing nowhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 REGISTER struct Lisp_Marker *m, *next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 for (m = BUF_MARKERS (b); m; m = next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 m->buffer = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 next = marker_next (m);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 marker_next (m) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 marker_prev (m) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 BUF_MARKERS (b) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 }