emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ace-window d92320e 10/92: Add fair window split.


From: Stefan Monnier
Subject: [elpa] externals/ace-window d92320e 10/92: Add fair window split.
Date: Wed, 17 Mar 2021 18:39:11 -0400 (EDT)

branch: externals/ace-window
commit d92320e74089cb346e172c63b02cce48a0d8cca7
Author: Will S. Medrano <will.s.medrano@gmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>

    Add fair window split.
    
    Document fair window splitting
    
    Fixes #83
---
 README.md     |  2 ++
 ace-window.el | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/README.md b/README.md
index 59afd57..8d87bbd 100644
--- a/README.md
+++ b/README.md
@@ -50,6 +50,7 @@ You can also start by calling `ace-window` and then decide to 
switch the action
 
 - <kbd>x</kbd> - delete window
 - <kbd>m</kbd> - swap (move) window
+- <kbd>c</kbd> - split window fairly, either vertically or horizontally
 - <kbd>v</kbd> - split window vertically
 - <kbd>b</kbd> - split window horizontally
 - <kbd>n</kbd> - select the previous window
@@ -109,6 +110,7 @@ By default is:
     '((?x aw-delete-window " Ace - Delete Window")
         (?m aw-swap-window " Ace - Swap Window")
         (?n aw-flip-window)
+        (?c aw-split-window-fair " Ace - Split Fair Window")
         (?v aw-split-window-vert " Ace - Split Vert Window")
         (?b aw-split-window-horz " Ace - Split Horz Window")
         (?i delete-other-windows " Ace - Maximize Window")
diff --git a/ace-window.el b/ace-window.el
index ad7204b..02a0654 100644
--- a/ace-window.el
+++ b/ace-window.el
@@ -263,6 +263,7 @@ LEAF is (PT . WND)."
     (?m aw-swap-window " Ace - Swap Window")
     (?M aw-move-window " Ace - Move Window")
     (?n aw-flip-window)
+    (?c aw-split-window-fair " Ace - Split Fair Window")
     (?v aw-split-window-vert " Ace - Split Vert Window")
     (?b aw-split-window-horz " Ace - Split Horz Window")
     (?i delete-other-windows " Ace - Maximize Window")
@@ -504,6 +505,21 @@ Switch the current window to the previous buffer."
   (select-window window)
   (split-window-horizontally))
 
+(defcustom aw-fair-aspect-ratio 2
+  "The aspect ratio to aim for when splitting windows.
+Sizes are based on the number of characters, not pixels.
+Increase to prefer wider windows, or decrease for taller windows."
+  :type 'number)
+
+(defun aw-split-window-fair (window)
+  "Split WINDOW vertically or horizontally, based on its current dimensions.
+Modify `aw-fair-aspect-ratio' to tweak behavior."
+  (let ((w (window-body-width window))
+        (h (window-body-height window)))
+    (if (< (* h aw-fair-aspect-ratio) w)
+        (aw-split-window-horz window)
+      (aw-split-window-vert window))))
+
 (defun aw-offset (window)
   "Return point in WINDOW that's closest to top left corner.
 The point is writable, i.e. it's not part of space after newline."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]