From: Ryan Yeske <rcyeske+spam@vcn.bc.ca>
Subject: Re: save-restriction, save-excursion
Date: Tue, 17 Sep 2002 02:02:05 GMT [thread overview]
Message-ID: <87ofaxcr3e.fsf@cut.hotdog.tmp> (raw)
In-Reply-To: Xns928C53AA2BB4pokerfaceusenet@130.133.1.4
pokerface <pokerface@use.net> writes:
> I am beginning to study Emacs Lisp and I have the following question:
>
> Why is it wrong to write (save-restriction
> (save-excursion
> ....))
>
> and it is recommended instead to write
> (save-excursion
> (save-restriction
> ....))
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.
> Can someone please give an example of the difference?
(defun do-excursion-restriction ()
(save-excursion
(save-restriction
(do-it))))
(defun do-restriction-excursion ()
(save-restriction
(save-excursion
(do-it))))
(defun do-it ()
(goto-char (point-min))
(narrow-to-region (point) (+ 1 (point))))
;; this one restores point properly:
(do-excursion-restriction)
;; this one doesn't:
(do-restriction-excursion)
;; Hope that helps.
;; Ryan
next prev parent reply other threads:[~2002-09-17 2:02 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 [this message]
2002-09-17 2:33 ` David Kastrup
2002-09-17 6:24 ` Ryan Yeske
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=87ofaxcr3e.fsf@cut.hotdog.tmp \
--to=rcyeske+spam@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.