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#3142: 23.0.92; split-window-prefered-function should be able to use split-window-horizontally/split-window-vertically Date: Sat, 02 May 2009 10:40:23 +0200 Message-ID: <49FC06F7.9060509@gmx.at> References: <49F6A25B.3050108@gmx.at> <874ow84cp6.fsf_-_@mail.jurta.org> <49F7FE0F.1020107@gmx.at> <49F9673F.6000806@gmx.at> <87ljpiuyi0.fsf@mail.jurta.org> <49FAB3F1.7040301@gmx.at> <878wlhkoo8.fsf@mail.jurta.org> Reply-To: martin rudalics , 3142@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090807060400060205070103" X-Trace: ger.gmane.org 1241254340 12965 80.91.229.12 (2 May 2009 08:52:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 2 May 2009 08:52:20 +0000 (UTC) Cc: 3142@emacsbugs.donarmstrong.com, Jared Finder To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat May 02 10:52:09 2009 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1M0Ax7-0005uI-4I for geb-bug-gnu-emacs@m.gmane.org; Sat, 02 May 2009 10:52:09 +0200 Original-Received: from localhost ([127.0.0.1]:49724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M0Ax6-0002E8-9Q for geb-bug-gnu-emacs@m.gmane.org; Sat, 02 May 2009 04:52:08 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M0Awz-0002E3-1A for bug-gnu-emacs@gnu.org; Sat, 02 May 2009 04:52:01 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M0Awt-0002Dk-Ut for bug-gnu-emacs@gnu.org; Sat, 02 May 2009 04:51:59 -0400 Original-Received: from [199.232.76.173] (port=41062 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M0Awt-0002Dh-OC for bug-gnu-emacs@gnu.org; Sat, 02 May 2009 04:51:55 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:37480) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1M0Aws-0001Az-Um for bug-gnu-emacs@gnu.org; Sat, 02 May 2009 04:51:55 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id n428pqhS013251; Sat, 2 May 2009 01:51:52 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id n428j3Nf010669; Sat, 2 May 2009 01:45:03 -0700 X-Loop: owner@emacsbugs.donarmstrong.com Resent-From: martin rudalics Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Sat, 02 May 2009 08:45:03 +0000 Resent-Message-ID: Resent-Sender: owner@emacsbugs.donarmstrong.com X-Emacs-PR-Message: followup 3142 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 3142-submit@emacsbugs.donarmstrong.com id=B3142.124125377410590 (code B ref 3142); Sat, 02 May 2009 08:45:03 +0000 Original-Received: (at 3142) by emacsbugs.donarmstrong.com; 2 May 2009 08:42:54 +0000 X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. Original-Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with SMTP id n428gms9010584 for <3142@emacsbugs.donarmstrong.com>; Sat, 2 May 2009 01:42:50 -0700 Original-Received: (qmail invoked by alias); 02 May 2009 08:42:42 -0000 Original-Received: from 62-47-43-85.adsl.highway.telekom.at (EHLO [62.47.43.85]) [62.47.43.85] by mail.gmx.net (mp017) with SMTP; 02 May 2009 10:42:42 +0200 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX18yDkQyye4ythRuN+Q1rXmcXHpuIU0pr9DHY80FMv 6yh6T9OmAgAtkq User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) In-Reply-To: <878wlhkoo8.fsf@mail.jurta.org> X-Y-GMX-Trusted: 0 X-FuHaFi: 0.8100000000000001,0.53 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Resent-Date: Sat, 02 May 2009 04:51:59 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:27602 Archived-At: This is a multi-part message in MIME format. --------------090807060400060205070103 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit > Thanks, the only thing to fix I noticed is the missing const option for > the default value split-window-sensibly in split-window-preferred-function. I added the const option, rewrote some doc-strings, and narrowed the scope of the condition-case. If no one objects I shall commit that. Thanks, martin --------------090807060400060205070103 Content-Type: text/plain; name="window.el.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="window.el.diff" *** window.el.~1.179.~ 2009-04-29 07:50:42.078125000 +0200 --- window.el 2009-05-01 17:28:24.125000000 +0200 *************** *** 794,832 **** :type 'boolean :group 'windows) (defcustom split-height-threshold 80 "Minimum height of window to be split vertically. ! If the value is a number, `display-buffer' can split a window ! only if it has at least as many lines. If the value is nil, ! `display-buffer' cannot split a window vertically. ! ! If the window is the only window on its frame, `display-buffer' ! can split it regardless of this value." :type '(choice (const nil) (number :tag "lines")) :version "23.1" :group 'windows) (defcustom split-width-threshold 160 "Minimum width of window to be split horizontally. ! If the value is a number, `display-buffer' can split a window ! only if it has at least as many columns. If the value is nil, ! `display-buffer' cannot split a window horizontally." :type '(choice (const nil) (number :tag "columns")) :version "23.1" :group 'windows) - (defcustom split-window-preferred-function nil - "Function used by `display-buffer' to split windows. - If non-nil, a function called with a window as single argument - supposed to split that window and return the new window. If the - function returns nil the window is not split. - - If nil, `display-buffer' will split the window respecting the - values of `split-height-threshold' and `split-width-threshold'." - :type '(choice (const nil) (function :tag "Function")) - :version "23.1" - :group 'windows) - (defun window--splittable-p (window &optional horizontal) "Return non-nil if WINDOW can be split evenly. Optional argument HORIZONTAL non-nil means check whether WINDOW --- 794,848 ---- :type 'boolean :group 'windows) + (defcustom split-window-preferred-function 'split-window-sensibly + "Function called by `display-buffer' to split a window. + The window that shall be split is selected when this function is + called. The function is supposed to either return the new window + or nil if the selected window can (or shall) not be split. + + The default is to split the window \"sensibly\". This calls the + function `split-window-sensibly' which tries to split the window + in a way which seems most suitable. A second standard option is + \"vertically\" which calls the function `split-window-vertically' + to split the window into two windows one above the other. The + third standard option is \"horizontally\" which calls the + function `split-window-horizontally' to split the window into two + windows side by side. + + If you set this to any other function, observe that it may be + called two times: A first time with the largest window selected + and, if that call fails to provide a suitable window, a second + time with the least recently used window selected. If neither of + these calls produces a suitable window, `display-buffer' will use + an existing one to display its buffer." + :type '(choice + (const :tag "Split sensibly" split-window-sensibly) + (const :tag "Split vertically" split-window-vertically) + (const :tag "Split horizontally" split-window-horizontally) + (function :tag "Function")) + :version "23.1" + :group 'windows) + (defcustom split-height-threshold 80 "Minimum height of window to be split vertically. ! If the value is a number, `split-window-sensibly' splits a window ! vertically only if it has at least as many lines. If the value ! is nil, it does not split a window vertically. If a window is ! the only window on its frame, it can be split regardless of the ! value of this variable." :type '(choice (const nil) (number :tag "lines")) :version "23.1" :group 'windows) (defcustom split-width-threshold 160 "Minimum width of window to be split horizontally. ! If the value is a number, `split-window-sensibly' splits a window ! only if it has at least as many columns. If the value is nil, it ! does not split a window horizontally." :type '(choice (const nil) (number :tag "columns")) :version "23.1" :group 'windows) (defun window--splittable-p (window &optional horizontal) "Return non-nil if WINDOW can be split evenly. Optional argument HORIZONTAL non-nil means check whether WINDOW *************** *** 882,911 **** (* 2 (max window-min-height (if mode-line-format 2 1)))))))))) (defun window--try-to-split-window (window) ! "Split WINDOW if it is splittable. ! See `window--splittable-p' for how to determine whether a window ! is splittable. If WINDOW can be split, return the value returned ! by `split-window' (or `split-window-preferred-function')." ! (when (and (window-live-p window) ! (not (frame-parameter (window-frame window) 'unsplittable))) ! (if (functionp split-window-preferred-function) ! ;; `split-window-preferred-function' is specified, so use it. ! (funcall split-window-preferred-function window) ! (or (and (window--splittable-p window) ! ;; Split window vertically. ! (split-window window)) ! (and (window--splittable-p window t) ! ;; Split window horizontally. ! (split-window window nil t)) ! (and (eq window (frame-root-window (window-frame window))) ! (not (window-minibuffer-p window)) ! ;; If WINDOW is the only window on its frame and not the ! ;; minibuffer window, attempt to split it vertically ! ;; disregarding the value of `split-height-threshold'. ! (let ((split-height-threshold 0)) ! (and (window--splittable-p window) ! (split-window window)))))))) (defun window--frame-usable-p (frame) "Return FRAME if it can be used to display a buffer." --- 898,945 ---- (* 2 (max window-min-height (if mode-line-format 2 1)))))))))) + (defun split-window-sensibly () + "\"Sensibly\" split the selected window. + If the selected window has at least `split-height-threshold' + lines, split it into two windows one above the other and return + the lower one. Otherwise, if the selected window is at least + `split-width-threshold' columns wide, split it into two windows + side by side and return the one on the right. If this does not + produce a suitable window either and the selected window is the + only one on its frame, try to split that window vertically and + return the lower one. Return nil if that fails as well. + + The default value of `split-window-preferred-function' is set to + this function." + (or (and (window--splittable-p (selected-window)) + ;; Split window vertically. + (split-window-vertically)) + (and (window--splittable-p (selected-window) t) + ;; Split window horizontally. + (split-window-horizontally)) + (and (eq (selected-window) (frame-root-window)) + (not (window-minibuffer-p)) + ;; If the selected 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)) + (and (window--splittable-p (selected-window)) + (split-window-vertically)))))) + (defun window--try-to-split-window (window) ! "Split WINDOW if it can be split. ! Return value returned by `split-window-preferred-function' if it ! represents a live window, nil otherwise." ! (and (window-live-p window) ! (not (frame-parameter (window-frame window) 'unsplittable)) ! (with-selected-window window ! (let ((new-window ! ;; Since `split-window-preferred-function' might ! ;; throw an error use `condition-case'. ! (condition-case nil ! (funcall split-window-preferred-function) ! (error nil)))) ! (and (window-live-p new-window) new-window))))) (defun window--frame-usable-p (frame) "Return FRAME if it can be used to display a buffer." --------------090807060400060205070103--