Skip to content

Commit f9ed324

Browse files
committed
ignore 3-pane mode if frame is too small
Fixes ProofGeneral#760.
1 parent 379b24b commit f9ed324

File tree

3 files changed

+85
-56
lines changed

3 files changed

+85
-56
lines changed

ci/simple-tests/coq-test-three-window.el

Lines changed: 67 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616
;; three times `window-min-height' (which defaults to 4). The problem
1717
;; was relevant for Emacs 26.3, 27.1, and 27.2 running in batch mode
1818
;; in docker containers, because they set their frame height to 9 (and
19-
;; their width to 10). For this reason most Proof General CI tests
20-
;; disable three pane mode in one or the other way.
19+
;; their width to 10) in such environments. For this reason most Proof
20+
;; General CI tests disable three pane mode in one or the other way.
2121
;;
22-
;; This file tests the internal function `proof-select-three-b' that
23-
;; contains the bug and one user command affected by the bug
24-
;; (`proof-toggle-active-scripting') with three different frame sizes:
25-
;; too small for 3 windows, just big enough for 3 windows, and the
26-
;; default frame size.
22+
;; This file tests that the internal function `proof-select-three-b'
23+
;; creates 3 windows if the frame height is big enough. Additionally,
24+
;; it is tested that one user command
25+
;; (`proof-toggle-active-scripting') that used to be affected by the
26+
;; bug does not signal an error, regardless of the frame size. Both
27+
;; functions are tested with three different frame sizes: too small
28+
;; for 3 windows, just big enough for 3 windows, and the default frame
29+
;; size.
2730

2831
(require 'pg-response)
2932

@@ -39,51 +42,64 @@ source file."
3942
(message "Coq and Proof General reseted")))
4043

4144

42-
(defun test-proof-select-three-b-for-height (height)
45+
(defun test-proof-select-three-b-for-height (height expect-error)
4346
"Test `proof-select-three-b' in 3-pane mode for HEIGHT.
44-
The function should not signal an error and set up 3 windows."
45-
(let ((b1 (get-buffer-create "test-b1"))
46-
(b2 (get-buffer-create "test-b2"))
47-
(b3 (get-buffer-create "test-b3"))
48-
;; the following is set to its default value
49-
(proof-three-window-enable t))
50-
(reset-coq)
51-
(message "Check test-proof-select-three-b for height %d" height)
52-
(set-frame-height (selected-frame) height)
53-
(proof-select-three-b b1 b2 b3 'smart)
54-
(message "Apparently no error signaled in proof-select-three-b")
55-
(message "Check that there are 3 windows")
56-
(should (eq (length (window-list)) 3))))
47+
EXPECT-ERROR must be non-nil precisely if the frame height is
48+
expected to be too small for 3 windows. In this case nothing is
49+
done here, because `proof-select-three-b' must not be called in
50+
such situations. Otherwise the function should not signal an
51+
error and set up 3 windows."
52+
(if expect-error
53+
(message "Skip test-proof-select-three-b for height %d" height)
54+
(let ((b1 (get-buffer-create "test-b1"))
55+
(b2 (get-buffer-create "test-b2"))
56+
(b3 (get-buffer-create "test-b3"))
57+
;; the following is set to its default value
58+
(proof-three-window-enable t))
59+
(reset-coq)
60+
(message "Check test-proof-select-three-b for height %d" height)
61+
(set-frame-height (selected-frame) height)
62+
(proof-select-three-b b1 b2 b3 'smart)
63+
(message "Apparently no error signaled in proof-select-three-b")
64+
(message "Check that there are 3 windows")
65+
(should (eq (length (window-list)) 3))
66+
67+
;; clean up
68+
(kill-buffer b1)
69+
(kill-buffer b2)
70+
(kill-buffer b3))))
71+
5772

5873
(ert-deftest test-proof-select-three-b-too-small ()
5974
"Test `proof-select-three-b' for a frame height too small for 3 windows."
60-
:expected-result :failed
61-
(test-proof-select-three-b-for-height (- (* 3 window-min-height) 1)))
75+
(test-proof-select-three-b-for-height (- (* 3 window-min-height) 1) t))
6276

6377
(ert-deftest test-proof-select-three-b-just-big-enough ()
6478
"Test `proof-select-three-b' for a frame height just big enough for 3 windows."
65-
(test-proof-select-three-b-for-height (* 3 window-min-height)))
79+
(test-proof-select-three-b-for-height (* 3 window-min-height) nil))
6680

6781
(ert-deftest test-proof-select-three-b-default-height ()
6882
"Test `proof-select-three-b' for the default frame height.
6983
Note that for Emacs 26.3, 27.1, and 27.2, the default frame
7084
height is 9 when running in a docker container."
71-
:expected-result (if (and
72-
;; >= 26.3
73-
(or (> emacs-major-version 26)
74-
(and (eq emacs-major-version 26)
75-
(>= emacs-minor-version 3)))
76-
;; < 28
77-
(< emacs-major-version 28))
78-
:failed
79-
:passed)
80-
(test-proof-select-three-b-for-height (frame-height)))
85+
(test-proof-select-three-b-for-height
86+
(frame-height)
87+
(if (and
88+
;; >= 26.3
89+
(or (> emacs-major-version 26)
90+
(and (eq emacs-major-version 26) (>= emacs-minor-version 3)))
91+
;; < 28
92+
(< emacs-major-version 28))
93+
t
94+
nil)))
8195

8296

83-
(defun test-activate-scripting-for-height (height)
97+
(defun test-activate-scripting-for-height (height num-win)
8498
"Test `proof-toggle-active-scripting' in 3-pane mode for HEIGHT.
85-
The function should not signal an error and there should be 3
86-
windows afterwards."
99+
The function should never signal an error and afterwards there
100+
should be 3 windows if the frame has enough space and 2
101+
otherwise. Argument NUM-WIN specifies the expected number of
102+
windows for HEIGHT."
87103
(let ((proof-three-window-enable t)
88104
(proof-three-window-mode-policy 'smart))
89105
(reset-coq)
@@ -92,30 +108,29 @@ windows afterwards."
92108
(find-file "some_file.v")
93109
(proof-toggle-active-scripting)
94110
(message "Apparently no error signaled in proof-toggle-active-scripting")
95-
(message "Check that there are 3 windows")
96-
(should (eq (length (window-list)) 3))))
111+
(message "Check that there are %d windows" num-win)
112+
(should (eq (length (window-list)) num-win))))
97113

98114

99115
(ert-deftest test-proof-toggle-active-scripting-too-small ()
100116
"Test `proof-toggle-active-scripting' in a frame too small for 3 windows."
101-
:expected-result :failed
102-
(test-activate-scripting-for-height (- (* 3 window-min-height) 1)))
117+
(test-activate-scripting-for-height (* 4 window-min-height) 2))
103118

104119
(ert-deftest test-proof-toggle-active-scripting-just-big-enough ()
105120
"Test `proof-toggle-active-scripting' in a frame just enough for 3 windows."
106-
(test-activate-scripting-for-height (* 3 window-min-height)))
121+
(test-activate-scripting-for-height (+ (* 4 window-min-height) 1) 3))
107122

108123
(ert-deftest test-proof-toggle-active-scripting-default-height ()
109124
"Test `proof-toggle-active-scripting' with the default frame size.
110125
Note that for Emacs 26.3, 27.1, and 27.2, the default frame
111126
height is 9 when running in a docker container."
112-
:expected-result (if (and
113-
;; >= 26.3
114-
(or (> emacs-major-version 26)
115-
(and (eq emacs-major-version 26)
116-
(>= emacs-minor-version 3)))
117-
;; < 28
118-
(< emacs-major-version 28))
119-
:failed
120-
:passed)
121-
(test-activate-scripting-for-height (frame-height)))
127+
(test-activate-scripting-for-height
128+
(frame-height)
129+
(if (and
130+
;; >= 26.3
131+
(or (> emacs-major-version 26)
132+
(and (eq emacs-major-version 26) (>= emacs-minor-version 3)))
133+
;; < 28
134+
(< emacs-major-version 28))
135+
2
136+
3)))

generic/pg-response.el

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ See ‘proof-layout-windows’ for more details about POLICY."
146146
"Put the three buffers B1, B2, and B3 into three windows.
147147
Following POLICY, which can be 'smart, 'horizontal, 'vertical, or 'hybrid.
148148
149-
See ‘proof-layout-windows’ for more details about POLICY."
149+
See ‘proof-layout-windows’ for more details about POLICY.
150+
151+
This function must not be called if the frame has not enough
152+
space for 3 windows (see `window-min-height')."
150153
(interactive "bBuffer1:\nbBuffer2:\nbBuffer3:")
151154
(delete-other-windows)
152155
(switch-to-buffer b1)
@@ -187,7 +190,10 @@ See ‘proof-layout-windows’ for more details about POLICY."
187190

188191
(defun proof-display-three-b (&optional policy)
189192
"Layout three buffers in a single frame. Only do this if buffers exist.
190-
In this case, call ‘proof-select-three-b’ with argument POLICY."
193+
In this case, call ‘proof-select-three-b’ with argument POLICY.
194+
195+
This function must not be called if the frame has not enough
196+
space for 3 windows (see `window-min-height')."
191197
(interactive)
192198
(when (and (buffer-live-p proof-goals-buffer)
193199
(buffer-live-p proof-response-buffer))
@@ -272,7 +278,11 @@ dragging the separating bars.
272278
;; Restore an existing frame configuration (seems buggy, typical)
273279
(if pg-frame-configuration
274280
(set-frame-configuration pg-frame-configuration 'nodelete)))
275-
(proof-three-window-enable ; single frame
281+
((and proof-three-window-enable ; single frame
282+
;; The minimal frame size for setting up 3 windows is 3 *
283+
;; window-min-height, obviously. Use a slightly bigger margin
284+
;; here.
285+
(> (frame-height) (* 4 window-min-height)))
276286
;; If we are coming from multiple frame mode, delete associated
277287
;; frames (and only them).
278288
(proof-delete-all-associated-windows)

generic/proof-useropts.el

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ Emacs automatically resizing windows between proof steps.
176176
177177
If you use several frames (the same Emacs in several windows on the
178178
screen), you can force a frame to stick to showing the goals or
179-
response buffer."
179+
response buffer.
180+
181+
This option only takes effect if the frame height is bigger than
182+
4 times `window-min-height' (i.e., bigger than 16 with default
183+
values) because there must be enough space to create 3 windows."
180184
:type 'boolean
181185
:set 'proof-set-value
182186
:group 'proof-user-options)

0 commit comments

Comments
 (0)