From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.bugs Subject: bug#20189: 25.0.50; Feature request: Alternative split-window-sensibly functions Date: Thu, 26 Mar 2015 11:58:17 +0100 Message-ID: <5513E649.80004@gmx.at> 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; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1427367605 4751 80.91.229.3 (26 Mar 2015 11:00:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 26 Mar 2015 11:00:05 +0000 (UTC) Cc: 20189@debbugs.gnu.org To: Tassilo Horn Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Mar 26 11:59:53 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 1Yb5Vu-00085t-3V for geb-bug-gnu-emacs@m.gmane.org; Thu, 26 Mar 2015 11:59:50 +0100 Original-Received: from localhost ([::1]:43809 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yb5Vt-0007Ua-I5 for geb-bug-gnu-emacs@m.gmane.org; Thu, 26 Mar 2015 06:59:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57284) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yb5VD-0006Kv-6t for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2015 06:59:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yb5V9-00052b-1n for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2015 06:59:07 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:47267) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yb5V8-00052P-W0 for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2015 06:59:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Yb5V8-0005WP-HK for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2015 06:59:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: martin rudalics Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 26 Mar 2015 10:59: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.142736751721176 (code B ref 20189); Thu, 26 Mar 2015 10:59:02 +0000 Original-Received: (at 20189) by debbugs.gnu.org; 26 Mar 2015 10:58:37 +0000 Original-Received: from localhost ([127.0.0.1]:37040 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Yb5Ui-0005VT-Mb for submit@debbugs.gnu.org; Thu, 26 Mar 2015 06:58:37 -0400 Original-Received: from mout.gmx.net ([212.227.15.19]:49844) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Yb5Uf-0005VF-KS for 20189@debbugs.gnu.org; Thu, 26 Mar 2015 06:58:34 -0400 Original-Received: from [178.191.139.211] ([178.191.139.211]) by mail.gmx.com (mrgmx002) with ESMTPSA (Nemesis) id 0M4WRI-1ZQbFO1UxY-00yfVQ; Thu, 26 Mar 2015 11:58:26 +0100 In-Reply-To: <87k2y51kjk.fsf@gnu.org> X-Provags-ID: V03:K0:ym8H3bb7mnuRBQSe/FBTpCyufOvsDToQnp++HUrylJnkGIXgeCy kMMFJ3w8ioS/jcmZ0CFCRsC4z1kPHeYwfVLRNPg9aAUpwIxSLzZdifVQoczWc1VYZ9Xm1JQ /+M8cgoc8ru/plRMclk51qvPyFV1q+3Vih3PLvzC5ydEk+PyUwTLJXkKTeRrAXk7EFfa0rT +MNEKO7aflo6t7TWWqeuQ== X-UI-Out-Filterresults: notjunk:1; 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:100943 Archived-At: >> 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. Then you have to set `split-width-threshold' to a larger value. >> 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. I only suggested to use the idioms of that form. Instead of `window-tree' or `balance-windows' as you did. > In that case, it should have reused some > existing window. That's invalid with `split-window-preferred-function': This function is called with a window as single argument and is supposed to split that window and return the new window. If the window can (or shall) not be split, it is supposed to return nil. I think its doc-string is very clear about this. > That's ok for me although I think I'd like it better if it was this way: > > +--------------------+--------------------+-----------------+ > | | | | > | | | | > | | | | > | | | | > | | | | > | | | | > | | | | > | | | | > | | | | > | | | | > | | | (TWO) | > | | | (THREE) | > | *scratch* | ONE | FOUR | > +--------------------+--------------------+-----------------+ If you want to "reuse" a window you have to do it "elsewhere". For example thusly (largely untested, you also have to tweak hardcoded values like 40 and 80): (defun th/display-buffer (buffer alist) (or (display-buffer-reuse-window buffer alist) (let* ((root (frame-root-window)) (horizontal (window-combination-p root t)) (combs (window-combinations root horizontal))) (if (> combs 1) (let* ((last (window-last-child root)) (window-combination-resize 'resize) (window (or (and horizontal (>= (/ (window-total-width root) combs) 80) (split-window last nil 'right)) (and (not horizontal) (>= (/ (window-total-height root) combs) 40) (split-window last nil 'below))))) (if (window-live-p window) (window--display-buffer buffer window 'window alist display-buffer-mark-dedicated) ;; Reuse last. (window--display-buffer buffer last 'reuse alist))) ;; Try to pop up a new window. (display-buffer-pop-up-window buffer alist))))) (customize-set-variable 'display-buffer-base-action '(th/display-buffer . nil)) I hope you get the idea ;-) martin