From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: split-window-preferred-function Date: Fri, 28 Mar 2008 01:44:35 +0200 Organization: JURTA Message-ID: <87d4pfzt2j.fsf@jurta.org> References: <47E188D5.5030502@gmx.at> <87hcf1rrdj.fsf@jurta.org> <87r6e3k3hc.fsf@jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1206662209 14960 80.91.229.12 (27 Mar 2008 23:56:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 27 Mar 2008 23:56:49 +0000 (UTC) Cc: martin rudalics , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Mar 28 00:57:20 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Jf1yA-0006NG-MU for ged-emacs-devel@m.gmane.org; Fri, 28 Mar 2008 00:57:19 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jf1xZ-0003Rz-6c for ged-emacs-devel@m.gmane.org; Thu, 27 Mar 2008 19:56:41 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Jf1wG-0002pV-Cr for emacs-devel@gnu.org; Thu, 27 Mar 2008 19:55:20 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Jf1wF-0002ot-4a for emacs-devel@gnu.org; Thu, 27 Mar 2008 19:55:19 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jf1wE-0002oa-TL for emacs-devel@gnu.org; Thu, 27 Mar 2008 19:55:18 -0400 Original-Received: from relay03.kiev.sovam.com ([62.64.120.201]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Jf1wE-0006HN-99 for emacs-devel@gnu.org; Thu, 27 Mar 2008 19:55:18 -0400 Original-Received: from [83.170.232.243] (helo=smtp.svitonline.com) by relay03.kiev.sovam.com with esmtp (Exim 4.67) (envelope-from ) id 1Jf1w9-0006qD-0l; Fri, 28 Mar 2008 01:55:15 +0200 In-Reply-To: (Stefan Monnier's message of "Sat, 22 Mar 2008 12:36:32 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) X-Scanner-Signature: 347b60a7d50e4b51b7e2953e35c97cdf X-DrWeb-checked: yes X-SpamTest-Envelope-From: juri@jurta.org X-SpamTest-Group-ID: 00000000 X-SpamTest-Header: Not Detected X-SpamTest-Info: Profiles 2455 [Mar 21 2008] X-SpamTest-Info: helo_type=3 X-SpamTest-Info: {HEADERS: header Content-Type found without required header Content-Transfer-Encoding} X-SpamTest-Method: none X-SpamTest-Rate: 11 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0278], KAS30/Release X-detected-kernel: by monty-python.gnu.org: FreeBSD 6.x (1) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:93675 Archived-At: >>> I think we need to allow the function to return nil and in this case >>> continue with the rest of the code. I.e. it should be possible to >>> reproduce in Elisp what happens when split-window-preferred-function >>> is nil. A good way to make sure that's true is to write the code in >>> Elisp in the first place. > >> If I understand you correctly, this patch implements what you meant: > > Part of it, the missing parts: > 1 - update the docstring of split_window_preferred_function. > 2 - provide a non-nil default for split_window_preferred_function > by moving the current C code that checks the size and calls > split-window to Elisp. Please see a complete patch with docstring updates: Index: src/window.c =================================================================== RCS file: /sources/emacs/emacs/src/window.c,v retrieving revision 1.604 diff -c -w -b -r1.604 window.c *** src/window.c 19 Mar 2008 15:18:29 -0000 1.604 --- src/window.c 27 Mar 2008 23:36:06 -0000 *************** *** 3848,3853 **** --- 3848,3859 ---- else window = Fget_largest_window (frames, Qt); + if (!NILP (Vsplit_window_preferred_function)) + tem = call1 (Vsplit_window_preferred_function, window); + + if (!NILP (tem)) + window = tem; + else /* If the largest window is tall enough, full-width, and either eligible for splitting or the only window, split it. */ if (!NILP (window) *************** *** 3857,3863 **** || (NILP (XWINDOW (window)->parent))) && (window_height (window) >= (2 * window_min_size_2 (XWINDOW (window), 0)))) ! window = call1 (Vsplit_window_preferred_function, window); else { Lisp_Object upper, other; --- 3863,3869 ---- || (NILP (XWINDOW (window)->parent))) && (window_height (window) >= (2 * window_min_size_2 (XWINDOW (window), 0)))) ! window = Fsplit_window (window, Qnil, Qnil); else { Lisp_Object upper, other; *************** *** 3872,3878 **** || (NILP (XWINDOW (window)->parent))) && (window_height (window) >= (2 * window_min_size_2 (XWINDOW (window), 0)))) ! window = call1 (Vsplit_window_preferred_function, window); else window = Fget_lru_window (frames, Qnil); /* If Fget_lru_window returned nil, try other approaches. */ --- 3878,3884 ---- || (NILP (XWINDOW (window)->parent))) && (window_height (window) >= (2 * window_min_size_2 (XWINDOW (window), 0)))) ! window = Fsplit_window (window, Qnil, Qnil); else window = Fget_lru_window (frames, Qnil); /* If Fget_lru_window returned nil, try other approaches. */ *************** *** 7596,7604 **** doc: /* Function to use to split a window. This is used by `display-buffer' to allow the user to choose whether to split windows horizontally or vertically or some mix of the two. It is called with a window as single argument and should split it in two ! and return the new window. */); ! Vsplit_window_preferred_function = intern ("split-window"); DEFVAR_INT ("window-min-height", &window_min_height, doc: /* *Delete any window less than this tall (including its mode line). --- 7602,7613 ---- doc: /* Function to use to split a window. This is used by `display-buffer' to allow the user to choose whether to split windows horizontally or vertically or some mix of the two. + When this variable is nil, `display-buffer' splits windows vertically. + Otherwise, `display-buffer' calls this function to split a window. It is called with a window as single argument and should split it in two ! and return the new window, or return an appropriate existing window ! if splitting is not eligible. */); ! Vsplit_window_preferred_function = Qnil; DEFVAR_INT ("window-min-height", &window_min_height, doc: /* *Delete any window less than this tall (including its mode line). Index: lisp/cus-start.el =================================================================== RCS file: /sources/emacs/emacs/lisp/cus-start.el,v retrieving revision 1.118 diff -c -r1.118 cus-start.el *** lisp/cus-start.el 8 Feb 2008 20:12:26 -0000 1.118 --- lisp/cus-start.el 27 Mar 2008 23:37:05 -0000 *************** *** 346,358 **** (split-height-threshold windows integer) (split-window-preferred-function windows ! (choice (const :tag "vertically" split-window) ;; FIXME: Add `sensibly' which chooses between ;; vertical or horizontal splits depending on the size ;; and shape of the window. (const :tag "horizontally" ! (lambda (window) ! (split-window window nil 'horiz)))) "23.1") (window-min-height windows integer) (window-min-width windows integer) --- 346,357 ---- (split-height-threshold windows integer) (split-window-preferred-function windows ! (choice (const :tag "vertically" nil) ;; FIXME: Add `sensibly' which chooses between ;; vertical or horizontal splits depending on the size ;; and shape of the window. (const :tag "horizontally" ! split-window-preferred-horizontally)) "23.1") (window-min-height windows integer) (window-min-width windows integer) Index: lisp/window.el =================================================================== RCS file: /sources/emacs/emacs/lisp/window.el,v retrieving revision 1.131 diff -c -r1.131 window.el *** lisp/window.el 8 Jan 2008 20:44:44 -0000 1.131 --- lisp/window.el 27 Mar 2008 23:36:37 -0000 *************** *** 614,619 **** --- 614,661 ---- (setq size (+ (window-width) size))) (split-window-save-restore-data (split-window nil size t) old-w))) + (defun split-window-preferred-horizontally (window) + "Split WINDOW horizontally or select an appropriate existing window. + It is called by `display-buffer' to split windows horizontally + when the option `split-window-preferred-function' is set to \"horizontally\". + This function tries to match the implementation of vertical splitting + in `display-buffer' as close as possible but with the logic of + horizontal splitting. It returns a new window or an appropriate + existing window if splitting is not eligible." + (interactive) + ;; If the largest window is wide enough, eligible for splitting, + ;; and the only window, split it horizontally. + (if (and window + (not (frame-parameter (window-frame window) 'unsplittable)) + (one-window-p (window-frame window)) + (>= (window-width window) (* 2 window-min-width))) + (split-window window nil t) + ;; Otherwise, if the LRU window is wide enough, eligible for + ;; splitting and selected or the only window, split it horizontally. + (setq window (get-lru-window nil t)) + (if (and window + (not (frame-parameter (window-frame window) 'unsplittable)) + (or (eq window (selected-window)) + (one-window-p (window-frame window))) + (>= (window-width window) (* 2 window-min-width))) + (split-window window nil t) + ;; Otherwise, if get-lru-window returns nil, try other approaches. + (setq window (get-lru-window nil nil)) + ;; Try visible frames first. + (unless window + (setq window (get-buffer-window (current-buffer) 'visible))) + (unless window + (setq window (get-largest-window 'visible))) + ;; If that didn't work, try iconified frames. + (unless window + (setq window (get-buffer-window (current-buffer) 0))) + (unless window + (setq window (get-largest-window 0))) + ;; As a last resort, make a new frame. + (unless window + (setq window (frame-selected-window (funcall pop-up-frame-function)))) + window))) + (defun set-window-text-height (window height) "Sets the height in lines of the text display area of WINDOW to HEIGHT. -- Juri Linkov http://www.jurta.org/emacs/