all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ryan Yeske <rcyeske@vcn.bc.ca>
Subject: Re: save-restriction, save-excursion
Date: Tue, 17 Sep 2002 06:24:18 GMT	[thread overview]
Message-ID: <87fzw9ceye.fsf@cut.hotdog.tmp> (raw)
In-Reply-To: x5hegppcoi.fsf@tupik.goethe.zz

David Kastrup <David.Kastrup@t-online.de> writes:

> Ryan Yeske <rcyeske+spam@vcn.bc.ca> writes:
> 
> > From the node "Narrowing" in the elisp manual:
> > 
> >      `save-restriction' does _not_ restore point and the mark; use
> >      `save-excursion' for that.  If you use both `save-restriction' and
> >      `save-excursion' together, `save-excursion' should come first (on
> >      the outside).  Otherwise, the old point value would be restored
> >      with temporary narrowing still in effect.  If the old point value
> >      were outside the limits of the temporary narrowing, this would
> >      fail to restore it accurately.
> 
> Hmmm.  What if I have a restriction active and write
> (save-excursion
>   (save-restriction
>     (widen)
>     (goto (point-min))))
> 
> When the restriction gets restored, point will lie outside of the
> restored restriction.  Wouldn't that cause trouble?

Try it :)

It helps me to think about it like this:

1) save the point
2) save the restriction
3) frob the restriction (narrow *or* widen)
4) frob the point
5) restore the old restriction
6) restore the old point
 
It doesn't matter whether you are widening or narrowing.  When the
restriction is restored (step 5), the point is adjusted to be within
the restriction (the point can never be outside the current
restriction).  It doesn't really matter though, since the point is
then immediatly restored to the initial value within the initial
restriction at step 6.

Ryan

  reply	other threads:[~2002-09-17  6:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-16 23:31 save-restriction, save-excursion pokerface
2002-09-17  2:02 ` Ryan Yeske
2002-09-17  2:33   ` David Kastrup
2002-09-17  6:24     ` Ryan Yeske [this message]
2002-09-18 22:17       ` pokerface

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fzw9ceye.fsf@cut.hotdog.tmp \
    --to=rcyeske@vcn.bc.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.