GNU bug report logs - #3142
23.0.92; split-window-prefered-function should be able to use split-window-horizontally/split-window-vertically

Previous Next

Package: emacs;

Reported by: Jared Finder <jfinder <at> crypticstudios.com>

Date: Tue, 28 Apr 2009 01:45:03 UTC

Severity: wishlist

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


Message #57 received at 3142 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 3142 <at> debbugs.gnu.org, Juri Linkov <juri <at> jurta.org>,
        Jared Finder <jfinder <at> crypticstudios.com>
Subject: Re: bug#3142: 23.0.92; split-window-prefered-function should be able
 to use split-window-horizontally/split-window-vertically
Date: Thu, 30 Apr 2009 10:54:23 +0200
[Message part 1 (text/plain, inline)]
> I agree it would make sense to operate on the selected-window rather
> than pass an explicit window argument.

Please have a look at the attached patch.

martin
[window.el.diff (text/plain, inline)]
*** window.el.~1.179.~	2009-04-29 07:50:42.078125000 +0200
--- window.el	2009-04-30 10:48:18.875000000 +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,828 ----
    :type 'boolean
    :group 'windows)
  
+ (defcustom split-window-preferred-function 'split-selected-window
+   "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 window can (or shall) not be split."
+   :type '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-selected-window' 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-selected-window' 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."
--- 878,913 ----
  		      (* 2 (max window-min-height
  				(if mode-line-format 2 1))))))))))
  
+ (defun split-selected-window ()
+   "Split selected window.
+ Return the new window if the selected window can be split either
+ vertically or horizontally.  If the selected window is the only
+ window on its frame try to split it disregarding the value of
+ `split-height-threshold'.  Return nil if the selected window
+ can't be split.  This function provides the default value for
+ `split-window-preferred-function'."
+   (or (and (window--splittable-p (selected-window))
+ 	   ;; Split window vertically.
+ 	   (split-window))
+       (and (window--splittable-p (selected-window) t)
+ 	   ;; Split window horizontally.
+ 	   (split-window nil nil t))
+       (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))))))
+ 
  (defun window--try-to-split-window (window)
!   "Split WINDOW if it can be split.
! Return value returned by `split-window-preferred-function'."
!   (and (window-live-p window)
!        (not (frame-parameter (window-frame window) 'unsplittable))
!        (with-selected-window window
! 	 (funcall split-window-preferred-function))))
  
  (defun window--frame-usable-p (frame)
    "Return FRAME if it can be used to display a buffer."

This bug report was last modified 13 years and 291 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.