From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Ryan Yeske Newsgroups: gmane.emacs.help Subject: Re: save-restriction, save-excursion Date: Tue, 17 Sep 2002 02:02:05 GMT Sender: help-gnu-emacs-admin@gnu.org Message-ID: <87ofaxcr3e.fsf@cut.hotdog.tmp> References: NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1032228965 26503 127.0.0.1 (17 Sep 2002 02:16:05 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 17 Sep 2002 02:16:05 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17r7uD-0006t2-00 for ; Tue, 17 Sep 2002 04:16:01 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17r7uR-0006PM-00; Mon, 16 Sep 2002 22:16:15 -0400 Original-Path: shelby.stanford.edu!nntp.stanford.edu!newsfeed.stanford.edu!cyclone.bc.net!newsfeed.telusplanet.net!news0.telusplanet.net.POSTED!53ab2750!not-for-mail Original-Newsgroups: comp.emacs,gnu.emacs.help Original-Lines: 46 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Original-NNTP-Posting-Host: 66.183.164.95 Original-X-Trace: news0.telusplanet.net 1032228125 66.183.164.95 (Mon, 16 Sep 2002 20:02:05 MDT) Original-NNTP-Posting-Date: Mon, 16 Sep 2002 20:02:05 MDT Original-Xref: nntp.stanford.edu comp.emacs:74547 gnu.emacs.help:104965 Original-To: help-gnu-emacs@gnu.org Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:1520 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:1520 pokerface 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