Mercurial > emacs
comparison src/editfns.c @ 30931:35428eaf59e3
(save_restriction_save): Rewrite to use markers.
(save_restriction_restore): Rewrite to understand new form of data
saved by save_restriction_save.
(Fsave_restriction): Remove cautionary note in doc-string.
author | Miles Bader <miles@gnu.org> |
---|---|
date | Fri, 18 Aug 2000 00:42:49 +0000 |
parents | 9193f208ef24 |
children | b26ac1565dd4 |
comparison
equal
deleted
inserted
replaced
30930:ac1cc84d89c9 | 30931:35428eaf59e3 |
---|---|
2679 } | 2679 } |
2680 | 2680 |
2681 Lisp_Object | 2681 Lisp_Object |
2682 save_restriction_save () | 2682 save_restriction_save () |
2683 { | 2683 { |
2684 register Lisp_Object bottom, top; | 2684 if (BEGV == BEG && ZV == Z) |
2685 /* Note: I tried using markers here, but it does not win | 2685 /* The common case that the buffer isn't narrowed. |
2686 because insertion at the end of the saved region | 2686 We return just the buffer object, which save_restriction_restore |
2687 does not advance mh and is considered "outside" the saved region. */ | 2687 recognizes as meaning `no restriction'. */ |
2688 XSETFASTINT (bottom, BEGV - BEG); | 2688 return Fcurrent_buffer (); |
2689 XSETFASTINT (top, Z - ZV); | 2689 else |
2690 | 2690 /* We have to save a restriction, so return a pair of markers, one |
2691 return Fcons (Fcurrent_buffer (), Fcons (bottom, top)); | 2691 for the beginning and one for the end. */ |
2692 { | |
2693 Lisp_Object beg, end; | |
2694 | |
2695 beg = buildmark (BEGV, BEGV_BYTE); | |
2696 end = buildmark (ZV, ZV_BYTE); | |
2697 | |
2698 /* END must move forward if text is inserted at its exact location. */ | |
2699 XMARKER(end)->insertion_type = 1; | |
2700 | |
2701 return Fcons (beg, end); | |
2702 } | |
2692 } | 2703 } |
2693 | 2704 |
2694 Lisp_Object | 2705 Lisp_Object |
2695 save_restriction_restore (data) | 2706 save_restriction_restore (data) |
2696 Lisp_Object data; | 2707 Lisp_Object data; |
2697 { | 2708 { |
2698 register struct buffer *buf; | 2709 if (CONSP (data)) |
2699 register int newhead, newtail; | 2710 /* A pair of marks bounding a saved restriction. */ |
2700 register Lisp_Object tem; | 2711 { |
2701 int obegv, ozv; | 2712 struct Lisp_Marker *beg = XMARKER (XCAR (data)); |
2702 | 2713 struct Lisp_Marker *end = XMARKER (XCDR (data)); |
2703 buf = XBUFFER (XCAR (data)); | 2714 struct buffer *buf = beg->buffer; /* END should have the same buffer. */ |
2704 | 2715 |
2705 data = XCDR (data); | 2716 if (beg->charpos != BUF_BEGV(buf) || end->charpos != BUF_ZV(buf)) |
2706 | 2717 /* The restriction has changed from the saved one, so restore |
2707 tem = XCAR (data); | 2718 the saved restriction. */ |
2708 newhead = XINT (tem); | 2719 { |
2709 tem = XCDR (data); | 2720 int pt = BUF_PT (buf); |
2710 newtail = XINT (tem); | 2721 |
2711 if (newhead + newtail > BUF_Z (buf) - BUF_BEG (buf)) | 2722 SET_BUF_BEGV_BOTH (buf, beg->charpos, beg->bytepos); |
2712 { | 2723 SET_BUF_ZV_BOTH (buf, end->charpos, end->bytepos); |
2713 newhead = 0; | 2724 |
2714 newtail = 0; | 2725 if (pt < beg->charpos || pt > end->charpos) |
2715 } | 2726 /* The point is outside the new visible range, move it inside. */ |
2716 | 2727 SET_BUF_PT_BOTH (buf, |
2717 obegv = BUF_BEGV (buf); | 2728 clip_to_bounds (beg->charpos, pt, end->charpos), |
2718 ozv = BUF_ZV (buf); | 2729 clip_to_bounds (beg->bytepos, BUF_PT_BYTE(buf), |
2719 | 2730 end->bytepos)); |
2720 SET_BUF_BEGV (buf, BUF_BEG (buf) + newhead); | 2731 |
2721 SET_BUF_ZV (buf, BUF_Z (buf) - newtail); | 2732 buf->clip_changed = 1; /* Remember that the narrowing changed. */ |
2722 | 2733 } |
2723 if (obegv != BUF_BEGV (buf) || ozv != BUF_ZV (buf)) | 2734 } |
2724 current_buffer->clip_changed = 1; | 2735 else |
2725 | 2736 /* A buffer, which means that there was no old restriction. */ |
2726 /* If point is outside the new visible range, move it inside. */ | 2737 { |
2727 SET_BUF_PT_BOTH (buf, | 2738 struct buffer *buf = XBUFFER (data); |
2728 clip_to_bounds (BUF_BEGV (buf), BUF_PT (buf), BUF_ZV (buf)), | 2739 |
2729 clip_to_bounds (BUF_BEGV_BYTE (buf), BUF_PT_BYTE (buf), | 2740 if (BUF_BEGV(buf) != BUF_BEG(buf) || BUF_ZV(buf) != BUF_Z(buf)) |
2730 BUF_ZV_BYTE (buf))); | 2741 /* The buffer has been narrowed, get rid of the narrowing. */ |
2742 { | |
2743 SET_BUF_BEGV_BOTH (buf, BUF_BEG(buf), BUF_BEG_BYTE(buf)); | |
2744 SET_BUF_ZV_BOTH (buf, BUF_Z(buf), BUF_Z_BYTE(buf)); | |
2745 | |
2746 buf->clip_changed = 1; /* Remember that the narrowing changed. */ | |
2747 } | |
2748 } | |
2731 | 2749 |
2732 return Qnil; | 2750 return Qnil; |
2733 } | 2751 } |
2734 | 2752 |
2735 DEFUN ("save-restriction", Fsave_restriction, Ssave_restriction, 0, UNEVALLED, 0, | 2753 DEFUN ("save-restriction", Fsave_restriction, Ssave_restriction, 0, UNEVALLED, 0, |
2741 So any `narrow-to-region' within BODY lasts only until the end of the form.\n\ | 2759 So any `narrow-to-region' within BODY lasts only until the end of the form.\n\ |
2742 The old restrictions settings are restored\n\ | 2760 The old restrictions settings are restored\n\ |
2743 even in case of abnormal exit (throw or error).\n\ | 2761 even in case of abnormal exit (throw or error).\n\ |
2744 \n\ | 2762 \n\ |
2745 The value returned is the value of the last form in BODY.\n\ | 2763 The value returned is the value of the last form in BODY.\n\ |
2746 \n\ | |
2747 `save-restriction' can get confused if, within the BODY, you widen\n\ | |
2748 and then make changes outside the area within the saved restrictions.\n\ | |
2749 See Info node `(elisp)Narrowing' for details and an appropriate technique.\n\ | |
2750 \n\ | 2764 \n\ |
2751 Note: if you are using both `save-excursion' and `save-restriction',\n\ | 2765 Note: if you are using both `save-excursion' and `save-restriction',\n\ |
2752 use `save-excursion' outermost:\n\ | 2766 use `save-excursion' outermost:\n\ |
2753 (save-excursion (save-restriction ...))") | 2767 (save-excursion (save-restriction ...))") |
2754 (body) | 2768 (body) |