bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#12170: save-excursion fails boundary case with recenter


From: Bill Brodie
Subject: bug#12170: save-excursion fails boundary case with recenter
Date: Fri, 10 Aug 2012 09:40:24 -0400

Martin,

Thanks for the test code and clarification request.

(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.

Bill

-----Original Message-----
From: martin rudalics [mailto:rudalics@gmx.at] 
Sent: Friday, August 10, 2012 5:34 AM
To: Bill Brodie
Cc: 12170@debbugs.gnu.org
Subject: Re: bug#12170: save-excursion fails boundary case with recenter

 >                 (defun f (n) (save-excursion (forward-line (- n))
(recenter
 > 0)))
 >
 >
 >
 > Let H be the window height in lines, and suppose that point is positioned
at  > the beginning of line L > H.
 >
 >
 >
 > Despite 'save-excursion', (f K) moves point if K = H.  It leaves point  >
unchanged for any other value of K, 0 <= K < L.

I'm not sure whether I clearly understand your scenario.  Suppose with emacs
-Q I evaluate

(progn
   (defun f (n)
     (save-excursion (forward-line (- n)) (recenter 0)))
   (let ((buffer (switch-to-buffer "foo"))
        (height (window-height (get-buffer-window "foo"))))
     (insert-char 10 (* height 2))
     (let ((pt (point)))
       (f height)
       (message "old %s new %s" pt (point)))))

Then the values printed by the message are equal.  Please elaborate.

Thanks, martin






reply via email to

[Prev in Thread] Current Thread [Next in Thread]