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: Tue, 24 Mar 2015 15:59:08 +0100 Message-ID: <87384ubfwj.fsf@gnu.org> References: <87iodqbvoz.fsf@gnu.org> <551141AC.40003@gmx.at> <87egoebp60.fsf@gnu.org> <551166DE.9070007@gmx.at> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1427209237 7874 80.91.229.3 (24 Mar 2015 15:00:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 24 Mar 2015 15:00:37 +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 Tue Mar 24 16:00:25 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 1YaQJQ-0001nF-LM for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 Mar 2015 16:00:12 +0100 Original-Received: from localhost ([::1]:32928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YaQJQ-0000O7-33 for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 Mar 2015 11:00:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YaQJM-0000Mi-EE for bug-gnu-emacs@gnu.org; Tue, 24 Mar 2015 11:00:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YaQJJ-0002tj-6y for bug-gnu-emacs@gnu.org; Tue, 24 Mar 2015 11:00:08 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45396) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YaQJJ-0002sq-3c for bug-gnu-emacs@gnu.org; Tue, 24 Mar 2015 11:00:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YaQJI-0007KS-5X for bug-gnu-emacs@gnu.org; Tue, 24 Mar 2015 11:00:04 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tassilo Horn Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 24 Mar 2015 15:00:03 +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.142720915428085 (code B ref 20189); Tue, 24 Mar 2015 15:00:03 +0000 Original-Received: (at 20189) by debbugs.gnu.org; 24 Mar 2015 14:59:14 +0000 Original-Received: from localhost ([127.0.0.1]:35172 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YaQIT-0007Iu-DI for submit@debbugs.gnu.org; Tue, 24 Mar 2015 10:59:14 -0400 Original-Received: from deliver.uni-koblenz.de ([141.26.64.15]:34195) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YaQIQ-0007Il-A4 for 20189@debbugs.gnu.org; Tue, 24 Mar 2015 10:59:11 -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 2133A3D6005; Tue, 24 Mar 2015 15:59:09 +0100 (CET) In-Reply-To: <551166DE.9070007@gmx.at> (martin rudalics's message of "Tue, 24 Mar 2015 14:30:06 +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:100886 Archived-At: martin rudalics writes: >>>> With that and a maximized frame of size 269x82, I'd eventually end >>>> up with three side-by-side windows each of size 86x82. >>> >>> Interesting. What is your value of `window-combination-resize'? >> >> I didn't know that, so it has the default value nil. > > Then how comes you "eventually end up with three side-by-side windows > each of size 86x82"? No, I don't end up with that. If I had the split function I imagined, then I would end up with that configuration. So that's the goal I want to achieve but for which I have no solution. > By default you should get one window with 135 columns and two windows > with 67 columns, approximately. Indeed, that's what I get with C-x 3 C-x 3 starting from a single window of size 269x82 and the default value of `window-combination-resize' and `window-combination-limit'. With (setq window-combination-resize t window-combination-limit nil) 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'. >> Reading its docs I get the impression that I want that to be t >> instead, and to have it effective, I'd also need to set >> `window-combination-limit' to nil. >> >> But with >> >> (setq window-combination-resize t >> window-combination-limit nil) ;; was window-size before >> >> and a single 269x82 window, I still get a horizontal split first >> (forming a horizontal combination IIUC) and then a vertical split. > > Yes - these are unrelated. `split-window-sensibly' controls the > "split-direction". > > I share most of your concerns. But I'm not sure though where to put > a/the solution. 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. --8<---------------cut here---------------start------------->8--- (defun th/split-window-sensibly-prefer-horizontal-split (&optional window) "Like `split-window-sensibly' but prefer horizontal splits." (let ((window (or window (selected-window)))) (or (and (window-splittable-p window t) ;; Split window horizontally. (with-selected-window window (split-window-right))) (and (window-splittable-p window) ;; Split window vertically. (with-selected-window window (split-window-below))) (and (eq window (frame-root-window (window-frame window))) (not (window-minibuffer-p window)) ;; If WINDOW is the only window on its frame and is not the ;; minibuffer window, try to split it vertically disregarding ;; the value of `split-height-threshold'. (let ((split-height-threshold 0)) (when (window-splittable-p window) (with-selected-window window (split-window-below)))))))) (defun th/split-window-sensibly (&optional window) (interactive) (let* ((root-tree (car (window-tree))) (new-window (when (listp root-tree) (let ((dir (car root-tree)) (windows (cddr root-tree))) (cond ;; Split horizontally if we're horizontally split ;; already and have enough space for another ;; horizontal window after balancing. ((and (null dir) (cl-every #'windowp windows) (> (apply #'+ (mapcar (lambda (w) (- (window-width w) (/ split-width-threshold 2))) windows)) (/ split-width-threshold 2))) (split-window-right)) ;; Split vertically if we're vertically split already ;; and have enough space for another vertical window. ((and dir (cl-every #'windowp windows) (> (apply #'+ (mapcar (lambda (w) (- (window-height w) (/ split-height-threshold 2))) windows)) (/ split-height-threshold 2))) (split-window-below)) ;; If we're already split either only horizontally or ;; vertically, reuse the right-most/bottom window ;; unless that's the one which should be split (which ;; is usually the selected one). In that case, reuse ;; the LRU window. ((cl-every #'windowp windows) (if (eq window (car (last windows))) (get-lru-window) (car (last windows))))))))) (unless new-window ;; Ok, if we arrive here this means we've already destroyed our preferred ;; either-only-horizontal-or-only-vertical splits layout, so just let my ;; horizontal splitting favoring sensible split function do its job. We ;; have to arrange windows manually anyhow to come back to (setq new-window (th/split-window-sensibly-prefer-horizontal-split window))) (balance-windows (window-parent new-window)) new-window)) (setq split-window-preferred-function #'th/split-window-sensibly) --8<---------------cut here---------------end--------------->8--- Bye, Tassilo