GNU bug report logs - #10971
Problem with `split-window-keep-point' set to `nil'

Previous Next

Package: emacs;

Reported by: Dani Moncayo <dmoncayo <at> gmail.com>

Date: Thu, 8 Mar 2012 21:15:02 UTC

Severity: normal

Done: martin rudalics <rudalics <at> gmx.at>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 10971 in the body.
You can then email your comments to 10971 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#10971; Package emacs. (Thu, 08 Mar 2012 21:15:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Dani Moncayo <dmoncayo <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 08 Mar 2012 21:15:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Dani Moncayo <dmoncayo <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Problem with `split-window-keep-point' set to `nil'
Date: Thu, 8 Mar 2012 22:12:54 +0100
[Message part 1 (text/plain, inline)]
Recipe:

0. emacs -Q
1. M-: (setq split-window-keep-point nil) RET
2. Visit the attached file.
3. C-x 2

The point in the original (top) window has moved (unnecessarily) from
the first line to the last visible one.

The docstring of the variable `split-window-keep-point' says:

 If non-nil, C-x 2 preserves point in the new window.
 If nil, adjust point in the two windows to minimize redisplay.
 [...]

But in this case there was no need to adjust point, because it was in
a position which would remain visible after the splitting.

This behavior is specially annoying if you are in a Dired buffer and
do `C-o' on a file (the point jumps to the last visible line).

-- 
Dani Moncayo
[f1 (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10971; Package emacs. (Thu, 08 Mar 2012 22:47:01 GMT) Full text and rfc822 format available.

Message #8 received at 10971 <at> debbugs.gnu.org (full text, mbox):

From: Dani Moncayo <dmoncayo <at> gmail.com>
To: 10971 <at> debbugs.gnu.org
Subject: Re: bug#10971: Problem with `split-window-keep-point' set to `nil'
Date: Thu, 8 Mar 2012 23:44:52 +0100
This was reproduced...

In GNU Emacs 24.0.94.1 (i386-mingw-nt6.1.7601)
 of 2012-03-07 on DANI-PC
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --with-gcc (4.6) --enable-checking'


-- 
Dani Moncayo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10971; Package emacs. (Fri, 09 Mar 2012 15:24:02 GMT) Full text and rfc822 format available.

Message #11 received at 10971 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Dani Moncayo <dmoncayo <at> gmail.com>
Cc: 10971 <at> debbugs.gnu.org
Subject: Re: bug#10971: Problem with `split-window-keep-point' set to `nil'
Date: Fri, 09 Mar 2012 16:21:02 +0100
[Message part 1 (text/plain, inline)]
> 0. emacs -Q
> 1. M-: (setq split-window-keep-point nil) RET
> 2. Visit the attached file.

Vist any file large enough to extend beyond the end of the selected
window.

> 3. C-x 2
>
> The point in the original (top) window has moved (unnecessarily) from
> the first line to the last visible one.
>
> The docstring of the variable `split-window-keep-point' says:
>
>  If non-nil, C-x 2 preserves point in the new window.
>  If nil, adjust point in the two windows to minimize redisplay.
>  [...]
>
> But in this case there was no need to adjust point, because it was in
> a position which would remain visible after the splitting.
>
> This behavior is specially annoying if you are in a Dired buffer and
> do `C-o' on a file (the point jumps to the last visible line).

Does the attached patch give better results?

martin
[split-window-below.diff (text/plain, inline)]
=== modified file 'lisp/window.el'
--- lisp/window.el	2012-02-12 05:10:30 +0000
+++ lisp/window.el	2012-03-09 15:12:05 +0000
@@ -3282,22 +3282,23 @@
     (setq new-window (split-window nil size))
     (unless split-window-keep-point
       (with-current-buffer (window-buffer)
-	(goto-char (window-start))
-	(setq moved (vertical-motion (window-height)))
-	(set-window-start new-window (point))
-	(when (> (point) (window-point new-window))
-	  (set-window-point new-window (point)))
-	(when (= moved (window-height))
-	  (setq moved-by-window-height t)
-	  (vertical-motion -1))
-	(setq bottom (point)))
-      (and moved-by-window-height
-	   (<= bottom (point))
-	   (set-window-point old-window (1- bottom)))
-      (and moved-by-window-height
-	   (<= (window-start new-window) old-point)
-	   (set-window-point new-window old-point)
-	   (select-window new-window)))
+	(save-excursion
+	  (goto-char (window-start))
+	  (setq moved (vertical-motion (window-height)))
+	  (set-window-start new-window (point))
+	  (when (> (point) (window-point new-window))
+	    (set-window-point new-window (point)))
+	  (when (= moved (window-height))
+	    (setq moved-by-window-height t)
+	    (vertical-motion -1))
+	  (setq bottom (point)))
+	(and moved-by-window-height
+	     (<= bottom (point))
+	     (set-window-point old-window (1- bottom)))
+	(and moved-by-window-height
+	     (<= (window-start new-window) old-point)
+	     (set-window-point new-window old-point)
+	     (select-window new-window))))
     ;; Always copy quit-restore parameter in interactive use.
     (let ((quit-restore (window-parameter old-window 'quit-restore)))
       (when quit-restore


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10971; Package emacs. (Fri, 09 Mar 2012 16:25:02 GMT) Full text and rfc822 format available.

Message #14 received at 10971 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Dani Moncayo <dmoncayo <at> gmail.com>
Cc: 10971 <at> debbugs.gnu.org
Subject: Re: bug#10971: Problem with `split-window-keep-point' set to `nil'
Date: Fri, 09 Mar 2012 17:24:24 +0100
> Does the attached patch give better results?

Just to explain what IMO happened and maybe should happen here: Emacs 23
had a wrapper

      (save-excursion
	(set-buffer (window-buffer))

which, probably to avoid a warning, Stefan changed on 2009-11-13 to

      (with-current-buffer (window-buffer)

Ever since that `split-window-keep-point' was broken and the fact that
nobody complained till now seems to indicate that we probably should
obsolete this option.

I don't understand the purpose of the (set-buffer (window-buffer)).
Maybe it was due to the fact that the current buffer might not be the
window buffer of the selected window when `split-window-vertically' is
called.  In that case, however, the specification of `old-point' and the
conjunct

	   (<= bottom (point))

some lines below _would_ consult the current buffer (since it's outside
the `save-excursion') and we'd have a problem anyway.

OTOH, not using `save-excursion' is the wrong thing since everything
done in the excursion is to _calculate_ positions and not to modify
them.  My patch is an attempt to fix most old and new issues with one
exception: The let's

	(old-point (point))

should probably become

	(old-point (window-point-1))

but I'm not very sure yet.  Any ideas?

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10971; Package emacs. (Sat, 10 Mar 2012 09:19:01 GMT) Full text and rfc822 format available.

Message #17 received at 10971 <at> debbugs.gnu.org (full text, mbox):

From: Dani Moncayo <dmoncayo <at> gmail.com>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 10971 <at> debbugs.gnu.org
Subject: Re: bug#10971: Problem with `split-window-keep-point' set to `nil'
Date: Sat, 10 Mar 2012 09:48:18 +0100
>> Does the attached patch give better results?

Yes, it does.  Thank you.

> Ever since that `split-window-keep-point' was broken and the fact that
> nobody complained till now seems to indicate that we probably should
> obsolete this option.

Probably.

Actually I don't have this option set to nil in my init file.  I
discovered the bug while playing around with Emacs.

-- 
Dani Moncayo




Reply sent to martin rudalics <rudalics <at> gmx.at>:
You have taken responsibility. (Sun, 11 Mar 2012 14:37:02 GMT) Full text and rfc822 format available.

Notification sent to Dani Moncayo <dmoncayo <at> gmail.com>:
bug acknowledged by developer. (Sun, 11 Mar 2012 14:37:02 GMT) Full text and rfc822 format available.

Message #22 received at 10971-done <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Dani Moncayo <dmoncayo <at> gmail.com>
Cc: 10971-done <at> debbugs.gnu.org
Subject: Re: bug#10971: Problem with `split-window-keep-point' set to `nil'
Date: Sun, 11 Mar 2012 15:06:45 +0100
I installed a patch similar to the one I posted earlier.  There are
still some glitches when the window to split has a header line but most
of the remaining issues should have been fixed now.

martin




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 09 Apr 2012 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 135 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.