From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.bugs Subject: bug#20189: 25.0.50; Feature request: Alternative split-window-sensibly functions Date: Thu, 26 Mar 2015 12:01:05 +0100 Message-ID: <87iodo58ge.fsf@gnu.org> References: <87iodqbvoz.fsf@gnu.org> <551141AC.40003@gmx.at> <87egoebp60.fsf@gnu.org> <551166DE.9070007@gmx.at> <87384ubfwj.fsf@gnu.org> <55127095.2010703@gmx.at> <87k2y51kjk.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1427367748 7007 80.91.229.3 (26 Mar 2015 11:02:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 26 Mar 2015 11:02:28 +0000 (UTC) Cc: 20189@debbugs.gnu.org To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Mar 26 12:02:18 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Yb5YG-0001FE-KW for geb-bug-gnu-emacs@m.gmane.org; Thu, 26 Mar 2015 12:02:16 +0100 Original-Received: from localhost ([::1]:43819 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yb5YG-0000Zi-1M for geb-bug-gnu-emacs@m.gmane.org; Thu, 26 Mar 2015 07:02:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yb5Y6-0000YP-Lm for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2015 07:02:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yb5Y2-0006oN-Hk for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2015 07:02:06 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:47272) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yb5Y2-0006oJ-6F for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2015 07:02:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Yb5Y2-0005cP-12 for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2015 07:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tassilo Horn Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 26 Mar 2015 11:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20189 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 20189-submit@debbugs.gnu.org id=B20189.142736767721542 (code B ref 20189); Thu, 26 Mar 2015 11:02:01 +0000 Original-Received: (at 20189) by debbugs.gnu.org; 26 Mar 2015 11:01:17 +0000 Original-Received: from localhost ([127.0.0.1]:37048 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Yb5XF-0005bK-Pd for submit@debbugs.gnu.org; Thu, 26 Mar 2015 07:01:17 -0400 Original-Received: from deliver.uni-koblenz.de ([141.26.64.15]:38424) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Yb5XA-0005b3-B0 for 20189@debbugs.gnu.org; Thu, 26 Mar 2015 07:01:12 -0400 Original-Received: from thinkpad-t440p (dhcp25.uni-koblenz.de [141.26.71.25]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by deliver.uni-koblenz.de (Postfix) with ESMTPSA id 86FCF1A84DE; Thu, 26 Mar 2015 12:01:05 +0100 (CET) In-Reply-To: <87k2y51kjk.fsf@gnu.org> (Tassilo Horn's message of "Wed, 25 Mar 2015 10:41:19 +0100") User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:100945 Archived-At: Tassilo Horn 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))) (cond ((and (< (window-combinations root) 2) (>= (/ (window-total-width root) (1+ (window-combinations root t))) window-min-width)) (split-window (window-last-child root) nil 'right)) ((and (< (window-combinations root t) 2) (>= (/ (window-total-height root) (1+ (window-combinations root))) window-min-height)) (split-window (window-last-child root) nil 'below)) (t ;; Reuse the LRU window (get-lru-window))))) --8<---------------cut here---------------end--------------->8--- Bye, Tassilo