window.el 268 KB
Newer Older
1 2
;;; window.el --- GNU Emacs window commands aside from those written in C

3
;; Copyright (C) 1985, 1989, 1992-1994, 2000-2012
4
;;   Free Software Foundation, Inc.
5 6 7

;; Maintainer: FSF
;; Keywords: internal
8
;; Package: emacs
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Window tree functions.

;;; Code:

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
(defun internal--before-save-selected-window ()
  (cons (selected-window)
        ;; We save and restore all frames' selected windows, because
        ;; `select-window' can change the frame-selected-window of
        ;; whatever frame that window is in.  Each text terminal's
        ;; top-frame is preserved by putting it last in the list.
        (apply #'append
               (mapcar (lambda (terminal)
                         (let ((frames (frames-on-display-list terminal))
                               (top-frame (tty-top-frame terminal))
                               alist)
                           (if top-frame
                               (setq frames
                                     (cons top-frame
                                           (delq top-frame frames))))
                           (dolist (f frames)
                             (push (cons f (frame-selected-window f))
                                   alist))
                           alist))
                       (terminal-list)))))

(defun internal--after-save-selected-window (state)
  (dolist (elt (cdr state))
    (and (frame-live-p (car elt))
         (window-live-p (cdr elt))
         (set-frame-selected-window (car elt) (cdr elt) 'norecord)))
  (when (window-live-p (car state))
    (select-window (car state) 'norecord)))

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
(defmacro save-selected-window (&rest body)
  "Execute BODY, then select the previously selected window.
The value returned is the value of the last form in BODY.

This macro saves and restores the selected window, as well as the
selected window in each frame.  If the previously selected window
is no longer live, then whatever window is selected at the end of
BODY remains selected.  If the previously selected window of some
frame is no longer live at the end of BODY, that frame's selected
window is left alone.

This macro saves and restores the current buffer, since otherwise
its normal operation could make a different buffer current.  The
order of recently selected windows and the buffer list ordering
are not altered by this macro (unless they are altered in BODY)."
Stefan Monnier's avatar
Stefan Monnier committed
75
  (declare (indent 0) (debug t))
76
  `(let ((save-selected-window--state (internal--before-save-selected-window)))
77 78 79
     (save-current-buffer
       (unwind-protect
	   (progn ,@body)
80
         (internal--after-save-selected-window save-selected-window--state)))))
81

82 83 84 85 86 87 88 89 90 91 92
(defvar temp-buffer-window-setup-hook nil
  "Normal hook run by `with-temp-buffer-window' before buffer display.
This hook is run by `with-temp-buffer-window' with the buffer to be
displayed current.")

(defvar temp-buffer-window-show-hook nil
  "Normal hook run by `with-temp-buffer-window' after buffer display.
This hook is run by `with-temp-buffer-window' with the buffer
displayed and current and its window selected.")

(defun temp-buffer-window-setup (buffer-or-name)
93
  "Set up temporary buffer specified by BUFFER-OR-NAME.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
Return the buffer."
  (let ((old-dir default-directory)
	(buffer (get-buffer-create buffer-or-name)))
    (with-current-buffer buffer
      (kill-all-local-variables)
      (setq default-directory old-dir)
      (delete-all-overlays)
      (setq buffer-read-only nil)
      (setq buffer-file-name nil)
      (setq buffer-undo-list t)
      (let ((inhibit-read-only t)
	    (inhibit-modification-hooks t))
	(erase-buffer)
	(run-hooks 'temp-buffer-window-setup-hook))
      ;; Return the buffer.
      buffer)))

(defun temp-buffer-window-show (&optional buffer action)
  "Show temporary buffer BUFFER in a window.
Return the window showing BUFFER.  Pass ACTION as action argument
to `display-buffer'."
  (let (window frame)
    (with-current-buffer buffer
      (set-buffer-modified-p nil)
      (setq buffer-read-only t)
      (goto-char (point-min))
120 121 122 123 124 125 126 127 128 129 130 131 132
      (when (let ((window-combination-limit
		   ;; When `window-combination-limit' equals
		   ;; `temp-buffer' or `temp-buffer-resize' and
		   ;; `temp-buffer-resize-mode' is enabled in this
		   ;; buffer bind it to t so resizing steals space
		   ;; preferably from the window that was split.
		   (if (or (eq window-combination-limit 'temp-buffer)
			   (and (eq window-combination-limit
				    'temp-buffer-resize)
				temp-buffer-resize-mode))
		       t
		     window-combination-limit)))
	      (setq window (display-buffer buffer action)))
133 134 135 136 137 138 139 140 141 142 143 144 145
	(setq frame (window-frame window))
	(unless (eq frame (selected-frame))
	  (raise-frame frame))
	(setq minibuffer-scroll-window window)
	(set-window-hscroll window 0)
	(with-selected-window window
	  (run-hooks 'temp-buffer-window-show-hook)
	  (when temp-buffer-resize-mode
	    (resize-temp-buffer-window window)))
	;; Return the window.
	window))))

(defmacro with-temp-buffer-window (buffer-or-name action quit-function &rest body)
146 147 148
  "Evaluate BODY and display the buffer specified by BUFFER-OR-NAME.
BUFFER-OR-NAME must specify either a live buffer, or the name of a
buffer (if it does not exist, this macro creates it).
149 150 151 152 153 154

Make sure the specified buffer is empty before evaluating BODY.
Do not make that buffer current for BODY.  Instead, bind
`standard-output' to that buffer, so that output generated with
`prin1' and similar functions in BODY goes into that buffer.

155 156 157 158
After evaluating BODY, this marks the specified buffer unmodified and
read-only, and displays it in a window via `display-buffer', passing
ACTION as the action argument to `display-buffer'.  It automatically
shrinks the relevant window if `temp-buffer-resize-mode' is enabled.
159

160 161
Returns the value returned by BODY, unless QUIT-FUNCTION specifies
a function.  In that case, runs the function with two arguments -
162
the window showing the specified buffer and the value returned by
163
BODY - and returns the value returned by that function.
164 165 166 167 168

If the buffer is displayed on a new frame, the window manager may
decide to select that frame.  In that case, it's usually a good
strategy if the function specified by QUIT-FUNCTION selects the
window showing the buffer before reading a value from the
169 170 171 172 173 174 175
minibuffer; for example, when asking a `yes-or-no-p' question.

This construct is similar to `with-output-to-temp-buffer', but does
not put the buffer in help mode, or call `temp-buffer-show-function'.
It also runs different hooks, namely `temp-buffer-window-setup-hook'
\(with the specified buffer current) and `temp-buffer-window-show-hook'
\(with the specified buffer current and the window showing it selected).
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

Since this macro calls `display-buffer', the window displaying
the buffer is usually not selected and the specified buffer
usually not made current.  QUIT-FUNCTION can override that."
  (declare (debug t))
  (let ((buffer (make-symbol "buffer"))
	(window (make-symbol "window"))
	(value (make-symbol "value")))
    `(let* ((,buffer (temp-buffer-window-setup ,buffer-or-name))
	    (standard-output ,buffer)
	    ,window ,value)
       (with-current-buffer ,buffer
	 (setq ,value (progn ,@body))
	 (setq ,window (temp-buffer-window-show ,buffer ,action)))

       (if (functionp ,quit-function)
	   (funcall ,quit-function ,window ,value)
	 ,value))))

195 196 197 198 199
;; The following two functions are like `window-next-sibling' and
;; `window-prev-sibling' but the WINDOW argument is _not_ optional (so
;; they don't substitute the selected window for nil), and they return
;; nil when WINDOW doesn't have a parent (like a frame's root window or
;; a minibuffer window).
200
(defun window-right (window)
201 202 203
  "Return WINDOW's right sibling.
Return nil if WINDOW is the root window of its frame.  WINDOW can
be any window."
204
  (and window (window-parent window) (window-next-sibling window)))
205

206
(defun window-left (window)
207 208 209
  "Return WINDOW's left sibling.
Return nil if WINDOW is the root window of its frame.  WINDOW can
be any window."
210
  (and window (window-parent window) (window-prev-sibling window)))
211

212
(defun window-child (window)
213 214
  "Return WINDOW's first child window.
WINDOW can be any window."
215
  (or (window-top-child window) (window-left-child window)))
216 217

(defun window-child-count (window)
218 219
  "Return number of WINDOW's child windows.
WINDOW can be any window."
220 221 222 223
  (let ((count 0))
    (when (and (windowp window) (setq window (window-child window)))
      (while window
	(setq count (1+ count))
224
	(setq window (window-next-sibling window))))
225 226 227
    count))

(defun window-last-child (window)
228 229
  "Return last child window of WINDOW.
WINDOW can be any window."
230
  (when (and (windowp window) (setq window (window-child window)))
231 232
    (while (window-next-sibling window)
      (setq window (window-next-sibling window))))
233 234
  window)

235
(defun window-normalize-buffer (buffer-or-name)
236 237 238 239 240 241 242 243 244 245 246 247 248 249
  "Return buffer specified by BUFFER-OR-NAME.
BUFFER-OR-NAME must be either a buffer or a string naming a live
buffer and defaults to the current buffer."
  (cond
   ((not buffer-or-name)
    (current-buffer))
   ((bufferp buffer-or-name)
    (if (buffer-live-p buffer-or-name)
	buffer-or-name
      (error "Buffer %s is not a live buffer" buffer-or-name)))
   ((get-buffer buffer-or-name))
   (t
    (error "No such buffer %s" buffer-or-name))))

250
(defun window-normalize-frame (frame)
251 252 253 254 255 256 257 258
  "Return frame specified by FRAME.
FRAME must be a live frame and defaults to the selected frame."
  (if frame
      (if (frame-live-p frame)
	  frame
	(error "%s is not a live frame" frame))
    (selected-frame)))

259
(defun window-normalize-window (window &optional live-only)
260 261 262 263
  "Return the window specified by WINDOW.
If WINDOW is nil, return the selected window.  Otherwise, if
WINDOW is a live or an internal window, return WINDOW; if
LIVE-ONLY is non-nil, return WINDOW for a live window only.
264
Otherwise, signal an error."
265 266 267 268 269 270 271 272 273 274 275
  (cond
   ((null window)
    (selected-window))
   (live-only
    (if (window-live-p window)
	window
      (error "%s is not a live window" window)))
   ((window-valid-p window)
    window)
   (t
    (error "%s is not a valid window" window))))
276 277 278 279 280 281 282 283 284

(defvar ignore-window-parameters nil
  "If non-nil, standard functions ignore window parameters.
The functions currently affected by this are `split-window',
`delete-window', `delete-other-windows' and `other-window'.

An application may bind this to a non-nil value around calls to
these functions to inhibit processing of window parameters.")

285
(defconst window-safe-min-height 1
286
  "The absolute minimum number of lines of a window.
287 288
Anything less might crash Emacs.")

289 290
(defcustom window-min-height 4
  "The minimum number of lines of any window.
Juanma Barranquero's avatar
Juanma Barranquero committed
291 292
The value has to accommodate a mode- or header-line if present.
A value less than `window-safe-min-height' is ignored.  The value
293 294 295 296
of this variable is honored when windows are resized or split.

Applications should never rebind this variable.  To resize a
window to a height less than the one specified here, an
297
application should instead call `window-resize' with a non-nil
298
IGNORE argument.  In order to have `split-window' make a window
Paul Eggert's avatar
Paul Eggert committed
299
shorter, explicitly specify the SIZE argument of that function."
300 301 302 303
  :type 'integer
  :version "24.1"
  :group 'windows)

304
(defconst window-safe-min-width 2
305
  "The absolute minimum number of columns of a window.
306 307
Anything less might crash Emacs.")

308 309
(defcustom window-min-width 10
  "The minimum number of columns of any window.
310
The value has to accommodate margins, fringes, or scrollbars if
311 312 313 314 315 316
present.  A value less than `window-safe-min-width' is ignored.
The value of this variable is honored when windows are resized or
split.

Applications should never rebind this variable.  To resize a
window to a width less than the one specified here, an
317
application should instead call `window-resize' with a non-nil
318
IGNORE argument.  In order to have `split-window' make a window
Paul Eggert's avatar
Paul Eggert committed
319
narrower, explicitly specify the SIZE argument of that function."
320 321 322 323
  :type 'integer
  :version "24.1"
  :group 'windows)

324
(defun window-combined-p (&optional window horizontal)
325
  "Return non-nil if WINDOW has siblings in a given direction.
326
WINDOW must be a valid window and defaults to the selected one.
327 328 329 330 331 332

HORIZONTAL determines a direction for the window combination.
If HORIZONTAL is omitted or nil, return non-nil if WINDOW is part
of a vertical window combination.
If HORIZONTAL is non-nil, return non-nil if WINDOW is part of a
horizontal window combination."
333
  (setq window (window-normalize-window window))
334
  (let ((parent (window-parent window)))
335 336 337 338
    (and parent
	 (if horizontal
	     (window-left-child parent)
	   (window-top-child parent)))))
339

340 341
(defun window-combinations (window &optional horizontal)
  "Return largest number of windows vertically arranged within WINDOW.
342
WINDOW must be a valid window and defaults to the selected one.
343
If HORIZONTAL is non-nil, return the largest number of
344
windows horizontally arranged within WINDOW."
345
  (setq window (window-normalize-window window))
346 347 348 349
  (cond
   ((window-live-p window)
    ;; If WINDOW is live, return 1.
    1)
350 351 352
   ((if horizontal
	(window-left-child window)
      (window-top-child window))
353
    ;; If WINDOW is iso-combined, return the sum of the values for all
354
    ;; child windows of WINDOW.
355 356 357 358
    (let ((child (window-child window))
	  (count 0))
      (while child
	(setq count
359
	      (+ (window-combinations child horizontal)
360 361 362 363 364
		 count))
	(setq child (window-right child)))
      count))
   (t
    ;; If WINDOW is not iso-combined, return the maximum value of any
365
    ;; child window of WINDOW.
366 367 368 369
    (let ((child (window-child window))
	  (count 1))
      (while child
	(setq count
370
	      (max (window-combinations child horizontal)
371 372 373 374
		   count))
	(setq child (window-right child)))
      count))))

375
(defun walk-window-tree-1 (fun walk-window-tree-window any &optional sub-only)
376 377 378 379 380 381
  "Helper function for `walk-window-tree' and `walk-window-subtree'."
  (let (walk-window-tree-buffer)
    (while walk-window-tree-window
      (setq walk-window-tree-buffer
	    (window-buffer walk-window-tree-window))
      (when (or walk-window-tree-buffer any)
382
	(funcall fun walk-window-tree-window))
383 384
      (unless walk-window-tree-buffer
	(walk-window-tree-1
385
	 fun (window-left-child walk-window-tree-window) any)
386
	(walk-window-tree-1
387
	 fun (window-top-child walk-window-tree-window) any))
388 389 390 391 392
      (if sub-only
	  (setq walk-window-tree-window nil)
	(setq walk-window-tree-window
	      (window-right walk-window-tree-window))))))

393
(defun walk-window-tree (fun &optional frame any minibuf)
394 395
  "Run function FUN on each live window of FRAME.
FUN must be a function with one argument - a window.  FRAME must
396
be a live frame and defaults to the selected one.  ANY, if
397
non-nil, means to run FUN on all live and internal windows of
398 399
FRAME.

400 401 402 403 404 405
Optional argument MINIBUF t means run FUN on FRAME's minibuffer
window even if it isn't active.  MINIBUF nil or omitted means run
FUN on FRAME's minibuffer window only if it's active.  In both
cases the minibuffer window must be part of FRAME.  MINIBUF
neither nil nor t means never run FUN on the minibuffer window.

406
This function performs a pre-order, depth-first traversal of the
407
window tree.  If FUN changes the window tree, the result is
408
unpredictable."
409 410 411 412 413 414 415 416 417 418
  (setq frame (window-normalize-frame frame))
  (walk-window-tree-1 fun (frame-root-window frame) any)
  (when (memq minibuf '(nil t))
    ;; Run FUN on FRAME's minibuffer window if requested.
    (let ((minibuffer-window (minibuffer-window frame)))
      (when (and (window-live-p minibuffer-window)
		 (eq (window-frame minibuffer-window) frame)
		 (or (eq minibuf t)
		     (minibuffer-window-active-p minibuffer-window)))
	(funcall fun minibuffer-window)))))
419

420 421 422 423
(defun walk-window-subtree (fun &optional window any)
  "Run function FUN on the subtree of windows rooted at WINDOW.
WINDOW defaults to the selected window.  FUN must be a function
with one argument - a window.  By default, run FUN only on live
424
windows of the subtree.  If the optional argument ANY is non-nil,
425 426
run FUN on all live and internal windows of the subtree.  If
WINDOW is live, run FUN on WINDOW only.
427 428

This function performs a pre-order, depth-first traversal of the
429
subtree rooted at WINDOW.  If FUN changes that tree, the result
430
is unpredictable."
431
  (setq window (window-normalize-window window))
432
  (walk-window-tree-1 fun window any t))
433

434
(defun window-with-parameter (parameter &optional value frame any minibuf)
435 436 437
  "Return first window on FRAME with PARAMETER non-nil.
FRAME defaults to the selected frame.  Optional argument VALUE
non-nil means only return a window whose window-parameter value
Juanma Barranquero's avatar
Juanma Barranquero committed
438
for PARAMETER equals VALUE (comparison is done with `equal').
439
Optional argument ANY non-nil means consider internal windows
440 441 442 443 444 445 446
too.

Optional argument MINIBUF t means consider FRAME's minibuffer
window even if it isn't active.  MINIBUF nil or omitted means
consider FRAME's minibuffer window only if it's active.  In both
cases the minibuffer window must be part of FRAME.  MINIBUF
neither nil nor t means never consider the minibuffer window."
447
  (let (this-value)
448 449 450 451 452 453
    (catch 'found
      (walk-window-tree
       (lambda (window)
	 (when (and (setq this-value (window-parameter window parameter))
		    (or (not value) (equal value this-value)))
	   (throw 'found window)))
454
       frame any minibuf))))
455 456 457 458

;;; Atomic windows.
(defun window-atom-root (&optional window)
  "Return root of atomic window WINDOW is a part of.
459
WINDOW must be a valid window and defaults to the selected one.
Juanma Barranquero's avatar
Juanma Barranquero committed
460
Return nil if WINDOW is not part of an atomic window."
461
  (setq window (window-normalize-window window))
462 463 464 465 466 467
  (let (root)
    (while (and window (window-parameter window 'window-atom))
      (setq root window)
      (setq window (window-parent window)))
    root))

468
(defun window-make-atom (window)
469 470 471 472 473 474 475 476 477 478
  "Make WINDOW an atomic window.
WINDOW must be an internal window.  Return WINDOW."
  (if (not (window-child window))
      (error "Window %s is not an internal window" window)
    (walk-window-subtree
     (lambda (window)
       (set-window-parameter window 'window-atom t))
     window t)
    window))

479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
(defun display-buffer-in-atom-window (buffer alist)
  "Display BUFFER in an atomic window.
This function displays BUFFER in a new window that will be
combined with an existing window to form an atomic window.  If
the existing window is already part of an atomic window, add the
new window to that atomic window.  Operations like `split-window'
or `delete-window', when applied to a constituent of an atomic
window, are applied atomically to the root of that atomic window.

ALIST is an association list of symbols and values.  The
following symbols can be used.

`window' specifies the existing window the new window shall be
  combined with.  Use `window-atom-root' to make the new window a
  sibling of an atomic window's root.  If an internal window is
  specified here, all children of that window become part of the
  atomic window too.  If no window is specified, the new window
  becomes a sibling of the selected window.

`side' denotes the side of the existing window where the new
  window shall be located.  Valid values are `below', `right',
  `above' and `left'.  The default is `below'.

The return value is the new window, nil when creating that window
failed."
  (let ((ignore-window-parameters t)
	(window-combination-limit t)
	(window (cdr (assq 'window alist)))
	(side (cdr (assq 'side alist)))
	new)
    (setq window (window-normalize-window window))
    ;; Split off new window
    (when (setq new (split-window window nil side))
      ;; Make sure we have a valid atomic window.
      (window-make-atom (window-parent window))
      ;; Display BUFFER in NEW and return NEW.
      (window--display-buffer
516
       buffer new 'window alist display-buffer-mark-dedicated))))
517

518 519
(defun window--atom-check-1 (window)
  "Subroutine of `window--atom-check'."
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
  (when window
    (if (window-parameter window 'window-atom)
	(let ((count 0))
	  (when (or (catch 'reset
		      (walk-window-subtree
		       (lambda (window)
			 (if (window-parameter window 'window-atom)
			     (setq count (1+ count))
			   (throw 'reset t)))
		       window t))
		    ;; count >= 1 must hold here.  If there's no other
		    ;; window around dissolve this atomic window.
		    (= count 1))
	    ;; Dissolve atomic window.
	    (walk-window-subtree
	     (lambda (window)
	       (set-window-parameter window 'window-atom nil))
	     window t)))
      ;; Check children.
      (unless (window-buffer window)
540 541
	(window--atom-check-1 (window-left-child window))
	(window--atom-check-1 (window-top-child window))))
542
    ;; Check right sibling
543
    (window--atom-check-1 (window-right window))))
544

545
(defun window--atom-check (&optional frame)
546 547
  "Check atomicity of all windows on FRAME.
FRAME defaults to the selected frame.  If an atomic window is
548 549 550
wrongly configured, reset the atomicity of all its windows on
FRAME to nil.  An atomic window is wrongly configured if it has
no child windows or one of its child windows is not atomic."
551
  (window--atom-check-1 (frame-root-window frame)))
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566

;; Side windows.
(defvar window-sides '(left top right bottom)
  "Window sides.")

(defcustom window-sides-vertical nil
  "If non-nil, left and right side windows are full height.
Otherwise, top and bottom side windows are full width."
  :type 'boolean
  :group 'windows
  :version "24.1")

(defcustom window-sides-slots '(nil nil nil nil)
  "Maximum number of side window slots.
The value is a list of four elements specifying the number of
Juanma Barranquero's avatar
Juanma Barranquero committed
567
side window slots on (in this order) the left, top, right and
568 569 570 571
bottom side of each frame.  If an element is a number, this means
to display at most that many side windows on the corresponding
side.  If an element is nil, this means there's no bound on the
number of slots on that side."
572
  :version "24.1"
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
  :risky t
  :type
  '(list
    :value (nil nil nil nil)
    (choice
     :tag "Left"
     :help-echo "Maximum slots of left side window."
     :value nil
     :format "%[Left%] %v\n"
     (const :tag "Unlimited" :format "%t" nil)
     (integer :tag "Number" :value 2 :size 5))
    (choice
     :tag "Top"
     :help-echo "Maximum slots of top side window."
     :value nil
     :format "%[Top%] %v\n"
     (const :tag "Unlimited" :format "%t" nil)
     (integer :tag "Number" :value 3 :size 5))
    (choice
     :tag "Right"
     :help-echo "Maximum slots of right side window."
     :value nil
     :format "%[Right%] %v\n"
     (const :tag "Unlimited" :format "%t" nil)
     (integer :tag "Number" :value 2 :size 5))
    (choice
     :tag "Bottom"
     :help-echo "Maximum slots of bottom side window."
     :value nil
     :format "%[Bottom%] %v\n"
     (const :tag "Unlimited" :format "%t" nil)
     (integer :tag "Number" :value 3 :size 5)))
  :group 'windows)

607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
(defun window--major-non-side-window (&optional frame)
  "Return the major non-side window of frame FRAME.
The optional argument FRAME must be a live frame and defaults to
the selected one.

If FRAME has at least one side window, the major non-side window
is either an internal non-side window such that all other
non-side windows on FRAME descend from it, or the single live
non-side window of FRAME.  If FRAME has no side windows, return
its root window."
  (let ((frame (window-normalize-frame frame))
	major sibling)
    ;; Set major to the _last_ window found by `walk-window-tree' that
    ;; is not a side window but has a side window as its sibling.
    (walk-window-tree
     (lambda (window)
       (and (not (window-parameter window 'window-side))
	    (or (and (setq sibling (window-prev-sibling window))
		     (window-parameter sibling 'window-side))
		(and (setq sibling (window-next-sibling window))
		     (window-parameter sibling 'window-side)))
	    (setq major window)))
     frame t)
    (or major (frame-root-window frame))))

(defun window--major-side-window (side)
  "Return major side window on SIDE.
SIDE must be one of the symbols `left', `top', `right' or
`bottom'.  Return nil if no such window exists."
  (let ((root (frame-root-window))
	window)
    ;; (1) If a window on the opposite side exists, return that window's
    ;;     sibling.
    ;; (2) If the new window shall span the entire side, return the
    ;;     frame's root window.
    ;; (3) If a window on an orthogonal side exists, return that
    ;;     window's sibling.
    ;; (4) Otherwise return the frame's root window.
    (cond
     ((or (and (eq side 'left)
	       (setq window (window-with-parameter 'window-side 'right nil t)))
	  (and (eq side 'top)
	       (setq window (window-with-parameter 'window-side 'bottom nil t))))
      (window-prev-sibling window))
     ((or (and (eq side 'right)
	       (setq window (window-with-parameter 'window-side 'left nil t)))
	  (and (eq side 'bottom)
	       (setq window (window-with-parameter 'window-side 'top nil t))))
      (window-next-sibling window))
     ((memq side '(left right))
      (cond
       (window-sides-vertical
	root)
       ((setq window (window-with-parameter 'window-side 'top nil t))
	(window-next-sibling window))
       ((setq window (window-with-parameter 'window-side 'bottom nil t))
	(window-prev-sibling window))
       (t root)))
     ((memq side '(top bottom))
      (cond
       ((not window-sides-vertical)
	root)
       ((setq window (window-with-parameter 'window-side 'left nil t))
	(window-next-sibling window))
       ((setq window (window-with-parameter 'window-side 'right nil t))
	(window-prev-sibling window))
       (t root))))))

(defun display-buffer-in-major-side-window (buffer side slot &optional alist)
  "Display BUFFER in a new window on SIDE of the selected frame.
SIDE must be one of `left', `top', `right' or `bottom'.  SLOT
specifies the slot to use.  ALIST is an association list of
symbols and values as passed to `display-buffer-in-side-window'.
This function may be called only if no window on SIDE exists yet.
The new window automatically becomes the \"major\" side window on
SIDE.  Return the new window, nil if its creation window failed."
  (let* ((root (frame-root-window))
	 (left-or-right (memq side '(left right)))
	 (major (window--major-side-window side))
	 (selected-window (selected-window))
	 (on-side (cond
		   ((eq side 'top) 'above)
		   ((eq side 'bottom) 'below)
		   (t side)))
	 ;; The following two bindings will tell `split-window' to take
	 ;; the space for the new window from `major' and not make a new
	 ;; parent window unless needed.
	 (window-combination-resize 'side)
	 (window-combination-limit nil)
696
	 (new (split-window major nil on-side))
697 698 699 700 701 702 703 704 705 706
	 fun)
    (when new
      ;; Initialize `window-side' parameter of new window to SIDE.
      (set-window-parameter new 'window-side side)
      ;; Install `window-slot' parameter of new window.
      (set-window-parameter new 'window-slot slot)
      ;; Install `delete-window' parameter thus making sure that when
      ;; the new window is deleted, a side window on the opposite side
      ;; does not get resized.
      (set-window-parameter new 'delete-window 'delete-side-window)
707 708
      ;; Auto-adjust height/width of new window unless a size has been
      ;; explicitly requested.
Paul Eggert's avatar
Paul Eggert committed
709
      (unless (if left-or-right
710 711 712 713 714 715 716 717 718 719 720
		  (cdr (assq 'window-width alist))
		(cdr (assq 'window-height alist)))
	(setq alist
	      (cons
	       (cons
		(if left-or-right 'window-width 'window-height)
		(/ (window-total-size (frame-root-window) left-or-right)
		   ;; By default use a fourth of the size of the
		   ;; frame's root window.
		   4))
	       alist)))
721
      ;; Install BUFFER in new window and return NEW.
722
      (window--display-buffer buffer new 'window alist 'side))))
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829

(defun delete-side-window (window)
  "Delete side window WINDOW."
  (let ((window-combination-resize
	 (window-parameter (window-parent window) 'window-side))
	(ignore-window-parameters t))
    (delete-window window)))

(defun display-buffer-in-side-window (buffer alist)
  "Display BUFFER in a window on side SIDE of the selected frame.
ALIST is an association list of symbols and values.  The
following symbols can be used:

`side' denotes the side of the existing window where the new
  window shall be located.  Valid values are `bottom', `right',
  `top' and `left'.  The default is `bottom'.

`slot' if non-nil, specifies the window slot where to display
  BUFFER.  A value of zero or nil means use the middle slot on
  the specified side.  A negative value means use a slot
  preceding (that is, above or on the left of) the middle slot.
  A positive value means use a slot following (that is, below or
  on the right of) the middle slot.  The default is zero."
  (let ((side (or (cdr (assq 'side alist)) 'bottom))
	(slot (or (cdr (assq 'slot alist)) 0))
	new)
    (cond
     ((not (memq side '(top bottom left right)))
      (error "Invalid side %s specified" side))
     ((not (numberp slot))
      (error "Invalid slot %s specified" slot)))

    (let* ((major (window-with-parameter 'window-side side nil t))
	   ;; `major' is the major window on SIDE, `windows' the list of
	   ;; life windows on SIDE.
	   (windows
	    (when major
	      (let (windows)
		(walk-window-tree
		 (lambda (window)
		   (when (eq (window-parameter window 'window-side) side)
		     (setq windows (cons window windows)))))
		(nreverse windows))))
	   (slots (when major (max 1 (window-child-count major))))
	   (max-slots
	    (nth (cond
		  ((eq side 'left) 0)
		  ((eq side 'top) 1)
		  ((eq side 'right) 2)
		  ((eq side 'bottom) 3))
		 window-sides-slots))
	   (selected-window (selected-window))
	   window this-window this-slot prev-window next-window
	   best-window best-slot abs-slot new-window)

      (cond
       ((and (numberp max-slots) (<= max-slots 0))
	;; No side-slots available on this side.  Don't create an error,
	;; just return nil.
	nil)
       ((not windows)
	;; No major window exists on this side, make one.
	(display-buffer-in-major-side-window buffer side slot alist))
       (t
	;; Scan windows on SIDE.
	(catch 'found
	  (dolist (window windows)
	    (setq this-slot (window-parameter window 'window-slot))
	    (cond
	     ;; The following should not happen and probably be checked
	     ;; by window--side-check.
	     ((not (numberp this-slot)))
	     ((= this-slot slot)
	      ;; A window with a matching slot has been found.
	      (setq this-window window)
	      (throw 'found t))
	     (t
	      ;; Check if this window has a better slot value wrt the
	      ;; slot of the window we want.
	      (setq abs-slot
		    (if (or (and (> this-slot 0) (> slot 0))
			    (and (< this-slot 0) (< slot 0)))
			(abs (- slot this-slot))
		      (+ (abs slot) (abs this-slot))))
	      (unless (and best-slot (<= best-slot abs-slot))
		(setq best-window window)
		(setq best-slot abs-slot))
	      (cond
	       ((<= this-slot slot)
		(setq prev-window window))
	       ((not next-window)
		(setq next-window window)))))))

	;; `this-window' is the first window with the same SLOT.
	;; `prev-window' is the window with the largest slot < SLOT.  A new
	;; window will be created after it.
	;; `next-window' is the window with the smallest slot > SLOT.  A new
	;; window will be created before it.
	;; `best-window' is the window with the smallest absolute difference
	;; of its slot and SLOT.

	;; Note: We dedicate the window used softly to its buffer to
	;; avoid that "other" (non-side) buffer display functions steal
	;; it from us.  This must eventually become customizable via
	;; ALIST (or, better, avoided in the "other" functions).
	(or (and this-window
		 ;; Reuse `this-window'.
830
		 (window--display-buffer buffer this-window 'reuse alist 'side))
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854
	    (and (or (not max-slots) (< slots max-slots))
		 (or (and next-window
			  ;; Make new window before `next-window'.
			  (let ((next-side
				 (if (memq side '(left right)) 'above 'left))
				(window-combination-resize 'side))
			    (setq window (split-window next-window nil next-side))
			    ;; When the new window is deleted, its space
			    ;; is returned to other side windows.
			    (set-window-parameter
			     window 'delete-window 'delete-side-window)
			    window))
		     (and prev-window
			  ;; Make new window after `prev-window'.
			  (let ((prev-side
				 (if (memq side '(left right)) 'below 'right))
				(window-combination-resize 'side))
			    (setq window (split-window prev-window nil prev-side))
			    ;; When the new window is deleted, its space
			    ;; is returned to other side windows.
			    (set-window-parameter
			     window 'delete-window 'delete-side-window)
			    window)))
		   (set-window-parameter window 'window-slot slot)
855
		   (window--display-buffer buffer window 'window alist 'side))
856 857 858 859 860
	    (and best-window
		 ;; Reuse `best-window'.
		 (progn
		   ;; Give best-window the new slot value.
		   (set-window-parameter best-window 'window-slot slot)
861 862
		   (window--display-buffer
		    buffer best-window 'reuse alist 'side)))))))))
863

864
(defun window--side-check (&optional frame)
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
  "Check the side window configuration of FRAME.
FRAME defaults to the selected frame.

A valid side window configuration preserves the following two
invariants:

- If there exists a window whose window-side parameter is
  non-nil, there must exist at least one live window whose
  window-side parameter is nil.

- If a window W has a non-nil window-side parameter (i) it must
  have a parent window and that parent's window-side parameter
  must be either nil or the same as for W, and (ii) any child
  window of W must have the same window-side parameter as W.

If the configuration is invalid, reset the window-side parameters
of all windows on FRAME to nil."
  (let (left top right bottom none side parent parent-side)
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897
    (when (or (catch 'reset
		(walk-window-tree
		 (lambda (window)
		   (setq side (window-parameter window 'window-side))
		   (setq parent (window-parent window))
		   (setq parent-side
			 (and parent (window-parameter parent 'window-side)))
		   ;; The following `cond' seems a bit tedious, but I'd
		   ;; rather stick to using just the stack.
		   (cond
		    (parent-side
		     (when (not (eq parent-side side))
		       ;; A parent whose window-side is non-nil must
		       ;; have a child with the same window-side.
		       (throw 'reset t)))
898 899 900 901
		    ((not side)
		     (when (window-buffer window)
		       ;; Record that we have at least one non-side,
		       ;; live window.
902
		       (setq none t)))
903 904 905 906 907 908 909 910 911
		    ((if (memq side '(left top))
			 (window-prev-sibling window)
		       (window-next-sibling window))
		     ;; Left and top major side windows must not have a
		     ;; previous sibling, right and bottom major side
		     ;; windows must not have a next sibling.
		     (throw 'reset t))
		    ;; Now check that there's no more than one major
		    ;; window for any of left, top, right and bottom.
912
		    ((eq side 'left)
913
		     (if left (throw 'reset t) (setq left t)))
914
		    ((eq side 'top)
915
		     (if top (throw 'reset t) (setq top t)))
916
		    ((eq side 'right)
917
		     (if right (throw 'reset t) (setq right t)))
918
		    ((eq side 'bottom)
919
		     (if bottom (throw 'reset t) (setq bottom t)))
920
		    (t
921
		     (throw 'reset t))))
922
		 frame t))
923 924 925
	      ;; If there's a side window, there must be at least one
	      ;; non-side window.
	      (and (or left top right bottom) (not none)))
926 927 928 929 930
      (walk-window-tree
       (lambda (window)
	 (set-window-parameter window 'window-side nil))
       frame t))))

931
(defun window--check (&optional frame)
932 933
  "Check atomic and side windows on FRAME.
FRAME defaults to the selected frame."
934 935
  (window--side-check frame)
  (window--atom-check frame))
936 937 938 939 940 941 942 943 944

;;; Window sizes.
(defvar window-size-fixed nil
  "Non-nil in a buffer means windows displaying the buffer are fixed-size.
If the value is `height', then only the window's height is fixed.
If the value is `width', then only the window's width is fixed.
Any other non-nil value fixes both the width and the height.

Emacs won't change the size of any window displaying that buffer,
Juanma Barranquero's avatar
Juanma Barranquero committed
945
unless it has no other choice (like when deleting a neighboring
946 947 948
window).")
(make-variable-buffer-local 'window-size-fixed)

949
(defun window--size-ignore-p (window ignore)
950
  "Return non-nil if IGNORE says to ignore size restrictions for WINDOW."
951
  (if (window-valid-p ignore) (eq window ignore) ignore))
952 953

(defun window-min-size (&optional window horizontal ignore)
954
  "Return the minimum size of WINDOW.
955 956 957 958
WINDOW must be a valid window and defaults to the selected one.
Optional argument HORIZONTAL non-nil means return the minimum
number of columns of WINDOW; otherwise return the minimum number
of WINDOW's lines.
959

960
Optional argument IGNORE, if non-nil, means ignore restrictions
961
imposed by fixed size windows, `window-min-height' or
962
`window-min-width' settings.  If IGNORE equals `safe', live
963
windows may get as small as `window-safe-min-height' lines and
964 965 966
`window-safe-min-width' columns.  If IGNORE is a window, ignore
restrictions for that window only.  Any other non-nil value
means ignore all of the above restrictions for all windows."
967
  (window--min-size-1
968
   (window-normalize-window window) horizontal ignore))
969

970
(defun window--min-size-1 (window horizontal ignore)
971 972 973 974 975
  "Internal function of `window-min-size'."
  (let ((sub (window-child window)))
    (if sub
	(let ((value 0))
	  ;; WINDOW is an internal window.
976
	  (if (window-combined-p sub horizontal)
977
	      ;; The minimum size of an iso-combination is the sum of
978
	      ;; the minimum sizes of its child windows.
979 980
	      (while sub
		(setq value (+ value
981
			       (window--min-size-1 sub horizontal ignore)))
982 983
		(setq sub (window-right sub)))
	    ;; The minimum size of an ortho-combination is the maximum of
984
	    ;; the minimum sizes of its child windows.
985 986
	    (while sub
	      (setq value (max value
987
			       (window--min-size-1 sub horizontal ignore)))
988 989 990 991
	      (setq sub (window-right sub))))
	  value)
      (with-current-buffer (window-buffer window)
	(cond
992
	 ((and (not (window--size-ignore-p window ignore))
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
	       (window-size-fixed-p window horizontal))
	  ;; The minimum size of a fixed size window is its size.
	  (window-total-size window horizontal))
	 ((or (eq ignore 'safe) (eq ignore window))
	  ;; If IGNORE equals `safe' or WINDOW return the safe values.
	  (if horizontal window-safe-min-width window-safe-min-height))
	 (horizontal
	  ;; For the minimum width of a window take fringes and
	  ;; scroll-bars into account.  This is questionable and should
	  ;; be removed as soon as we are able to split (and resize)
	  ;; windows such that the new (or resized) windows can get a
	  ;; size less than the user-specified `window-min-height' and
	  ;; `window-min-width'.
	  (let ((frame (window-frame window))
		(fringes (window-fringes window))
		(scroll-bars (window-scroll-bars window)))
	    (max
	     (+ window-safe-min-width
		(ceiling (car fringes) (frame-char-width frame))
		(ceiling (cadr fringes) (frame-char-width frame))
		(cond
		 ((memq (nth 2 scroll-bars) '(left right))
		  (nth 1 scroll-bars))
		 ((memq (frame-parameter frame 'vertical-scroll-bars)
			'(left right))
		  (ceiling (or (frame-parameter frame 'scroll-bar-width) 14)
			   (frame-char-width)))
		 (t 0)))
1021
	     (if (and (not (window--size-ignore-p window ignore))
1022 1023 1024 1025 1026 1027 1028 1029 1030
		      (numberp window-min-width))
		 window-min-width
	       0))))
	 (t
	  ;; For the minimum height of a window take any mode- or
	  ;; header-line into account.
	  (max (+ window-safe-min-height
		  (if header-line-format 1 0)
		  (if mode-line-format 1 0))
1031
	       (if (and (not (window--size-ignore-p window ignore))
1032 1033 1034 1035 1036 1037
			(numberp window-min-height))
		   window-min-height
		 0))))))))

(defun window-sizable (window delta &optional horizontal ignore)
  "Return DELTA if DELTA lines can be added to WINDOW.
1038
WINDOW must be a valid window and defaults to the selected one.
1039 1040 1041 1042
Optional argument HORIZONTAL non-nil means return DELTA if DELTA
columns can be added to WINDOW.  A return value of zero means
that no lines (or columns) can be added to WINDOW.

1043 1044 1045
This function looks only at WINDOW and, recursively, its child
windows.  The function `window-resizable' looks at other windows
as well.
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056

DELTA positive means WINDOW shall be enlarged by DELTA lines or
columns.  If WINDOW cannot be enlarged by DELTA lines or columns
return the maximum value in the range 0..DELTA by which WINDOW
can be enlarged.

DELTA negative means WINDOW shall be shrunk by -DELTA lines or
columns.  If WINDOW cannot be shrunk by -DELTA lines or columns,
return the minimum value in the range DELTA..0 by which WINDOW
can be shrunk.

1057
Optional argument IGNORE non-nil means ignore restrictions
1058
imposed by fixed size windows, `window-min-height' or
1059
`window-min-width' settings.  If IGNORE equals `safe', live
1060
windows may get as small as `window-safe-min-height' lines and
1061 1062 1063
`window-safe-min-width' columns.  If IGNORE is a window, ignore
restrictions for that window only.  Any other non-nil value means
ignore all of the above restrictions for all windows."
1064
  (setq window (window-normalize-window window))
1065 1066 1067 1068 1069
  (cond
   ((< delta 0)
    (max (- (window-min-size window horizontal ignore)
	    (window-total-size window horizontal))
	 delta))
1070
   ((window--size-ignore-p window ignore)
1071 1072 1073 1074 1075 1076 1077
    delta)
   ((> delta 0)
    (if (window-size-fixed-p window horizontal)
	0
      delta))
   (t 0)))

1078
(defun window-sizable-p (window delta &optional horizontal ignore)
1079
  "Return t if WINDOW can be resized by DELTA lines.
1080
WINDOW must be a valid window and defaults to the selected one.
1081 1082
For the meaning of the arguments of this function see the
doc-string of `window-sizable'."
1083
  (setq window (window-normalize-window window))
1084 1085 1086 1087
  (if (> delta 0)
      (>= (window-sizable window delta horizontal ignore) delta)
    (<= (window-sizable window delta horizontal ignore) delta)))

1088
(defun window--size-fixed-1 (window horizontal)
1089 1090 1091 1092 1093
  "Internal function for `window-size-fixed-p'."
  (let ((sub (window-child window)))
    (catch 'fixed
      (if sub
	  ;; WINDOW is an internal window.
1094
	  (if (window-combined-p sub horizontal)
1095 1096
	      ;; An iso-combination is fixed size if all its child
	      ;; windows are fixed-size.
1097 1098
	      (progn
		(while sub
1099
		  (unless (window--size-fixed-1 sub horizontal)
1100 1101
		    ;; We found a non-fixed-size child window, so
		    ;; WINDOW's size is not fixed.
1102 1103
		    (throw 'fixed nil))
		  (setq sub (window-right sub)))
1104
		;; All child windows are fixed-size, so WINDOW's size is
1105 1106 1107
		;; fixed.
		(throw 'fixed t))
	    ;; An ortho-combination is fixed-size if at least one of its
1108
	    ;; child windows is fixed-size.
1109
	    (while sub
1110
	      (when (window--size-fixed-1 sub horizontal)
1111 1112
		;; We found a fixed-size child window, so WINDOW's size
		;; is fixed.
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122
		(throw 'fixed t))
	      (setq sub (window-right sub))))
	;; WINDOW is a live window.
	(with-current-buffer (window-buffer window)
	  (if horizontal
	      (memq window-size-fixed '(width t))
	    (memq window-size-fixed '(height t))))))))

(defun window-size-fixed-p (&optional window horizontal)
  "Return non-nil if WINDOW's height is fixed.
1123 1124 1125
WINDOW must be a valid window and defaults to the selected one.
Optional argument HORIZONTAL non-nil means return non-nil if
WINDOW's width is fixed.
1126 1127

If this function returns nil, this does not necessarily mean that
Martin Rudalics's avatar
Martin Rudalics committed
1128 1129
WINDOW can be resized in the desired direction.  The function
`window-resizable' can tell that."
1130
  (window--size-fixed-1
1131
   (window-normalize-window window) horizontal))
1132

1133
(defun window--min-delta-1 (window delta &optional horizontal ignore trail noup)
1134 1135 1136 1137 1138 1139 1140 1141
  "Internal function for `window-min-delta'."
  (if (not (window-parent window))
      ;; If we can't go up, return zero.
      0
    ;; Else try to find a non-fixed-size sibling of WINDOW.
    (let* ((parent (window-parent window))
	   (sub (window-child parent)))
      (catch 'done
1142
	(if (window-combined-p sub horizontal)
1143
	    ;; In an iso-combination throw DELTA if we find at least one
1144 1145
	    ;; child window and that window is either not fixed-size or
	    ;; we can ignore fixed-sizeness.
1146 1147 1148 1149 1150 1151
	    (let ((skip (eq trail 'after)))
	      (while sub
		(cond
		 ((eq sub window)
		  (setq skip (eq trail 'before)))
		 (skip)
1152
		 ((and (not (window--size-ignore-p window ignore))
1153 1154
		       (window-size-fixed-p sub horizontal)))
		 (t
1155
		  ;; We found a non-fixed-size child window.
1156 1157 1158
		  (throw 'done delta)))
		(setq sub (window-right sub))))
	  ;; In an ortho-combination set DELTA to the minimum value by
1159
	  ;; which other child windows can shrink.
1160 1161 1162 1163 1164 1165 1166 1167 1168
	  (while sub
	    (unless (eq sub window)
	      (setq delta
		    (min delta
			 (- (window-total-size sub horizontal)
			    (window-min-size sub horizontal ignore)))))
	    (setq sub (window-right sub))))
	(if noup
	    delta
1169
	  (window--min-delta-1 parent delta horizontal ignore trail))))))
1170 1171 1172

(defun window-min-delta (&optional window horizontal ignore trail noup nodown)
  "Return number of lines by which WINDOW can be shrunk.
1173 1174
WINDOW must be a valid window and defaults to the selected one.
Return zero if WINDOW cannot be shrunk.
1175 1176 1177 1178

Optional argument HORIZONTAL non-nil means return number of
columns by which WINDOW can be shrunk.

1179
Optional argument IGNORE non-nil means ignore restrictions
1180
imposed by fixed size windows, `window-min-height' or
Eli Zaretskii's avatar