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: Wed, 25 Mar 2015 10:41:19 +0100 Message-ID: <87k2y51kjk.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> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1427277530 13688 80.91.229.3 (25 Mar 2015 09:58:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 25 Mar 2015 09:58:50 +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 Wed Mar 25 10:58:43 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 1Yai5B-0005sL-Ad for geb-bug-gnu-emacs@m.gmane.org; Wed, 25 Mar 2015 10:58:41 +0100 Original-Received: from localhost ([::1]:37385 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yai55-0000az-Ub for geb-bug-gnu-emacs@m.gmane.org; Wed, 25 Mar 2015 05:58:35 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yai51-0000aY-Sx for bug-gnu-emacs@gnu.org; Wed, 25 Mar 2015 05:58:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yai4y-0001D7-Kn for bug-gnu-emacs@gnu.org; Wed, 25 Mar 2015 05:58:31 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45821) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yahp4-0003jd-Mq for bug-gnu-emacs@gnu.org; Wed, 25 Mar 2015 05:42:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Yahp4-0007VE-4Z for bug-gnu-emacs@gnu.org; Wed, 25 Mar 2015 05:42:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87iodqbvoz.fsf@gnu.org> Resent-From: Tassilo Horn Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 25 Mar 2015 09:42:02 +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.142727648528784 (code B ref 20189); Wed, 25 Mar 2015 09:42:02 +0000 Original-Received: (at 20189) by debbugs.gnu.org; 25 Mar 2015 09:41:25 +0000 Original-Received: from localhost ([127.0.0.1]:35597 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YahoT-0007UB-08 for submit@debbugs.gnu.org; Wed, 25 Mar 2015 05:41:25 -0400 Original-Received: from deliver.uni-koblenz.de ([141.26.64.15]:46012) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YahoP-0007Tz-1U for 20189@debbugs.gnu.org; Wed, 25 Mar 2015 05:41:22 -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 9241B1A843E; Wed, 25 Mar 2015 10:41:19 +0100 (CET) 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:100918 Archived-At: martin rudalics writes: >> two consecutive C-x 3 starting from the big single window results in >> three side-by-side *balanced* windows, each being 86x82 large. >> That's actually what I wanted. However, I'd like that this splitting >> behavior was the default for `display-buffer'. But that fails >> because after the first horizontal split, `window-splittable-p' says >> that both horizontal windows aren't horizontally splittable anymore >> because they are narrower than `split-width-threshold'. > > If you set `split-width-threshold' to zero and > `split-height-threshold' to nil you should get the behavior you want. Wouldn't that mean that I get as many horizontal windows until they become smaller than `window-min-width'? I want them to alway be at least 80 columns wide. >> I've come up with a solution which seems to fit my preferences quite >> nicely although it's probably quite hackish and ignores possible >> contracts that might exist for dedicated windows, fixed-size windows, >> side windows and what else there might be. > > 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. Here's my test case: --8<---------------cut here---------------start------------->8--- (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))))) (setq split-window-preferred-function #'th/split-window-sensibly) (defun test-splitting () (interactive) (display-buffer (get-buffer-create "ONE")) (display-buffer (get-buffer-create "TWO")) (display-buffer (get-buffer-create "THREE")) (display-buffer (get-buffer-create "FOUR"))) --8<---------------cut here---------------end--------------->8--- So now when starting with emacs -Q, maximizing, putting the above in *scratch*, evaling it, followed by M-x test-splitting RET, I get: +---------------+-------------+---------------+-------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | THREE | | | | +-------------+ | | | | | | | | | | | | | | | | | | | | | *scratch* | ONE | TWO | FOUR | +---------------+-------------+---------------+-------------+ With my function, I get instead +--------------------+--------------------+-----------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (ONE) | | | | (THREE) | | *scratch* | TWO | FOUR | +--------------------+--------------------+-----------------+ where the (ONE), (THREE) denotes the buffer history, e.g., initially the leftmost window showed buffer ONE, then it was reused to show THREE, and finally it was reused again to show buffer FOUR. That's ok for me although I think I'd like it better if it was this way: +--------------------+--------------------+-----------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (TWO) | | | | (THREE) | | *scratch* | ONE | FOUR | +--------------------+--------------------+-----------------+ Bye, Tassilo