branch: elpa/golden-ratio
commit 550fb225802c6accd047757e66b9105a37e82a90
Author: Thierry Volpiatto <[email protected]>
Commit: Thierry Volpiatto <[email protected]>

    * golden-ratio.el (window-width-after-balance, 
window-height-after-balance): new
    (golden-ratio--resize-window): use them and check with `window-resizable-p'.
---
 golden-ratio.el | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/golden-ratio.el b/golden-ratio.el
index 7da7b7935c..f75e630d51 100644
--- a/golden-ratio.el
+++ b/golden-ratio.el
@@ -53,13 +53,30 @@ will not cause the window to be resized to the golden 
ratio."
 
 (defun golden-ratio--resize-window (dimensions &optional window)
   (with-selected-window (or window (selected-window))
-    (let ((nrow  (floor (- (first  dimensions) (window-height))))
-          (ncol  (floor (- (second dimensions) (window-width)))))
-      (when (not (window-full-height-p))
+    (let ((nrow  (floor (- (first  dimensions) (window-height-after-balance))))
+          (ncol  (floor (- (second dimensions) (window-width-after-balance)))))
+      (when (window-resizable-p (selected-window) nrow)
         (enlarge-window nrow nil))
-      (when (not (window-full-width-p))
+      (when (window-resizable-p (selected-window) ncol t)
         (enlarge-window ncol t)))))
 
+(defun window-width-after-balance ()
+  (let* ((size-ls (loop for i in (window-list)
+                        unless (window-full-width-p i)
+                        collect (window-width i)))
+         (len (length size-ls))
+         (width (and size-ls (floor (/ (apply #'+ size-ls) len)))))
+    (if width (min (window-width) width) (window-width))))
+
+(defun window-height-after-balance ()
+  (let* ((size-ls (loop for i in (window-list)
+                        unless (or (window-full-height-p i)
+                                   (not (window-full-width-p i)))
+                        collect (window-height i)))
+         (len (length size-ls))
+         (height (and size-ls (floor (/ (apply #'+ size-ls) len)))))
+    (if height (min (window-height) height) (window-height))))
+
 ;;;###autoload
 (defun golden-ratio ()
   "Resizes current window to the golden-ratio's size specs."

Reply via email to