From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Bill Brodie" Newsgroups: gmane.emacs.bugs Subject: bug#12170: save-excursion fails boundary case with recenter Date: Fri, 10 Aug 2012 11:46:25 -0400 Message-ID: <006101cd770f$4cd7d380$e6877a80$@com> 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; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1344613615 26158 80.91.229.3 (10 Aug 2012 15:46:55 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 10 Aug 2012 15:46:55 +0000 (UTC) Cc: 12170@debbugs.gnu.org To: "'Stefan Monnier'" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Aug 10 17:46:54 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 1SzrQL-0006eR-OY for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 Aug 2012 17:46:53 +0200 Original-Received: from localhost ([::1]:40788 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzrQL-0002HS-0J for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 Aug 2012 11:46:53 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:53414) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzrQG-0002H9-S1 for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 11:46:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzrQE-0000jl-OZ for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 11:46:48 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:37597) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzrQE-0000jf-LT for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 11:46:46 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SzrYE-00082u-14 for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 11:55:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Bill Brodie" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 10 Aug 2012 15:55: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.134461409230912 (code B ref 12170); Fri, 10 Aug 2012 15:55:01 +0000 Original-Received: (at 12170) by debbugs.gnu.org; 10 Aug 2012 15:54:52 +0000 Original-Received: from localhost ([127.0.0.1]:47142 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SzrY3-00082X-Nw for submit@debbugs.gnu.org; Fri, 10 Aug 2012 11:54:51 -0400 Original-Received: from mailbackend.panix.com ([166.84.1.89]:57725) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SzrY1-00082P-Lo for 12170@debbugs.gnu.org; Fri, 10 Aug 2012 11:54:50 -0400 Original-Received: from Chianti (cpe-67-250-32-171.nyc.res.rr.com [67.250.32.171]) by mailbackend.panix.com (Postfix) with ESMTP id 195CE28354; Fri, 10 Aug 2012 11:46:33 -0400 (EDT) In-Reply-To: X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac13CX2lO64ULKKRTeCzmRKokxrwUAAAMwwQ Content-Language: en-us 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:63006 Archived-At: Thanks, Stefan. The purpose of the original code was to scroll the window so that a previous section marker is at the top of the window only if it will fit without moving point: (defun f () (interactive) (save-excursion (re-search-backward "^__") (beginning-of-line) (recenter 0))) I was surprised to discover that this fails if the span of lines from the previous section marker to the current position, inclusive, just barely won't fit in the window. Perhaps the moral is that `save-excursion' should not enclose any code, including `recenter', that affects how buffers are displayed within windows. Bill -----Original Message----- > (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