From xemacs-m  Sat Apr  5 01:24:29 1997
Received: from martigny.ai.mit.edu (martigny.ai.mit.edu [18.43.0.152])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id BAA07786
	for <xemacs-beta@xemacs.org>; Sat, 5 Apr 1997 01:24:29 -0600 (CST)
Received: from berne.ai.mit.edu by martigny.ai.mit.edu with SMTP
	(1.40.112.8/16.2) id AA020025066; Sat, 5 Apr 1997 02:24:26 -0500
From: Bill Dubuque <wgd@martigny.ai.mit.edu>
Message-Id: <199704050724.AA020025066@martigny.ai.mit.edu>
Received: by berne.ai.mit.edu
	(1.40.112.8/16.2) id AA001425065; Sat, 5 Apr 1997 02:24:25 -0500
Date: Sat, 5 Apr 1997 02:24:25 -0500
To: steve@miranova.com
Cc: xemacs-beta@xemacs.org
In-Reply-To: <m24tdmqp5h.fsf@altair.xemacs.org> (message from Steven L Baur on
	04 Apr 1997 16:39:06 -0800)
Subject: Re: save-excursion sometimes doesn't

: From: Steven L Baur <steve@miranova.com>
: Date: 04 Apr 1997 16:39:06 -0800
: 
: The following example behaves the same way in Emacs 19.34 which leads
: me to believe I'm probably missing something, or we copied a bug.
: 
: Put the following expression in *scratch* and hit C-x C-e at the end
: of it.  Point moves down 4 lines despite the save-excursion.
: 
: (save-excursion
:  (insert-before-markers "\n\n\n\n"))
: 
: I expect it to work like this.
: (let ((opoint (point)))
:  (save-excursion
:    (insert-before-markers "\n\n\n\n"))
:  (goto-char opoint))
: 
: 
: The doc string to save-excursion doesn't say anything about exceptions 
: to the rule, so if this is a feature it needs to be updated.

save-excursion preserves the current buffer and its region.
To preserve the region it of course saves/restores MARKERS for
point and mark, not actual integer buffer positions. Almost never
does one desire to save/restore absolute integer positions since 
they are essentially random pointers after arbitrary buffer 
modifications from within the save-excursion body.

In your example:

[1] save-excursion saves the marker for point
[2] your code inserts 4 \n's before the point-marker
[2] save-excursion restores point to the saved point-marker,
    which is correctly AFTER the inserted newlines, since you 
    requested that they be inserted before any markers,
    which includes the immediately following point-marker.

-Bill Dubuque

