[Top][All Lists]

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

bug#20189: 25.0.50; Feature request: Alternative split-window-sensibly f

From: Tassilo Horn
Subject: bug#20189: 25.0.50; Feature request: Alternative split-window-sensibly functions
Date: Thu, 26 Mar 2015 12:01:05 +0100
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux)

Tassilo Horn <address@hidden> writes:

>> You should be able to simplify your code by using idioms from the
>> below.
>> (defun th/split-window-sensibly (_window)
>>   (let ((root (frame-root-window))
>>      (window-combination-resize 'resize))
>>     (cond
>>      ((>= (/ (window-total-width root) (window-combinations root t)) 80)
>>       (split-window (window-last-child root) nil 'right))
>>      ((>= (/ (window-total-height root) (window-combinations root)) 40)
>>       (split-window (window-last-child root) nil 'below))
>>      (t
>>       (split-window-sensibly window)))))
> With that and repeated `display-buffer' calls for different buffers
> starting with a single 269x82 window, I get 3 balanced side-by-side
> windows first (good!), but the next d-b creates another horizontal
> window.  Then I have 4 side-by-side balanced windows where each one is
> less than 80 columns wide.  And yet another d-b splits the rightmost
> window vertically although I don't want vertical splits at all if there
> are already horizontal splits.  In that case, it should have reused some
> existing window.

With your suggestions, I finally came up with this which seems to work
exactly as I like it:

--8<---------------cut here---------------start------------->8---
(setq window-min-height 30
      window-min-width 80
      window-combination-resize t
      window-combination-limit nil)

(defun th/split-window-sensibly (window)
  (let ((root (frame-root-window)))
     ((and (< (window-combinations root) 2)
           (>= (/ (window-total-width root)
                  (1+ (window-combinations root t)))
      (split-window (window-last-child root) nil 'right))
     ((and (< (window-combinations root t) 2)
           (>= (/ (window-total-height root)
                  (1+ (window-combinations root)))
      (split-window (window-last-child root) nil 'below))
      ;; Reuse the LRU window
--8<---------------cut here---------------end--------------->8---


reply via email to

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