Commit 59526c32 authored by Martin Rudalics's avatar Martin Rudalics

2015-07-22 Martin Rudalics <>

Optionally even widths of `display-buffer' windows.  (Bug#21100)

* lisp/window.el (quit-restore-window): Restore width if
(display-buffer-record-window): Record width when window is
reused and horizontally combined.
(even-window-sizes): New option to allow evening window widths.
(even-window-heights): Defalias to `even-window-sizes'.
(window--even-window-heights): Rename to
`window--even-window-sizes'.  Handle side-by-side windows.
(display-buffer-use-some-window): Call `window--even-window-sizes'
instead of `window--even-window-heights'.
* lisp/help.el (resize-temp-buffer-window): Fix indentation.

* doc/lispref/windows.texi (Choosing Window Options): Describe
(Coordinates and Windows): Fix typo.
parent fed091f7
......@@ -2547,6 +2547,21 @@ least that many columns. If the value is @code{nil}, that means not
to split this way.
@end defopt
@defopt even-window-sizes
This variable, if non-nil, causes @code{display-buffer} to even window
sizes whenever it reuses an existing window and that window is adjacent
to the selected one.
If its value is @code{width-only}, sizes are evened only if the reused
window is on the left or right of the selected one and the selected
window is wider than the reused one. If its value is @code{height-only}
sizes are evened only if the reused window is above or beneath the
selected window and the selected window is higher than the reused one.
Any other non-@code{nil} value means to even sizes in any of these cases
provided the selected window is larger than the reused one in the sense
of their combination.
@end defopt
@defopt pop-up-frames
If the value of this variable is non-@code{nil}, that means
@code{display-buffer} may display buffers by making new frames. The
......@@ -3690,7 +3705,7 @@ The coordinates are in the header line of @var{window}.
The coordinates are in the divider separating @var{window} from a
window on the right.
@item right-divider
@item bottom-divider
The coordinates are in the divider separating @var{window} from a
window beneath.
......@@ -1106,6 +1106,10 @@ and `window-divider-default-right-width'.
how `switch-to-buffer' proceeds interactively when the selected window
is strongly dedicated to its buffer.
** The option `even-window-heights' has been renamed to
`even-window-sizes' and now handles window widths as well.
** Tearoff menus and detachable toolbars for Gtk+ has been removed.
Those features have been deprecated in Gtk+ for a long time.
......@@ -1163,8 +1163,8 @@ size of WINDOW."
(and (window-combined-p window t)
(and (eq quit-cadr 'frame)
(eq window (frame-root-window window))))
(eq window (frame-root-window window))))
(fit-window-to-buffer window height nil width nil t))))
;;; Help windows.
......@@ -4358,11 +4358,18 @@ nil means to not handle the buffer in a particular way. This
(eq (nth 3 quit-restore) buffer))
;; Show another buffer stored in quit-restore parameter.
(when (and (integerp (nth 3 quad))
(/= (nth 3 quad) (window-total-height window)))
(if (window-combined-p window)
(/= (nth 3 quad) (window-total-height window))
(/= (nth 3 quad) (window-total-width window))))
;; Try to resize WINDOW to its old height but don't signal an
;; error.
(condition-case nil
(window-resize window (- (nth 3 quad) (window-total-height window)))
(- (nth 3 quad) (if (window-combined-p window)
(window-total-height window)
(window-total-width window)))
(window-combined-p window t))
(error nil)))
(set-window-dedicated-p window nil)
;; Restore WINDOW's previous buffer, start and point position.
......@@ -5500,7 +5507,9 @@ element is BUFFER."
;; Preserve window-point-insertion-type (Bug#12588).
(window-point window) window-point-insertion-type)
(window-total-height window))
(if (window-combined-p window)
(window-total-height window)
(window-total-width window)))
(selected-window) buffer)))))
((eq type 'window)
;; WINDOW has been created on an existing frame.
......@@ -6081,33 +6090,38 @@ represents a live window, nil otherwise."
(defcustom even-window-heights t
"If non-nil `display-buffer' will try to even window heights.
(defcustom even-window-sizes t
"If non-nil `display-buffer' will try to even window sizes.
Otherwise `display-buffer' will leave the window configuration
alone. Heights are evened only when `display-buffer' chooses a
window that appears above or below the selected window."
alone. Special values are `height-only' to even heights only and
`width-only' to even widths only. Any other value means to even
any of them."
:type 'boolean
:group 'windows)
(defun window--even-window-heights (window)
"Even heights of WINDOW and selected window.
Do this only if these windows are vertically adjacent to each
other, `even-window-heights' is non-nil, and the selected window
is higher than WINDOW."
(when (and even-window-heights
;; Even iff WINDOW forms a vertical combination with the
;; selected window, and WINDOW's height exceeds that of the
;; selected window, see also bug#11880.
(window-combined-p window)
(= (window-child-count (window-parent window)) 2)
(eq (window-parent) (window-parent window))
(> (window-total-height) (window-total-height window)))
;; Don't throw an error if we can't even window heights for
;; whatever reason.
(condition-case nil
(/ (- (window-total-height window) (window-total-height)) 2))
(error nil))))
(defvaralias 'even-window-heights 'even-window-sizes)
(defun window--even-window-sizes (window)
"Even sizes of WINDOW and selected window.
Even only if these windows are the only children of their parent,
`even-window-sizes' has the appropriate value and the selected
window is larger than WINDOW."
(when (and (= (window-child-count (window-parent window)) 2)
(eq (window-parent) (window-parent window)))
((and (not (memq even-window-sizes '(nil height-only)))
(window-combined-p window t)
(> (window-total-width) (window-total-width window)))
(condition-case nil
(/ (- (window-total-width window) (window-total-width)) 2) t)
(error nil)))
((and (not (memq even-window-sizes '(nil width-only)))
(window-combined-p window)
(> (window-total-height) (window-total-height window)))
(condition-case nil
(/ (- (window-total-height window) (window-total-height)) 2))
(error nil))))))
(defun window--display-buffer (buffer window type &optional alist dedicated)
"Display BUFFER in WINDOW.
......@@ -6767,7 +6781,7 @@ that frame."
(window--display-buffer buffer window 'reuse alist)
(window--even-window-heights window)
(window--even-window-sizes window)
(unless (cdr (assq 'inhibit-switch-frame alist))
(window--maybe-raise-frame (window-frame window)))))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment