Commit d6abb4c7 authored by Miles Bader's avatar Miles Bader
Browse files

(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.
parent 83b6997f
2000-08-18 Miles Bader <miles@gnu.org>
* editfns.c (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.
2000-08-17 Gerd Moellmann <gerd@gnu.org> 2000-08-17 Gerd Moellmann <gerd@gnu.org>
* fileio.c (build_annotations): Add a comment explaining the * fileio.c (build_annotations): Add a comment explaining the
......
...@@ -2681,53 +2681,71 @@ or markers) bounding the text that should remain visible.") ...@@ -2681,53 +2681,71 @@ or markers) bounding the text that should remain visible.")
Lisp_Object Lisp_Object
save_restriction_save () save_restriction_save ()
{ {
register Lisp_Object bottom, top; if (BEGV == BEG && ZV == Z)
/* Note: I tried using markers here, but it does not win /* The common case that the buffer isn't narrowed.
because insertion at the end of the saved region We return just the buffer object, which save_restriction_restore
does not advance mh and is considered "outside" the saved region. */ recognizes as meaning `no restriction'. */
XSETFASTINT (bottom, BEGV - BEG); return Fcurrent_buffer ();
XSETFASTINT (top, Z - ZV); else
/* We have to save a restriction, so return a pair of markers, one
for the beginning and one for the end. */
{
Lisp_Object beg, end;
beg = buildmark (BEGV, BEGV_BYTE);
end = buildmark (ZV, ZV_BYTE);
return Fcons (Fcurrent_buffer (), Fcons (bottom, top)); /* END must move forward if text is inserted at its exact location. */
XMARKER(end)->insertion_type = 1;
return Fcons (beg, end);
}
} }
Lisp_Object Lisp_Object
save_restriction_restore (data) save_restriction_restore (data)
Lisp_Object data; Lisp_Object data;
{ {
register struct buffer *buf; if (CONSP (data))
register int newhead, newtail; /* A pair of marks bounding a saved restriction. */
register Lisp_Object tem; {
int obegv, ozv; struct Lisp_Marker *beg = XMARKER (XCAR (data));
struct Lisp_Marker *end = XMARKER (XCDR (data));
buf = XBUFFER (XCAR (data)); struct buffer *buf = beg->buffer; /* END should have the same buffer. */
data = XCDR (data);
tem = XCAR (data); if (beg->charpos != BUF_BEGV(buf) || end->charpos != BUF_ZV(buf))
newhead = XINT (tem); /* The restriction has changed from the saved one, so restore
tem = XCDR (data); the saved restriction. */
newtail = XINT (tem);
if (newhead + newtail > BUF_Z (buf) - BUF_BEG (buf))
{ {
newhead = 0; int pt = BUF_PT (buf);
newtail = 0;
} SET_BUF_BEGV_BOTH (buf, beg->charpos, beg->bytepos);
SET_BUF_ZV_BOTH (buf, end->charpos, end->bytepos);
obegv = BUF_BEGV (buf); if (pt < beg->charpos || pt > end->charpos)
ozv = BUF_ZV (buf); /* The point is outside the new visible range, move it inside. */
SET_BUF_PT_BOTH (buf,
clip_to_bounds (beg->charpos, pt, end->charpos),
clip_to_bounds (beg->bytepos, BUF_PT_BYTE(buf),
end->bytepos));
SET_BUF_BEGV (buf, BUF_BEG (buf) + newhead); buf->clip_changed = 1; /* Remember that the narrowing changed. */
SET_BUF_ZV (buf, BUF_Z (buf) - newtail); }
}
else
/* A buffer, which means that there was no old restriction. */
{
struct buffer *buf = XBUFFER (data);
if (obegv != BUF_BEGV (buf) || ozv != BUF_ZV (buf)) if (BUF_BEGV(buf) != BUF_BEG(buf) || BUF_ZV(buf) != BUF_Z(buf))
current_buffer->clip_changed = 1; /* The buffer has been narrowed, get rid of the narrowing. */
{
SET_BUF_BEGV_BOTH (buf, BUF_BEG(buf), BUF_BEG_BYTE(buf));
SET_BUF_ZV_BOTH (buf, BUF_Z(buf), BUF_Z_BYTE(buf));
/* If point is outside the new visible range, move it inside. */ buf->clip_changed = 1; /* Remember that the narrowing changed. */
SET_BUF_PT_BOTH (buf, }
clip_to_bounds (BUF_BEGV (buf), BUF_PT (buf), BUF_ZV (buf)), }
clip_to_bounds (BUF_BEGV_BYTE (buf), BUF_PT_BYTE (buf),
BUF_ZV_BYTE (buf)));
return Qnil; return Qnil;
} }
...@@ -2744,10 +2762,6 @@ even in case of abnormal exit (throw or error).\n\ ...@@ -2744,10 +2762,6 @@ even in case of abnormal exit (throw or error).\n\
\n\ \n\
The value returned is the value of the last form in BODY.\n\ The value returned is the value of the last form in BODY.\n\
\n\ \n\
`save-restriction' can get confused if, within the BODY, you widen\n\
and then make changes outside the area within the saved restrictions.\n\
See Info node `(elisp)Narrowing' for details and an appropriate technique.\n\
\n\
Note: if you are using both `save-excursion' and `save-restriction',\n\ Note: if you are using both `save-excursion' and `save-restriction',\n\
use `save-excursion' outermost:\n\ use `save-excursion' outermost:\n\
(save-excursion (save-restriction ...))") (save-excursion (save-restriction ...))")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment