From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.bugs Subject: bug#12170: save-excursion fails boundary case with recenter Date: Fri, 10 Aug 2012 16:47:09 +0200 Message-ID: <50251EED.3010804@gmx.at> 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=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1344610077 27344 80.91.229.3 (10 Aug 2012 14:47:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 10 Aug 2012 14:47:57 +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 16:47: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 1SzqVJ-0001WW-3a for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 Aug 2012 16:47:57 +0200 Original-Received: from localhost ([::1]:57067 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzqVI-0001IJ-53 for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 Aug 2012 10:47:56 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:54521) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzqVC-00014Z-Pj for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 10:47:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzqV8-00052T-KQ for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 10:47:50 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:37512) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzqV8-00052N-Gd for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 10:47:46 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Szqd7-0006i3-Ot for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 10:56:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: martin rudalics Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 10 Aug 2012 14:56: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.134461052825750 (code B ref 12170); Fri, 10 Aug 2012 14:56:01 +0000 Original-Received: (at 12170) by debbugs.gnu.org; 10 Aug 2012 14:55:28 +0000 Original-Received: from localhost ([127.0.0.1]:47057 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SzqcZ-0006hH-Ua for submit@debbugs.gnu.org; Fri, 10 Aug 2012 10:55:28 -0400 Original-Received: from mailout-de.gmx.net ([213.165.64.23]:44679) by debbugs.gnu.org with smtp (Exim 4.72) (envelope-from ) id 1SzqcX-0006h7-NU for 12170@debbugs.gnu.org; Fri, 10 Aug 2012 10:55:27 -0400 Original-Received: (qmail invoked by alias); 10 Aug 2012 14:47:08 -0000 Original-Received: from 62-47-41-199.adsl.highway.telekom.at (EHLO [62.47.41.199]) [62.47.41.199] by mail.gmx.net (mp041) with SMTP; 10 Aug 2012 16:47:08 +0200 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX180HSRcu1Q0rYpeAFGB5T7vvEjP33K387GxfjjfpJ O5O5RKnATHZXMx In-Reply-To: <003601cd76fd$b21cd590$165680b0$@com> X-Y-GMX-Trusted: 0 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:63003 Archived-At: > (1) By "window height", I meant the number of lines displayed for the actual > buffer, not counting the mode line or minibuffer. It turns out this is one > less than the value returned by `window-height'. > > (2) The value of `point' changes (the cursor "hops", in other words) when > the window is redisplayed, or when control returns to the user. > > Here is code that will produce the bug (with emacs -Q): > > (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))))) > > If you leave out the `redisplay' call, on the other hand, old = new in the > message -- but after control returns to the user, point has still been moved > in the buffer. I see it now, thanks. Surprisingly it doesn't show up with code like (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) (set-window-point (selected-window) ,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))))) so I'd suspect the culprit somewhere in redisplay_window's code if (w->optional_new_start w->optional_new_start is 1 from `recenter' && CHARPOS (startp) >= BEGV && CHARPOS (startp) <= ZV) { w->optional_new_start = 0; start_display (&it, w, startp); move_it_to (&it, PT, 0, it.last_visible_y, -1, MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y); if (IT_CHARPOS (it) == PT) w->force_start = 1; /* IT may overshoot PT if text at PT is invisible. */ else if (IT_CHARPOS (it) > PT && CHARPOS (startp) <= PT) w->force_start = 1; w->force_start 1 will cause redisplay to honor the start position set up by `recenter' despite of save_excursion_restore's Fgoto_char. } But I don't have the slightest idea how calling (set-window-start (selected-window) ,start t) would remedy this. Eli will soon teach us a lesson here. martin