Mercurial > hg > xemacs-beta
annotate src/marker.c @ 5341:fde0802ee3e0
Zap freebsd.h.
2011-01-18 Mike Sperber <mike@xemacs.org>
* s/freebsd.h: Zap. Not really needed anymore, and it has unclear
license status.
2011-01-15 Mike Sperber <mike@xemacs.org>
* fakemail.c: #include <osreldate.h> on FreeBSD, since we no
longer have freebsd.h.
| author | Mike Sperber <sperber@deinprogramm.de> |
|---|---|
| date | Tue, 18 Jan 2011 10:01:29 +0100 |
| parents | 71ee43b8a74d |
| children | 308d34e9f07d |
| rev | line source |
|---|---|
| 428 | 1 /* Markers: examining, setting and killing. |
| 2 Copyright (C) 1985, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
3 Copyright (C) 2002, 2010 Ben Wing. |
| 428 | 4 |
| 5 This file is part of XEmacs. | |
| 6 | |
| 7 XEmacs is free software; you can redistribute it and/or modify it | |
| 8 under the terms of the GNU General Public License as published by the | |
| 9 Free Software Foundation; either version 2, or (at your option) any | |
| 10 later version. | |
| 11 | |
| 12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
| 13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 15 for more details. | |
| 16 | |
| 17 You should have received a copy of the GNU General Public License | |
| 18 along with XEmacs; see the file COPYING. If not, write to | |
| 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 20 Boston, MA 02111-1307, USA. */ | |
| 21 | |
| 22 /* Synched up with: FSF 19.30. */ | |
| 23 | |
| 24 /* This file has been Mule-ized. */ | |
| 25 | |
| 26 /* Note that markers are currently kept in an unordered list. | |
| 27 This means that marker operations may be inefficient if | |
| 28 there are a bunch of markers in the buffer. This probably | |
| 29 won't have a significant impact on redisplay (which uses | |
| 30 markers), but if it does, it wouldn't be too hard to change | |
| 31 to an ordered gap array. (Just copy the code from extents.c.) | |
| 32 */ | |
| 33 | |
| 34 #include <config.h> | |
| 35 #include "lisp.h" | |
| 36 | |
| 37 #include "buffer.h" | |
| 38 | |
| 39 static Lisp_Object | |
| 40 mark_marker (Lisp_Object obj) | |
| 41 { | |
| 440 | 42 Lisp_Marker *marker = XMARKER (obj); |
| 428 | 43 Lisp_Object buf; |
| 44 /* DO NOT mark through the marker's chain. | |
| 45 The buffer's markers chain does not preserve markers from gc; | |
| 46 Instead, markers are removed from the chain when they are freed | |
| 47 by gc. | |
| 48 */ | |
| 49 if (!marker->buffer) | |
| 50 return (Qnil); | |
| 51 | |
| 793 | 52 buf = wrap_buffer (marker->buffer); |
| 428 | 53 return (buf); |
| 54 } | |
| 55 | |
| 56 static void | |
| 2286 | 57 print_marker (Lisp_Object obj, Lisp_Object printcharfun, |
| 58 int UNUSED (escapeflag)) | |
| 428 | 59 { |
| 440 | 60 Lisp_Marker *marker = XMARKER (obj); |
| 428 | 61 |
| 62 if (print_readably) | |
|
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
63 printing_unreadable_object_fmt ("#<marker 0x%x>", LISP_OBJECT_UID (obj)); |
| 428 | 64 |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
3263
diff
changeset
|
65 write_ascstring (printcharfun, GETTEXT ("#<marker ")); |
| 428 | 66 if (!marker->buffer) |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
3263
diff
changeset
|
67 write_ascstring (printcharfun, GETTEXT ("in no buffer")); |
| 428 | 68 else |
| 69 { | |
| 826 | 70 write_fmt_string (printcharfun, "at %ld in ", |
| 71 (long) marker_position (obj)); | |
| 428 | 72 print_internal (marker->buffer->name, printcharfun, 0); |
| 73 } | |
| 826 | 74 if (marker->insertion_type) |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
3263
diff
changeset
|
75 write_ascstring (printcharfun, " insertion-type=t"); |
|
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
76 write_fmt_string (printcharfun, " 0x%x>", LISP_OBJECT_UID (obj)); |
| 428 | 77 } |
| 78 | |
| 79 static int | |
|
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
3263
diff
changeset
|
80 marker_equal (Lisp_Object obj1, Lisp_Object obj2, int UNUSED (depth), |
|
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
3263
diff
changeset
|
81 int UNUSED (foldcase)) |
| 428 | 82 { |
| 440 | 83 Lisp_Marker *marker1 = XMARKER (obj1); |
| 84 Lisp_Marker *marker2 = XMARKER (obj2); | |
| 428 | 85 |
| 86 return ((marker1->buffer == marker2->buffer) && | |
| 665 | 87 (marker1->membpos == marker2->membpos || |
| 428 | 88 /* All markers pointing nowhere are equal */ |
| 89 !marker1->buffer)); | |
| 90 } | |
| 91 | |
| 2515 | 92 static Hashcode |
|
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5170
diff
changeset
|
93 marker_hash (Lisp_Object obj, int UNUSED (depth), Boolint UNUSED (equalp)) |
| 428 | 94 { |
| 2515 | 95 Hashcode hash = (Hashcode) XMARKER (obj)->buffer; |
| 428 | 96 if (hash) |
| 665 | 97 hash = HASH2 (hash, XMARKER (obj)->membpos); |
| 428 | 98 return hash; |
| 99 } | |
| 100 | |
| 1204 | 101 static const struct memory_description marker_description[] = { |
| 2551 | 102 { XD_LISP_OBJECT, offsetof (Lisp_Marker, next), 0, { 0 }, XD_FLAG_NO_KKCC }, |
| 103 { XD_LISP_OBJECT, offsetof (Lisp_Marker, prev), 0, { 0 }, XD_FLAG_NO_KKCC }, | |
| 440 | 104 { XD_LISP_OBJECT, offsetof (Lisp_Marker, buffer) }, |
| 428 | 105 { XD_END } |
| 106 }; | |
| 107 | |
| 3263 | 108 #ifdef NEW_GC |
| 2720 | 109 static void |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
110 finalize_marker (Lisp_Object obj) |
| 2720 | 111 { |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
112 unchain_marker (obj); |
| 2720 | 113 } |
|
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
114 #endif /* NEW_GC */ |
| 2720 | 115 |
|
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
116 DEFINE_DUMPABLE_FROB_BLOCK_LISP_OBJECT ("marker", marker, |
|
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
117 mark_marker, print_marker, |
|
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
118 IF_NEW_GC (finalize_marker), |
|
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
119 marker_equal, marker_hash, |
|
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
120 marker_description, Lisp_Marker); |
| 428 | 121 |
| 122 /* Operations on markers. */ | |
| 123 | |
| 124 DEFUN ("marker-buffer", Fmarker_buffer, 1, 1, 0, /* | |
| 125 Return the buffer that MARKER points into, or nil if none. | |
| 126 Return nil if MARKER points into a dead buffer or doesn't point anywhere. | |
| 127 */ | |
| 128 (marker)) | |
| 129 { | |
| 130 struct buffer *buf; | |
| 131 CHECK_MARKER (marker); | |
| 132 /* Return marker's buffer only if it is not dead. */ | |
| 133 if ((buf = XMARKER (marker)->buffer) && BUFFER_LIVE_P (buf)) | |
| 134 { | |
| 793 | 135 return wrap_buffer (buf); |
| 428 | 136 } |
| 137 return Qnil; | |
| 138 } | |
| 139 | |
| 140 DEFUN ("marker-position", Fmarker_position, 1, 1, 0, /* | |
| 141 Return the position MARKER points at, as a character number. | |
| 142 Return `nil' if marker doesn't point anywhere. | |
| 143 */ | |
| 144 (marker)) | |
| 145 { | |
| 146 CHECK_MARKER (marker); | |
| 147 return XMARKER (marker)->buffer ? make_int (marker_position (marker)) : Qnil; | |
| 148 } | |
| 149 | |
| 150 #if 0 /* useful debugging function */ | |
| 151 | |
| 152 static void | |
| 153 check_marker_circularities (struct buffer *buf) | |
| 154 { | |
| 440 | 155 Lisp_Marker *tortoise, *hare; |
| 428 | 156 |
| 157 tortoise = BUF_MARKERS (buf); | |
| 158 hare = tortoise; | |
| 159 | |
| 160 if (!tortoise) | |
| 161 return; | |
| 162 | |
| 163 while (1) | |
| 164 { | |
| 165 assert (hare->buffer == buf); | |
| 166 hare = hare->next; | |
| 167 if (!hare) | |
| 168 return; | |
| 169 assert (hare->buffer == buf); | |
| 170 hare = hare->next; | |
| 171 if (!hare) | |
| 172 return; | |
| 173 tortoise = tortoise->next; | |
| 174 assert (tortoise != hare); | |
| 175 } | |
| 176 } | |
| 177 | |
| 178 #endif | |
| 179 | |
| 180 static Lisp_Object | |
| 444 | 181 set_marker_internal (Lisp_Object marker, Lisp_Object position, |
| 182 Lisp_Object buffer, int restricted_p) | |
| 428 | 183 { |
| 665 | 184 Charbpos charno; |
| 428 | 185 struct buffer *b; |
| 440 | 186 Lisp_Marker *m; |
| 428 | 187 int point_p; |
| 188 | |
| 189 CHECK_MARKER (marker); | |
| 190 | |
| 191 point_p = POINT_MARKER_P (marker); | |
| 192 | |
| 193 /* If position is nil or a marker that points nowhere, | |
| 194 make this marker point nowhere. */ | |
| 444 | 195 if (NILP (position) || |
| 196 (MARKERP (position) && !XMARKER (position)->buffer)) | |
| 428 | 197 { |
| 198 if (point_p) | |
| 563 | 199 invalid_operation ("Can't make point-marker point nowhere", |
| 200 marker); | |
| 428 | 201 if (XMARKER (marker)->buffer) |
| 202 unchain_marker (marker); | |
| 203 return marker; | |
| 204 } | |
| 205 | |
| 444 | 206 CHECK_INT_COERCE_MARKER (position); |
| 428 | 207 if (NILP (buffer)) |
| 208 b = current_buffer; | |
| 209 else | |
| 210 { | |
| 211 CHECK_BUFFER (buffer); | |
| 212 b = XBUFFER (buffer); | |
| 213 /* If buffer is dead, set marker to point nowhere. */ | |
| 214 if (!BUFFER_LIVE_P (XBUFFER (buffer))) | |
| 215 { | |
| 216 if (point_p) | |
| 563 | 217 invalid_operation |
| 428 | 218 ("Can't move point-marker in a killed buffer", marker); |
| 219 if (XMARKER (marker)->buffer) | |
| 220 unchain_marker (marker); | |
| 221 return marker; | |
| 222 } | |
| 223 } | |
| 224 | |
| 444 | 225 charno = XINT (position); |
| 428 | 226 m = XMARKER (marker); |
| 227 | |
| 228 if (restricted_p) | |
| 229 { | |
| 230 if (charno < BUF_BEGV (b)) charno = BUF_BEGV (b); | |
| 231 if (charno > BUF_ZV (b)) charno = BUF_ZV (b); | |
| 232 } | |
| 233 else | |
| 234 { | |
| 235 if (charno < BUF_BEG (b)) charno = BUF_BEG (b); | |
| 236 if (charno > BUF_Z (b)) charno = BUF_Z (b); | |
| 237 } | |
| 238 | |
| 239 if (point_p) | |
| 240 { | |
| 241 #ifndef moving_point_by_moving_its_marker_is_a_bug | |
| 242 BUF_SET_PT (b, charno); /* this will move the marker */ | |
| 243 #else /* It's not a feature, so it must be a bug */ | |
| 563 | 244 invalid_operation ("DEBUG: attempt to move point via point-marker", |
| 245 marker); | |
| 428 | 246 #endif |
| 247 } | |
| 248 else | |
| 249 { | |
| 665 | 250 m->membpos = charbpos_to_membpos (b, charno); |
| 428 | 251 } |
| 252 | |
| 253 if (m->buffer != b) | |
| 254 { | |
| 255 if (point_p) | |
| 563 | 256 invalid_operation ("Can't change buffer of point-marker", marker); |
| 428 | 257 if (m->buffer != 0) |
| 258 unchain_marker (marker); | |
| 259 m->buffer = b; | |
| 260 marker_next (m) = BUF_MARKERS (b); | |
| 261 marker_prev (m) = 0; | |
| 262 if (BUF_MARKERS (b)) | |
| 263 marker_prev (BUF_MARKERS (b)) = m; | |
| 264 BUF_MARKERS (b) = m; | |
| 265 } | |
| 266 | |
| 267 return marker; | |
| 268 } | |
| 269 | |
| 270 | |
| 271 DEFUN ("set-marker", Fset_marker, 2, 3, 0, /* | |
| 444 | 272 Move MARKER to position POSITION in BUFFER. |
| 273 POSITION can be a marker, an integer or nil. If POSITION is an | |
| 274 integer, make MARKER point before the POSITIONth character in BUFFER. | |
| 275 If POSITION is nil, makes MARKER point nowhere. Then it no longer | |
| 276 slows down editing in any buffer. If POSITION is less than 1, move | |
| 277 MARKER to the beginning of BUFFER. If POSITION is greater than the | |
| 278 size of BUFFER, move MARKER to the end of BUFFER. | |
| 428 | 279 BUFFER defaults to the current buffer. |
| 444 | 280 If this marker was returned by (point-marker t), then changing its |
| 281 position moves point. You cannot change its buffer or make it point | |
| 282 nowhere. | |
| 283 The return value is MARKER. | |
| 428 | 284 */ |
| 444 | 285 (marker, position, buffer)) |
| 428 | 286 { |
| 444 | 287 return set_marker_internal (marker, position, buffer, 0); |
| 428 | 288 } |
| 289 | |
| 290 | |
| 291 /* This version of Fset_marker won't let the position | |
| 292 be outside the visible part. */ | |
| 293 Lisp_Object | |
| 444 | 294 set_marker_restricted (Lisp_Object marker, Lisp_Object position, |
| 295 Lisp_Object buffer) | |
| 428 | 296 { |
| 444 | 297 return set_marker_internal (marker, position, buffer, 1); |
| 428 | 298 } |
| 299 | |
| 300 | |
| 301 /* This is called during garbage collection, | |
| 302 so we must be careful to ignore and preserve mark bits, | |
| 303 including those in chain fields of markers. */ | |
| 304 | |
| 305 void | |
| 306 unchain_marker (Lisp_Object m) | |
| 307 { | |
| 440 | 308 Lisp_Marker *marker = XMARKER (m); |
| 428 | 309 struct buffer *b = marker->buffer; |
| 310 | |
| 311 if (b == 0) | |
| 312 return; | |
| 313 | |
| 800 | 314 #ifdef ERROR_CHECK_STRUCTURES |
| 428 | 315 assert (BUFFER_LIVE_P (b)); |
| 316 #endif | |
| 317 | |
| 318 if (marker_next (marker)) | |
| 319 marker_prev (marker_next (marker)) = marker_prev (marker); | |
| 320 if (marker_prev (marker)) | |
| 321 marker_next (marker_prev (marker)) = marker_next (marker); | |
| 322 else | |
| 323 BUF_MARKERS (b) = marker_next (marker); | |
| 324 | |
| 800 | 325 #ifdef ERROR_CHECK_STRUCTURES |
| 428 | 326 assert (marker != XMARKER (b->point_marker)); |
| 327 #endif | |
| 328 | |
| 329 marker->buffer = 0; | |
| 330 } | |
| 331 | |
| 665 | 332 Bytebpos |
| 826 | 333 byte_marker_position (Lisp_Object marker) |
| 428 | 334 { |
| 440 | 335 Lisp_Marker *m = XMARKER (marker); |
| 428 | 336 struct buffer *buf = m->buffer; |
| 665 | 337 Bytebpos pos; |
| 428 | 338 |
| 339 if (!buf) | |
| 563 | 340 invalid_argument ("Marker does not point anywhere", Qunbound); |
| 428 | 341 |
| 342 /* FSF claims that marker indices could end up denormalized, i.e. | |
| 343 in the gap. This is way bogus if it ever happens, and means | |
| 344 something fucked up elsewhere. Since I've overhauled all this | |
| 345 shit, I don't think this can happen. In any case, the following | |
| 346 macro has an assert() in it that will catch these denormalized | |
| 347 positions. */ | |
| 665 | 348 pos = membpos_to_bytebpos (buf, m->membpos); |
| 428 | 349 |
| 350 return pos; | |
| 351 } | |
| 352 | |
| 665 | 353 Charbpos |
| 428 | 354 marker_position (Lisp_Object marker) |
| 355 { | |
| 356 struct buffer *buf = XMARKER (marker)->buffer; | |
| 357 | |
| 358 if (!buf) | |
| 563 | 359 invalid_argument ("Marker does not point anywhere", Qunbound); |
| 428 | 360 |
| 826 | 361 return bytebpos_to_charbpos (buf, byte_marker_position (marker)); |
| 428 | 362 } |
| 363 | |
| 364 void | |
| 826 | 365 set_byte_marker_position (Lisp_Object marker, Bytebpos pos) |
| 428 | 366 { |
| 440 | 367 Lisp_Marker *m = XMARKER (marker); |
| 428 | 368 struct buffer *buf = m->buffer; |
| 369 | |
| 370 if (!buf) | |
| 563 | 371 invalid_argument ("Marker does not point anywhere", Qunbound); |
| 428 | 372 |
| 665 | 373 m->membpos = bytebpos_to_membpos (buf, pos); |
| 428 | 374 } |
| 375 | |
| 376 void | |
| 665 | 377 set_marker_position (Lisp_Object marker, Charbpos pos) |
| 428 | 378 { |
| 379 struct buffer *buf = XMARKER (marker)->buffer; | |
| 380 | |
| 381 if (!buf) | |
| 563 | 382 invalid_argument ("Marker does not point anywhere", Qunbound); |
| 428 | 383 |
| 826 | 384 set_byte_marker_position (marker, charbpos_to_bytebpos (buf, pos)); |
| 428 | 385 } |
| 386 | |
| 387 static Lisp_Object | |
| 388 copy_marker_1 (Lisp_Object marker, Lisp_Object type, int noseeum) | |
| 389 { | |
| 3025 | 390 REGISTER Lisp_Object new_; |
| 428 | 391 |
| 392 while (1) | |
| 393 { | |
| 394 if (INTP (marker) || MARKERP (marker)) | |
| 395 { | |
| 396 if (noseeum) | |
| 3025 | 397 new_ = noseeum_make_marker (); |
| 428 | 398 else |
| 3025 | 399 new_ = Fmake_marker (); |
| 400 Fset_marker (new_, marker, | |
| 428 | 401 (MARKERP (marker) ? Fmarker_buffer (marker) : Qnil)); |
| 3025 | 402 XMARKER (new_)->insertion_type = !NILP (type); |
| 403 return new_; | |
| 428 | 404 } |
| 405 else | |
| 406 marker = wrong_type_argument (Qinteger_or_marker_p, marker); | |
| 407 } | |
| 408 | |
| 1204 | 409 RETURN_NOT_REACHED (Qnil); /* not reached */ |
| 428 | 410 } |
| 411 | |
| 412 DEFUN ("copy-marker", Fcopy_marker, 1, 2, 0, /* | |
| 444 | 413 Return a new marker pointing at the same place as MARKER-OR-INTEGER. |
| 414 If MARKER-OR-INTEGER is an integer, return a new marker pointing | |
| 428 | 415 at that position in the current buffer. |
| 444 | 416 Optional argument MARKER-TYPE specifies the insertion type of the new |
| 417 marker; see `marker-insertion-type'. | |
| 428 | 418 */ |
| 444 | 419 (marker_or_integer, marker_type)) |
| 428 | 420 { |
| 444 | 421 return copy_marker_1 (marker_or_integer, marker_type, 0); |
| 428 | 422 } |
| 423 | |
| 424 Lisp_Object | |
| 444 | 425 noseeum_copy_marker (Lisp_Object marker, Lisp_Object marker_type) |
| 428 | 426 { |
| 444 | 427 return copy_marker_1 (marker, marker_type, 1); |
| 428 | 428 } |
| 429 | |
| 430 DEFUN ("marker-insertion-type", Fmarker_insertion_type, 1, 1, 0, /* | |
| 431 Return insertion type of MARKER: t if it stays after inserted text. | |
| 432 nil means the marker stays before text inserted there. | |
| 433 */ | |
| 434 (marker)) | |
| 435 { | |
| 436 CHECK_MARKER (marker); | |
| 437 return XMARKER (marker)->insertion_type ? Qt : Qnil; | |
| 438 } | |
| 439 | |
| 440 DEFUN ("set-marker-insertion-type", Fset_marker_insertion_type, 2, 2, 0, /* | |
| 441 Set the insertion-type of MARKER to TYPE. | |
| 442 If TYPE is t, it means the marker advances when you insert text at it. | |
| 443 If TYPE is nil, it means the marker stays behind when you insert text at it. | |
| 444 */ | |
| 445 (marker, type)) | |
| 446 { | |
| 447 CHECK_MARKER (marker); | |
| 448 | |
| 449 XMARKER (marker)->insertion_type = ! NILP (type); | |
| 450 return type; | |
| 451 } | |
| 452 | |
| 453 /* #### What is the possible use of this? It looks quite useless to | |
| 454 me, because there is no way to find *which* markers are positioned | |
| 455 at POSITION. Additional bogosity bonus: (buffer-has-markers-at | |
| 456 (point)) will always return t because of the `point-marker'. The | |
| 457 same goes for the position of mark. Bletch! | |
| 458 | |
| 459 Someone should discuss this with Stallman, but I don't have the | |
| 460 stomach. In fact, this function sucks so badly that I'm disabling | |
| 461 it by default (although I've debugged it). If you want to use it, | |
| 462 use extents instead. --hniksic */ | |
| 463 #if 0 | |
| 826 | 464 DEFUN ("buffer-has-markers-at", Fbuffer_has_markers_at, 1, 1, 0, /* |
| 428 | 465 Return t if there are markers pointing at POSITION in the current buffer. |
| 466 */ | |
| 467 (position)) | |
| 468 { | |
| 440 | 469 Lisp_Marker *marker; |
| 665 | 470 Membpos pos; |
| 428 | 471 |
| 665 | 472 /* A small optimization trick: convert POS to membpos now, rather |
| 473 than converting every marker's memory index to charbpos. */ | |
| 474 pos = bytebpos_to_membpos (current_buffer, | |
| 428 | 475 get_buffer_pos_byte (current_buffer, position, |
| 476 GB_COERCE_RANGE)); | |
| 477 | |
| 478 for (marker = BUF_MARKERS (current_buffer); | |
| 479 marker; | |
| 480 marker = marker_next (marker)) | |
| 481 { | |
| 665 | 482 /* We use marker->membpos, so we don't have to go through the |
| 428 | 483 unwieldy operation of creating a Lisp_Object for |
| 484 marker_position() every time around. */ | |
| 665 | 485 if (marker->membpos == pos) |
| 428 | 486 return Qt; |
| 487 } | |
| 488 | |
| 489 return Qnil; | |
| 490 } | |
| 491 #endif /* 0 */ | |
| 492 | |
| 493 #ifdef MEMORY_USAGE_STATS | |
| 494 | |
|
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
495 Bytecount |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5169
diff
changeset
|
496 compute_buffer_marker_usage (struct buffer *b) |
| 428 | 497 { |
| 440 | 498 Lisp_Marker *m; |
|
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
499 Bytecount total = 0; |
| 428 | 500 |
| 501 for (m = BUF_MARKERS (b); m; m = m->next) | |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5169
diff
changeset
|
502 total += lisp_object_memory_usage (wrap_marker (m)); |
|
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
503 return total; |
| 428 | 504 } |
| 505 | |
| 506 #endif /* MEMORY_USAGE_STATS */ | |
| 507 | |
| 508 | |
| 509 void | |
| 510 syms_of_marker (void) | |
| 511 { | |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
512 INIT_LISP_OBJECT (marker); |
| 442 | 513 |
| 428 | 514 DEFSUBR (Fmarker_position); |
| 515 DEFSUBR (Fmarker_buffer); | |
| 516 DEFSUBR (Fset_marker); | |
| 517 DEFSUBR (Fcopy_marker); | |
| 518 DEFSUBR (Fmarker_insertion_type); | |
| 519 DEFSUBR (Fset_marker_insertion_type); | |
| 520 #if 0 /* FSFmacs crock */ | |
| 521 DEFSUBR (Fbuffer_has_markers_at); | |
| 522 #endif | |
| 523 } | |
| 524 | |
| 525 void | |
| 526 init_buffer_markers (struct buffer *b) | |
| 527 { | |
| 793 | 528 Lisp_Object buf = wrap_buffer (b); |
| 428 | 529 |
| 530 b->mark = Fmake_marker (); | |
| 531 BUF_MARKERS (b) = 0; | |
| 532 b->point_marker = Fmake_marker (); | |
| 533 Fset_marker (b->point_marker, | |
| 534 /* For indirect buffers, point is already set. */ | |
| 535 b->base_buffer ? make_int (BUF_PT (b)) : make_int (1), | |
| 536 buf); | |
| 537 } | |
| 538 | |
| 539 void | |
| 540 uninit_buffer_markers (struct buffer *b) | |
| 541 { | |
| 542 /* Unchain all markers of this buffer | |
| 543 and leave them pointing nowhere. */ | |
| 440 | 544 REGISTER Lisp_Marker *m, *next; |
| 428 | 545 for (m = BUF_MARKERS (b); m; m = next) |
| 546 { | |
| 547 m->buffer = 0; | |
| 548 next = marker_next (m); | |
| 549 marker_next (m) = 0; | |
| 550 marker_prev (m) = 0; | |
| 551 } | |
| 552 BUF_MARKERS (b) = 0; | |
| 553 } |
