all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#10971: Problem with `split-window-keep-point' set to `nil'
@ 2012-03-08 21:12 Dani Moncayo
  2012-03-08 22:44 ` Dani Moncayo
  2012-03-09 15:21 ` martin rudalics
  0 siblings, 2 replies; 6+ messages in thread
From: Dani Moncayo @ 2012-03-08 21:12 UTC (permalink / raw)
  To: 10971

[-- Attachment #1: Type: text/plain, Size: 685 bytes --]

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

[-- Attachment #2: f1 --]
[-- Type: application/octet-stream, Size: 394 bytes --]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100


^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#10971: Problem with `split-window-keep-point' set to `nil'
  2012-03-08 21:12 bug#10971: Problem with `split-window-keep-point' set to `nil' Dani Moncayo
@ 2012-03-08 22:44 ` Dani Moncayo
  2012-03-09 15:21 ` martin rudalics
  1 sibling, 0 replies; 6+ messages in thread
From: Dani Moncayo @ 2012-03-08 22:44 UTC (permalink / raw)
  To: 10971

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





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#10971: Problem with `split-window-keep-point' set to `nil'
  2012-03-08 21:12 bug#10971: Problem with `split-window-keep-point' set to `nil' Dani Moncayo
  2012-03-08 22:44 ` Dani Moncayo
@ 2012-03-09 15:21 ` martin rudalics
  2012-03-09 16:24   ` martin rudalics
  1 sibling, 1 reply; 6+ messages in thread
From: martin rudalics @ 2012-03-09 15:21 UTC (permalink / raw)
  To: Dani Moncayo; +Cc: 10971

[-- Attachment #1: Type: text/plain, Size: 842 bytes --]

 > 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

[-- Attachment #2: split-window-below.diff --]
[-- Type: text/plain, Size: 1667 bytes --]

=== 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#10971: Problem with `split-window-keep-point' set to `nil'
  2012-03-09 15:21 ` martin rudalics
@ 2012-03-09 16:24   ` martin rudalics
  2012-03-10  8:48     ` Dani Moncayo
  0 siblings, 1 reply; 6+ messages in thread
From: martin rudalics @ 2012-03-09 16:24 UTC (permalink / raw)
  To: Dani Moncayo; +Cc: 10971

 > 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





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#10971: Problem with `split-window-keep-point' set to `nil'
  2012-03-09 16:24   ` martin rudalics
@ 2012-03-10  8:48     ` Dani Moncayo
  2012-03-11 14:06       ` martin rudalics
  0 siblings, 1 reply; 6+ messages in thread
From: Dani Moncayo @ 2012-03-10  8:48 UTC (permalink / raw)
  To: martin rudalics; +Cc: 10971

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





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#10971: Problem with `split-window-keep-point' set to `nil'
  2012-03-10  8:48     ` Dani Moncayo
@ 2012-03-11 14:06       ` martin rudalics
  0 siblings, 0 replies; 6+ messages in thread
From: martin rudalics @ 2012-03-11 14:06 UTC (permalink / raw)
  To: Dani Moncayo; +Cc: 10971-done

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





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-03-11 14:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-08 21:12 bug#10971: Problem with `split-window-keep-point' set to `nil' Dani Moncayo
2012-03-08 22:44 ` Dani Moncayo
2012-03-09 15:21 ` martin rudalics
2012-03-09 16:24   ` martin rudalics
2012-03-10  8:48     ` Dani Moncayo
2012-03-11 14:06       ` martin rudalics

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.