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

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

Re: save-window-excursion doesn't restore point properly


From: Stefan Monnier
Subject: Re: save-window-excursion doesn't restore point properly
Date: Fri, 18 Nov 2005 12:32:18 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

>> Steps to reproduce:
>> 
>> C-x 1
>> C-x 2
>> C-p
>> M-: (save-window-excursion (other-window 1))
>> 
>> Note that the point is restored to the same place the point is in the
>> other window.

>   As written in the documentation, the point of the current buffer is
>   not restored.

I believe Shawn's "point" is not the buffer's point but the window's point.
After all, he doesn't look at the value of `point' at the end of his
command, so all he could witness is the value of `window-point'.

I agree with him that it's a bug.  Why should any point or cursor be moved
if the code you execute doesn't include any kind of movement?

The patch below should fix it.  Any objection?


        Stefan


--- orig/src/window.c
+++ mod/src/window.c
@@ -5697,7 +5743,18 @@
   else
     {
       if (XBUFFER (new_current_buffer) == current_buffer)
-       old_point = PT;
+       /* The code further down is careful to preserve point in current
+          buffer (if current-buffer is equal to new_current_buffer), but
+          that ends up copying one window's point to another if the
+          selected-window before and after both display current-buffer but
+          aren't the same window.  */
+       if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer)
+           && WINDOWP (selected_window)
+           && EQ (XWINDOW (selected_window)->buffer, new_current_buffer)
+           && !EQ (selected_window, data->current_window))
+         old_point = XMARKER (XWINDOW (data->current_window)->pointm)->charpos;
+       else
+         old_point = PT;
       else
        /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
           point in new_current_buffer as of the last time this buffer was




reply via email to

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