From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#12170: save-excursion fails boundary case with recenter Date: Fri, 10 Aug 2012 11:04:47 -0400 Message-ID: References: <000001cd7696$b0e93d60$12bbb820$@com> <5024D593.7080305@gmx.at> <003601cd76fd$b21cd590$165680b0$@com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1344611167 4320 80.91.229.3 (10 Aug 2012 15:06:07 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 10 Aug 2012 15:06:07 +0000 (UTC) Cc: 12170@debbugs.gnu.org To: "Bill Brodie" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Aug 10 17:06:04 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Szqmh-00060O-0N for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 Aug 2012 17:05:55 +0200 Original-Received: from localhost ([::1]:44115 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Szqmg-0002K0-3f for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 Aug 2012 11:05:54 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:47571) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Szqmc-0002Jm-CX for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 11:05:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzqmY-0002nn-EM for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 11:05:50 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:37545) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzqmY-0002ne-BV for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 11:05:46 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SzquX-00077W-Vd for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 11:14:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 10 Aug 2012 15:14:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12170 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 12170-submit@debbugs.gnu.org id=B12170.134461158727297 (code B ref 12170); Fri, 10 Aug 2012 15:14:01 +0000 Original-Received: (at 12170) by debbugs.gnu.org; 10 Aug 2012 15:13:07 +0000 Original-Received: from localhost ([127.0.0.1]:47091 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Szqte-00076E-IA for submit@debbugs.gnu.org; Fri, 10 Aug 2012 11:13:06 -0400 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:35846) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Szqtc-000766-0M for 12170@debbugs.gnu.org; Fri, 10 Aug 2012 11:13:04 -0400 Original-Received: from faina.iro.umontreal.ca (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id q7AF4lnn000341; Fri, 10 Aug 2012 11:04:47 -0400 Original-Received: by faina.iro.umontreal.ca (Postfix, from userid 20848) id 4DA13B4177; Fri, 10 Aug 2012 11:04:47 -0400 (EDT) In-Reply-To: <003601cd76fd$b21cd590$165680b0$@com> (Bill Brodie's message of "Fri, 10 Aug 2012 09:40:24 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV4306=0 X-NAI-Spam-Version: 2.2.0.9309 : core <4306> : streams <797204> : uri <1188930> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:63005 Archived-At: > (progn > (defun f (n) > (save-excursion (forward-line (- n)) (recenter 0))) > (let ((buffer (switch-to-buffer "foo")) > (height (1- (window-height (get-buffer-window "foo"))))) > (insert-char 10 (* height 2)) > (let ((pt (point))) > (f height) > (redisplay) > (message "height %s old %s new %s" height pt (point))))) As mentioned by Martin, this is a misunderstanding about what save-excursion does and what `point' is. Every buffer can have many different `point's (it basically has one per window, accessible via `window-point' and changeable via `set-window-point', plus one for itself, called `point'). `save-excursion' preserves only `point'. `recenter' changes `window-point'. But `point' and `window-point' are linked (point is set to window-point and vice-versa in various occasions), so they're often confused. It seems your real problem is not that `point' changes but that the cursor ends up in a different position than the one you wanted (the cursor position, is represented by `window-point' rather than by `point'), right? If so, you want to preserve window-point. And there's nothing quite like save-excursion to preserve window-point. You can try save-window-excursion, tho it will do a lot more than you asked for. Or otherwise manually read window-point at the beginning and set-window-point at the end. Stefan