From: martin rudalics <rudalics@gmx.at>
To: Juri Linkov <juri@jurta.org>
Cc: 3142@emacsbugs.donarmstrong.com,
Jared Finder <jfinder@crypticstudios.com>
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 [thread overview]
Message-ID: <49FC06F7.9060509@gmx.at> (raw)
In-Reply-To: <878wlhkoo8.fsf@mail.jurta.org>
[-- Attachment #1: Type: text/plain, Size: 309 bytes --]
> 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
[-- Attachment #2: window.el.diff --]
[-- Type: text/plain, Size: 7916 bytes --]
*** 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."
next prev parent reply other threads:[~2009-05-02 8:40 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-28 1:16 bug#3142: 23.0.92; split-window-prefered-function should be able to use split-window-horizontally/split-window-vertically Jared Finder
2009-04-28 6:29 ` martin rudalics
2009-04-28 17:21 ` Jared Finder
2009-04-28 22:48 ` Juri Linkov
2009-04-29 1:29 ` Stefan Monnier
2009-04-29 7:13 ` martin rudalics
2009-04-29 9:59 ` Juri Linkov
2009-04-29 12:40 ` martin rudalics
2009-04-29 13:50 ` bug#3142: 23.0.92; split-window-prefered-function should be able to usesplit-window-horizontally/split-window-vertically Drew Adams
2009-04-30 9:05 ` martin rudalics
2011-10-05 18:49 ` Glenn Morris
2011-10-05 22:11 ` Stefan Monnier
2009-04-29 15:26 ` bug#3142: 23.0.92; split-window-prefered-function should be able to use split-window-horizontally/split-window-vertically Stefan Monnier
2009-04-30 8:54 ` martin rudalics
2009-04-30 11:47 ` Juri Linkov
2009-04-30 18:20 ` Stefan Monnier
2009-05-01 11:54 ` Juri Linkov
2009-05-01 8:33 ` martin rudalics
2009-05-01 11:52 ` Juri Linkov
2009-05-02 8:40 ` martin rudalics [this message]
2009-05-05 7:02 ` martin rudalics
2009-05-05 11:03 ` Juri Linkov
2009-05-06 1:41 ` Stefan Monnier
2009-05-06 16:21 ` martin rudalics
2009-05-06 19:04 ` Stefan Monnier
2009-05-07 9:36 ` martin rudalics
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=49FC06F7.9060509@gmx.at \
--to=rudalics@gmx.at \
--cc=3142@emacsbugs.donarmstrong.com \
--cc=jfinder@crypticstudios.com \
--cc=juri@jurta.org \
/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).