aboutsummaryrefslogtreecommitdiffstats
path: root/src/marker.c
diff options
context:
space:
mode:
authorStefan Monnier2003-06-26 23:17:50 +0000
committerStefan Monnier2003-06-26 23:17:50 +0000
commit5e097e002ba08205c8a4643b3495dbd45462147f (patch)
treebe2d8a17480fc197c5490c2056c4a4995eca105e /src/marker.c
parentdab0b04d496348fbc42155b3970ef4f322a4e972 (diff)
downloademacs-5e097e002ba08205c8a4643b3495dbd45462147f.tar.gz
emacs-5e097e002ba08205c8a4643b3495dbd45462147f.zip
(buf_charpos_to_bytepos, buf_bytepos_to_charpos)
(Fset_marker, set_marker_restricted, set_marker_both, unchain_marker) (set_marker_restricted_both, Fbuffer_has_markers_at, count_markers): Update for new types.
Diffstat (limited to 'src/marker.c')
-rw-r--r--src/marker.c116
1 files changed, 49 insertions, 67 deletions
diff --git a/src/marker.c b/src/marker.c
index b91609ca084..abdc123c876 100644
--- a/src/marker.c
+++ b/src/marker.c
@@ -1,5 +1,5 @@
1/* Markers: examining, setting and deleting. 1/* Markers: examining, setting and deleting.
2 Copyright (C) 1985, 1997, 1998 Free Software Foundation, Inc. 2 Copyright (C) 1985, 1997, 1998, 2003 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -133,7 +133,7 @@ buf_charpos_to_bytepos (b, charpos)
133 struct buffer *b; 133 struct buffer *b;
134 int charpos; 134 int charpos;
135{ 135{
136 Lisp_Object tail; 136 struct Lisp_Marker *tail;
137 int best_above, best_above_byte; 137 int best_above, best_above_byte;
138 int best_below, best_below_byte; 138 int best_below, best_below_byte;
139 139
@@ -169,18 +169,15 @@ buf_charpos_to_bytepos (b, charpos)
169 if (b == cached_buffer && BUF_MODIFF (b) == cached_modiff) 169 if (b == cached_buffer && BUF_MODIFF (b) == cached_modiff)
170 CONSIDER (cached_charpos, cached_bytepos); 170 CONSIDER (cached_charpos, cached_bytepos);
171 171
172 tail = BUF_MARKERS (b); 172 for (tail = BUF_MARKERS (b); tail; tail = tail->next)
173 while (! NILP (tail))
174 { 173 {
175 CONSIDER (XMARKER (tail)->charpos, XMARKER (tail)->bytepos); 174 CONSIDER (tail->charpos, tail->bytepos);
176 175
177 /* If we are down to a range of 50 chars, 176 /* If we are down to a range of 50 chars,
178 don't bother checking any other markers; 177 don't bother checking any other markers;
179 scan the intervening chars directly now. */ 178 scan the intervening chars directly now. */
180 if (best_above - best_below < 50) 179 if (best_above - best_below < 50)
181 break; 180 break;
182
183 tail = XMARKER (tail)->chain;
184 } 181 }
185 182
186 /* We get here if we did not exactly hit one of the known places. 183 /* We get here if we did not exactly hit one of the known places.
@@ -328,7 +325,7 @@ buf_bytepos_to_charpos (b, bytepos)
328 struct buffer *b; 325 struct buffer *b;
329 int bytepos; 326 int bytepos;
330{ 327{
331 Lisp_Object tail; 328 struct Lisp_Marker *tail;
332 int best_above, best_above_byte; 329 int best_above, best_above_byte;
333 int best_below, best_below_byte; 330 int best_below, best_below_byte;
334 331
@@ -355,18 +352,15 @@ buf_bytepos_to_charpos (b, bytepos)
355 if (b == cached_buffer && BUF_MODIFF (b) == cached_modiff) 352 if (b == cached_buffer && BUF_MODIFF (b) == cached_modiff)
356 CONSIDER (cached_bytepos, cached_charpos); 353 CONSIDER (cached_bytepos, cached_charpos);
357 354
358 tail = BUF_MARKERS (b); 355 for (tail = BUF_MARKERS (b); tail; tail = tail->next)
359 while (! NILP (tail))
360 { 356 {
361 CONSIDER (XMARKER (tail)->bytepos, XMARKER (tail)->charpos); 357 CONSIDER (tail->bytepos, tail->charpos);
362 358
363 /* If we are down to a range of 50 chars, 359 /* If we are down to a range of 50 chars,
364 don't bother checking any other markers; 360 don't bother checking any other markers;
365 scan the intervening chars directly now. */ 361 scan the intervening chars directly now. */
366 if (best_above - best_below < 50) 362 if (best_above - best_below < 50)
367 break; 363 break;
368
369 tail = XMARKER (tail)->chain;
370 } 364 }
371 365
372 /* We get here if we did not exactly hit one of the known places. 366 /* We get here if we did not exactly hit one of the known places.
@@ -388,7 +382,7 @@ buf_bytepos_to_charpos (b, bytepos)
388 It will last until the next GC. 382 It will last until the next GC.
389 But don't do it if BUF_MARKERS is nil; 383 But don't do it if BUF_MARKERS is nil;
390 that is a signal from Fset_buffer_multibyte. */ 384 that is a signal from Fset_buffer_multibyte. */
391 if (record && ! NILP (BUF_MARKERS (b))) 385 if (record && BUF_MARKERS (b))
392 { 386 {
393 Lisp_Object marker, buffer; 387 Lisp_Object marker, buffer;
394 marker = Fmake_marker (); 388 marker = Fmake_marker ();
@@ -421,7 +415,7 @@ buf_bytepos_to_charpos (b, bytepos)
421 It will last until the next GC. 415 It will last until the next GC.
422 But don't do it if BUF_MARKERS is nil; 416 But don't do it if BUF_MARKERS is nil;
423 that is a signal from Fset_buffer_multibyte. */ 417 that is a signal from Fset_buffer_multibyte. */
424 if (record && ! NILP (BUF_MARKERS (b))) 418 if (record && BUF_MARKERS (b))
425 { 419 {
426 Lisp_Object marker, buffer; 420 Lisp_Object marker, buffer;
427 marker = Fmake_marker (); 421 marker = Fmake_marker ();
@@ -489,12 +483,14 @@ Returns MARKER. */)
489 register struct Lisp_Marker *m; 483 register struct Lisp_Marker *m;
490 484
491 CHECK_MARKER (marker); 485 CHECK_MARKER (marker);
486 m = XMARKER (marker);
487
492 /* If position is nil or a marker that points nowhere, 488 /* If position is nil or a marker that points nowhere,
493 make this marker point nowhere. */ 489 make this marker point nowhere. */
494 if (NILP (position) 490 if (NILP (position)
495 || (MARKERP (position) && !XMARKER (position)->buffer)) 491 || (MARKERP (position) && !XMARKER (position)->buffer))
496 { 492 {
497 unchain_marker (marker); 493 unchain_marker (m);
498 return marker; 494 return marker;
499 } 495 }
500 496
@@ -507,13 +503,11 @@ Returns MARKER. */)
507 /* If buffer is dead, set marker to point nowhere. */ 503 /* If buffer is dead, set marker to point nowhere. */
508 if (EQ (b->name, Qnil)) 504 if (EQ (b->name, Qnil))
509 { 505 {
510 unchain_marker (marker); 506 unchain_marker (m);
511 return marker; 507 return marker;
512 } 508 }
513 } 509 }
514 510
515 m = XMARKER (marker);
516
517 /* Optimize the special case where we are copying the position 511 /* Optimize the special case where we are copying the position
518 of an existing marker, and MARKER is already in the same buffer. */ 512 of an existing marker, and MARKER is already in the same buffer. */
519 if (MARKERP (position) && b == XMARKER (position)->buffer 513 if (MARKERP (position) && b == XMARKER (position)->buffer
@@ -544,10 +538,10 @@ Returns MARKER. */)
544 538
545 if (m->buffer != b) 539 if (m->buffer != b)
546 { 540 {
547 unchain_marker (marker); 541 unchain_marker (m);
548 m->buffer = b; 542 m->buffer = b;
549 m->chain = BUF_MARKERS (b); 543 m->next = BUF_MARKERS (b);
550 BUF_MARKERS (b) = marker; 544 BUF_MARKERS (b) = m;
551 } 545 }
552 546
553 return marker; 547 return marker;
@@ -565,12 +559,14 @@ set_marker_restricted (marker, pos, buffer)
565 register struct Lisp_Marker *m; 559 register struct Lisp_Marker *m;
566 560
567 CHECK_MARKER (marker); 561 CHECK_MARKER (marker);
562 m = XMARKER (marker);
563
568 /* If position is nil or a marker that points nowhere, 564 /* If position is nil or a marker that points nowhere,
569 make this marker point nowhere. */ 565 make this marker point nowhere. */
570 if (NILP (pos) 566 if (NILP (pos)
571 || (MARKERP (pos) && !XMARKER (pos)->buffer)) 567 || (MARKERP (pos) && !XMARKER (pos)->buffer))
572 { 568 {
573 unchain_marker (marker); 569 unchain_marker (m);
574 return marker; 570 return marker;
575 } 571 }
576 572
@@ -583,13 +579,11 @@ set_marker_restricted (marker, pos, buffer)
583 /* If buffer is dead, set marker to point nowhere. */ 579 /* If buffer is dead, set marker to point nowhere. */
584 if (EQ (b->name, Qnil)) 580 if (EQ (b->name, Qnil))
585 { 581 {
586 unchain_marker (marker); 582 unchain_marker (m);
587 return marker; 583 return marker;
588 } 584 }
589 } 585 }
590 586
591 m = XMARKER (marker);
592
593 /* Optimize the special case where we are copying the position 587 /* Optimize the special case where we are copying the position
594 of an existing marker, and MARKER is already in the same buffer. */ 588 of an existing marker, and MARKER is already in the same buffer. */
595 if (MARKERP (pos) && b == XMARKER (pos)->buffer 589 if (MARKERP (pos) && b == XMARKER (pos)->buffer
@@ -620,10 +614,10 @@ set_marker_restricted (marker, pos, buffer)
620 614
621 if (m->buffer != b) 615 if (m->buffer != b)
622 { 616 {
623 unchain_marker (marker); 617 unchain_marker (m);
624 m->buffer = b; 618 m->buffer = b;
625 m->chain = BUF_MARKERS (b); 619 m->next = BUF_MARKERS (b);
626 BUF_MARKERS (b) = marker; 620 BUF_MARKERS (b) = m;
627 } 621 }
628 622
629 return marker; 623 return marker;
@@ -641,6 +635,7 @@ set_marker_both (marker, buffer, charpos, bytepos)
641 register struct Lisp_Marker *m; 635 register struct Lisp_Marker *m;
642 636
643 CHECK_MARKER (marker); 637 CHECK_MARKER (marker);
638 m = XMARKER (marker);
644 639
645 if (NILP (buffer)) 640 if (NILP (buffer))
646 b = current_buffer; 641 b = current_buffer;
@@ -651,13 +646,11 @@ set_marker_both (marker, buffer, charpos, bytepos)
651 /* If buffer is dead, set marker to point nowhere. */ 646 /* If buffer is dead, set marker to point nowhere. */
652 if (EQ (b->name, Qnil)) 647 if (EQ (b->name, Qnil))
653 { 648 {
654 unchain_marker (marker); 649 unchain_marker (m);
655 return marker; 650 return marker;
656 } 651 }
657 } 652 }
658 653
659 m = XMARKER (marker);
660
661 /* In a single-byte buffer, the two positions must be equal. */ 654 /* In a single-byte buffer, the two positions must be equal. */
662 if (BUF_Z (b) == BUF_Z_BYTE (b) 655 if (BUF_Z (b) == BUF_Z_BYTE (b)
663 && charpos != bytepos) 656 && charpos != bytepos)
@@ -671,10 +664,10 @@ set_marker_both (marker, buffer, charpos, bytepos)
671 664
672 if (m->buffer != b) 665 if (m->buffer != b)
673 { 666 {
674 unchain_marker (marker); 667 unchain_marker (m);
675 m->buffer = b; 668 m->buffer = b;
676 m->chain = BUF_MARKERS (b); 669 m->next = BUF_MARKERS (b);
677 BUF_MARKERS (b) = marker; 670 BUF_MARKERS (b) = m;
678 } 671 }
679 672
680 return marker; 673 return marker;
@@ -692,6 +685,7 @@ set_marker_restricted_both (marker, buffer, charpos, bytepos)
692 register struct Lisp_Marker *m; 685 register struct Lisp_Marker *m;
693 686
694 CHECK_MARKER (marker); 687 CHECK_MARKER (marker);
688 m = XMARKER (marker);
695 689
696 if (NILP (buffer)) 690 if (NILP (buffer))
697 b = current_buffer; 691 b = current_buffer;
@@ -702,13 +696,11 @@ set_marker_restricted_both (marker, buffer, charpos, bytepos)
702 /* If buffer is dead, set marker to point nowhere. */ 696 /* If buffer is dead, set marker to point nowhere. */
703 if (EQ (b->name, Qnil)) 697 if (EQ (b->name, Qnil))
704 { 698 {
705 unchain_marker (marker); 699 unchain_marker (m);
706 return marker; 700 return marker;
707 } 701 }
708 } 702 }
709 703
710 m = XMARKER (marker);
711
712 if (charpos < BUF_BEGV (b)) 704 if (charpos < BUF_BEGV (b))
713 charpos = BUF_BEGV (b); 705 charpos = BUF_BEGV (b);
714 if (charpos > BUF_ZV (b)) 706 if (charpos > BUF_ZV (b))
@@ -731,10 +723,10 @@ set_marker_restricted_both (marker, buffer, charpos, bytepos)
731 723
732 if (m->buffer != b) 724 if (m->buffer != b)
733 { 725 {
734 unchain_marker (marker); 726 unchain_marker (m);
735 m->buffer = b; 727 m->buffer = b;
736 m->chain = BUF_MARKERS (b); 728 m->next = BUF_MARKERS (b);
737 BUF_MARKERS (b) = marker; 729 BUF_MARKERS (b) = m;
738 } 730 }
739 731
740 return marker; 732 return marker;
@@ -749,46 +741,40 @@ set_marker_restricted_both (marker, buffer, charpos, bytepos)
749 741
750void 742void
751unchain_marker (marker) 743unchain_marker (marker)
752 register Lisp_Object marker; 744 register struct Lisp_Marker *marker;
753{ 745{
754 register Lisp_Object tail, prev, next; 746 register struct Lisp_Marker *tail, *prev, *next;
755 register EMACS_INT omark;
756 register struct buffer *b; 747 register struct buffer *b;
757 748
758 b = XMARKER (marker)->buffer; 749 b = marker->buffer;
759 if (b == 0) 750 if (b == 0)
760 return; 751 return;
761 752
762 if (EQ (b->name, Qnil)) 753 if (EQ (b->name, Qnil))
763 abort (); 754 abort ();
764 755
765 XMARKER (marker)->buffer = 0; 756 marker->buffer = 0;
766 757
767 tail = BUF_MARKERS (b); 758 tail = BUF_MARKERS (b);
768 prev = Qnil; 759 prev = NULL;
769 while (! GC_NILP (tail)) 760 while (tail)
770 { 761 {
771 next = XMARKER (tail)->chain; 762 next = tail->next;
772 XUNMARK (next);
773 763
774 if (XMARKER (marker) == XMARKER (tail)) 764 if (marker == tail)
775 { 765 {
776 if (NILP (prev)) 766 if (!prev)
777 { 767 {
778 BUF_MARKERS (b) = next; 768 BUF_MARKERS (b) = next;
779 /* Deleting first marker from the buffer's chain. Crash 769 /* Deleting first marker from the buffer's chain. Crash
780 if new first marker in chain does not say it belongs 770 if new first marker in chain does not say it belongs
781 to the same buffer, or at least that they have the same 771 to the same buffer, or at least that they have the same
782 base buffer. */ 772 base buffer. */
783 if (!NILP (next) && b->text != XMARKER (next)->buffer->text) 773 if (next && b->text != next->buffer->text)
784 abort (); 774 abort ();
785 } 775 }
786 else 776 else
787 { 777 prev->next = next;
788 omark = XMARKBIT (XMARKER (prev)->chain);
789 XMARKER (prev)->chain = next;
790 XSETMARKBIT (XMARKER (prev)->chain, omark);
791 }
792 /* We have removed the marker from the chain; 778 /* We have removed the marker from the chain;
793 no need to scan the rest of the chain. */ 779 no need to scan the rest of the chain. */
794 return; 780 return;
@@ -888,7 +874,7 @@ DEFUN ("buffer-has-markers-at", Fbuffer_has_markers_at, Sbuffer_has_markers_at,
888 (position) 874 (position)
889 Lisp_Object position; 875 Lisp_Object position;
890{ 876{
891 register Lisp_Object tail; 877 register struct Lisp_Marker *tail;
892 register int charno; 878 register int charno;
893 879
894 charno = XINT (position); 880 charno = XINT (position);
@@ -898,10 +884,8 @@ DEFUN ("buffer-has-markers-at", Fbuffer_has_markers_at, Sbuffer_has_markers_at,
898 if (charno > Z) 884 if (charno > Z)
899 charno = Z; 885 charno = Z;
900 886
901 for (tail = BUF_MARKERS (current_buffer); 887 for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next)
902 !NILP (tail); 888 if (tail->charpos == charno)
903 tail = XMARKER (tail)->chain)
904 if (XMARKER (tail)->charpos == charno)
905 return Qt; 889 return Qt;
906 890
907 return Qnil; 891 return Qnil;
@@ -914,11 +898,9 @@ count_markers (buf)
914 struct buffer *buf; 898 struct buffer *buf;
915{ 899{
916 int total = 0; 900 int total = 0;
917 Lisp_Object tail; 901 struct Lisp_Marker *tail;
918 902
919 for (tail = BUF_MARKERS (buf); 903 for (tail = BUF_MARKERS (buf); tail; tail = tail->next)
920 !NILP (tail);
921 tail = XMARKER (tail)->chain)
922 total++; 904 total++;
923 905
924 return total; 906 return total;