From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#12170: save-excursion fails boundary case with recenter Date: Sat, 11 Aug 2012 18:10:26 +0300 Message-ID: <83mx21cvml.fsf@gnu.org> References: <000001cd7696$b0e93d60$12bbb820$@com> <5024D593.7080305@gmx.at> <003601cd76fd$b21cd590$165680b0$@com> <50251EED.3010804@gmx.at> <83393uefkw.fsf@gnu.org> <502626AD.1080505@gmx.at> <83sjbtd6p0.fsf@gnu.org> <50266AAF.4000504@gmx.at> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: dough.gmane.org 1344697861 12520 80.91.229.3 (11 Aug 2012 15:11:01 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 11 Aug 2012 15:11:01 +0000 (UTC) Cc: 12170@debbugs.gnu.org, wbrodie@panix.com To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Aug 11 17:10:58 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 1T0DKx-0006eM-Av for geb-bug-gnu-emacs@m.gmane.org; Sat, 11 Aug 2012 17:10:47 +0200 Original-Received: from localhost ([::1]:36822 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0DKw-0001ok-5D for geb-bug-gnu-emacs@m.gmane.org; Sat, 11 Aug 2012 11:10:46 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:50470) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0DKt-0001oU-KR for bug-gnu-emacs@gnu.org; Sat, 11 Aug 2012 11:10:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T0DKr-0000Yz-9d for bug-gnu-emacs@gnu.org; Sat, 11 Aug 2012 11:10:43 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:40011) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0DKr-0000Yv-62 for bug-gnu-emacs@gnu.org; Sat, 11 Aug 2012 11:10:41 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1T0DSw-0001rb-D5 for bug-gnu-emacs@gnu.org; Sat, 11 Aug 2012 11:19:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 11 Aug 2012 15:19:02 +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.13446983227135 (code B ref 12170); Sat, 11 Aug 2012 15:19:02 +0000 Original-Received: (at 12170) by debbugs.gnu.org; 11 Aug 2012 15:18:42 +0000 Original-Received: from localhost ([127.0.0.1]:49557 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T0DSc-0001r2-D0 for submit@debbugs.gnu.org; Sat, 11 Aug 2012 11:18:42 -0400 Original-Received: from mtaout20.012.net.il ([80.179.55.166]:44415) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T0DSZ-0001qu-OL for 12170@debbugs.gnu.org; Sat, 11 Aug 2012 11:18:41 -0400 Original-Received: from conversion-daemon.a-mtaout20.012.net.il by a-mtaout20.012.net.il (HyperSendmail v2007.08) id <0M8L00H00IWLDB00@a-mtaout20.012.net.il> for 12170@debbugs.gnu.org; Sat, 11 Aug 2012 18:10:17 +0300 (IDT) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout20.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0M8L00H6JJH4HI10@a-mtaout20.012.net.il>; Sat, 11 Aug 2012 18:10:16 +0300 (IDT) In-reply-to: <50266AAF.4000504@gmx.at> X-012-Sender: halo1@inter.net.il 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:63040 Archived-At: > Date: Sat, 11 Aug 2012 16:22:39 +0200 > From: martin rudalics > CC: wbrodie@panix.com, 12170@debbugs.gnu.org > > (progn > (defmacro save-this-window-excursion (&rest body) > "..." > (let ((start (make-symbol "start")) > (point (make-symbol "point"))) > `(let ((,start (copy-marker (window-start))) > (,point (copy-marker (window-point)))) > (save-selected-window > (progn ,@body)) > (set-window-start (selected-window) ,start t) > (with-current-buffer (window-buffer (selected-window)) > (goto-char ,point))))) > > (defun f (n) > (save-this-window-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))))) > > I get the same results as with `set-window-point'. IMHO the > `set-window-start' call makes the difference but I don't understand why. Maybe. If it's really important, I could try looking at this in the debugger, although doing so to investigate such situations is notoriously hard, because redisplay is entered several times. IMO, save-excursion is simply not designed to make sure display isn't changed in such cases. It's for excursions into other portions of the buffer for processing those other parts, without affecting display. If the processing also scrolls the screen or calls recenter or otherwise affects the display, all bets are off, because scrolling can legitimately move point, and when that happens, it is no longer clear that restoring point should take precedence over window-start etc.