]> git.eshelyaron.com Git - emacs.git/commitdiff
2015-07-22 Martin Rudalics <rudalics@gmx.at>
authorMartin Rudalics <rudalics@gmx.at>
Wed, 22 Jul 2015 10:20:13 +0000 (12:20 +0200)
committerMartin Rudalics <rudalics@gmx.at>
Wed, 22 Jul 2015 10:20:13 +0000 (12:20 +0200)
Optionally even widths of `display-buffer' windows.  (Bug#21100)

* lisp/window.el (quit-restore-window): Restore width if
requested.
(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
`even-window-sizes'.
(Coordinates and Windows): Fix typo.

doc/lispref/windows.texi
etc/NEWS
lisp/help.el
lisp/window.el

index b2bc637800808398820419cb94c72eda62e153e7..750397c73751b0186482444b0b68ff36e9bf9df2 100644 (file)
@@ -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.
 
index 69ebb72854487d74c6704e540b93f6f719405a90..666cccff8e45c818e055788b89d51bc03448877f 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -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.
 
index 1826cb7219a2f9be9d93279bdefb74f892eb2798..46136d91003748479e533cad36edd69290ab9d73 100644 (file)
@@ -1163,8 +1163,8 @@ size of WINDOW."
                       (and (window-combined-p window t)
                            fit-window-to-buffer-horizontally)))
              (and (eq quit-cadr 'frame)
-                    fit-frame-to-buffer
-                    (eq window (frame-root-window window))))
+                   fit-frame-to-buffer
+                   (eq window (frame-root-window window))))
        (fit-window-to-buffer window height nil width nil t))))
 
 ;;; Help windows.
index a4ed9ea721648d12a980992410c9bde909154a6d..1a76ecec34dfe53cbbeca25bf3175e0c3bb8d399 100644 (file)
@@ -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)))
+           (window-resize
+             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).
                     (copy-marker
                      (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."
                        ))
        frame))))
 
-(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
-       (enlarge-window
-        (/ (- (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)))
+    (cond
+     ((and (not (memq even-window-sizes '(nil height-only)))
+           (window-combined-p window t)
+           (> (window-total-width) (window-total-width window)))
+      (condition-case nil
+          (enlarge-window
+           (/ (- (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
+          (enlarge-window
+           (/ (- (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."
 
       (prog1
          (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)))))))