unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: martin rudalics <rudalics@gmx.at>, emacs-devel@gnu.org
Subject: Re: split-window-preferred-function
Date: Fri, 28 Mar 2008 01:44:35 +0200	[thread overview]
Message-ID: <87d4pfzt2j.fsf@jurta.org> (raw)
In-Reply-To: <jwvr6e2d8ec.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Sat, 22 Mar 2008 12:36:32 -0400")

>>> 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)))
+ 
  \f
  (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/




  parent reply	other threads:[~2008-03-27 23:44 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-19 21:42 split-window-preferred-function martin rudalics
2008-03-20 23:02 ` split-window-preferred-function Juri Linkov
2008-03-21  1:47   ` split-window-preferred-function Stefan Monnier
2008-03-22  1:07     ` split-window-preferred-function Juri Linkov
2008-03-22 16:36       ` split-window-preferred-function Stefan Monnier
2008-03-23  2:16         ` split-window-preferred-function Juri Linkov
2008-03-27 23:44         ` Juri Linkov [this message]
2008-03-28 19:50           ` split-window-preferred-function martin rudalics
2008-03-29  0:45             ` split-window-preferred-function Juri Linkov
2008-03-29  9:05               ` split-window-preferred-function martin rudalics
2008-03-29 12:30                 ` split-window-preferred-function Juri Linkov
2008-03-29 13:25                   ` split-window-preferred-function martin rudalics
2008-03-29 19:42                   ` split-window-preferred-function Stefan Monnier
2008-03-30  5:49                   ` split-window-preferred-function Richard Stallman
2008-04-02  8:53                     ` split-window-preferred-function martin rudalics
2008-04-02  9:36                       ` split-window-preferred-function Tassilo Horn
2008-04-02  9:58                         ` split-window-preferred-function martin rudalics
2008-04-02 10:30                           ` split-window-preferred-function Tassilo Horn
2008-04-02 12:13                             ` split-window-preferred-function martin rudalics
2008-04-02 12:33                               ` split-window-preferred-function Tassilo Horn
2008-04-02 22:26                         ` split-window-preferred-function David De La Harpe Golden
2008-04-02 15:18                       ` split-window-preferred-function Stefan Monnier
2008-04-02 17:00                         ` split-window-preferred-function martin rudalics
2008-04-02 22:27                       ` split-window-preferred-function Juri Linkov
2008-04-03  6:49                         ` split-window-preferred-function martin rudalics
2008-04-03 22:52                           ` split-window-preferred-function Juri Linkov
2008-04-04  6:50                             ` split-window-preferred-function martin rudalics
2008-04-03  7:02                         ` split-window-preferred-function Tassilo Horn
2008-04-03 22:54                           ` split-window-preferred-function Juri Linkov
2008-04-04 10:04                             ` split-window-preferred-function Tassilo Horn
2008-04-04 12:19                               ` split-window-preferred-function martin rudalics
2008-04-04 12:57                                 ` split-window-preferred-function Tassilo Horn
2008-04-04 13:55                               ` split-window-preferred-function Stefan Monnier
2008-04-04 17:21                                 ` split-window-preferred-function Tassilo Horn
2008-04-04 20:21                                   ` split-window-preferred-function Stefan Monnier
2008-04-04 22:14                                     ` split-window-preferred-function Tassilo Horn
2008-04-04 23:52                                       ` split-window-preferred-function Stefan Monnier
2008-03-21  9:18   ` split-window-preferred-function martin rudalics
2008-03-22  1:09     ` split-window-preferred-function Juri Linkov
  -- strict thread matches above, loose matches on Subject: below --
2008-04-05 12:36 split-window-preferred-function grischka
2008-04-05 15:42 ` split-window-preferred-function martin rudalics
2008-04-05 18:35   ` split-window-preferred-function grischka
2008-04-05 22:02     ` split-window-preferred-function martin rudalics
2008-04-06 16:45       ` split-window-preferred-function grischka
2008-04-06 20:35   ` split-window-preferred-function Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d4pfzt2j.fsf@jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).