all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Dedicated window troubles
@ 2015-02-19 10:06 Tassilo Horn
  2015-02-19 12:35 ` Alexis
  0 siblings, 1 reply; 4+ messages in thread
From: Tassilo Horn @ 2015-02-19 10:06 UTC (permalink / raw)
  To: help-gnu-emacs

Hi all,

I have a wide screen, so I use

  (setq split-width-threshold 152
        split-height-threshold nil)

so that Emacs favors splitting horizontally so that I end up with two
side-by-side windows.  That works ok, but I run into troubles when I
decide to make one of the side-by-side windows dedicated to its buffer.
For example, now I have a buffer for editing a latex document shown in
the left window, and the right window displays the resulting PDF file
and is dedicated to that buffer.

+------------------------------+---------------------------------+
|                              |                                 |
|                              |                                 |
|                              |                                 |
|                              |                                 |
|                              |                                 |
|                              |                                 |
|                              |                                 |
|                              |                                 |
|                              |                                 |
|                              |                                 |
|                              |                                 |
|                              |                                 |
|                              |                                 |
|  latex-file                  |  PDF <dedicated>                |
+------------------------------+---------------------------------+

What I'd like to have now when doing, e.g., `C-h f defun RET' is that
the left window is split vertically, and the *Help* buffer is now shown
in the new, lower-left window.  What actually happens is that the left
window's buffer switches to *Help*.

That might be reasonable but other functions exhibit even stranger
behavior:

  (switch-to-buffer-other-window "*Help*") ;; Pops up a new *frame*
  (pop-to-buffer "*Help*") ;; Swiches buffer in the current window

Especially that `switch-to-buffer-other-window' pops up a new frame (and
I have `pop-up-frames' set to nil) is really annoying.  And I'd usually
expect from `pop-to-buffer' that it creates a new window if there's
enough space (and here the left window is more than 80 lines tall) but
it doesn't.

I think the reason for that inconvenience is that by setting
`split-height-threshold' to nil, I have effectively forbidden
`split-window-sensibly' to perform a vertical split in case there are
more than one window.  Well, that's properly documented, but what
configuration am I supposed to use so that Emacs prefers horizontal
splits if the window to be split is wide enough and falls back to
vertical splitting otherwise?

Currently, the only way I see is to have my own
`split-window-preferred-function' which is exactly like
`split-window-sensibly' but tries horizontal splits first, then vertical
splits, and then the fallback case.  Then I could go with
`split-width-threshold' set to 152 as its now and
`split-height-threshold' set to something like 60 or so.

But since wide displays are so common nowadays, there must be an easy
way to achieve what I'm looking for, no?

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Dedicated window troubles
  2015-02-19 10:06 Dedicated window troubles Tassilo Horn
@ 2015-02-19 12:35 ` Alexis
  2015-02-19 13:26   ` Tassilo Horn
  0 siblings, 1 reply; 4+ messages in thread
From: Alexis @ 2015-02-19 12:35 UTC (permalink / raw)
  To: help-gnu-emacs


On 2015-02-19T21:06:45+1100, Tassilo Horn said:

 TH> But since wide displays are so common nowadays, there must be 
 an TH> easy way to achieve what I'm looking for, no?

Given my own workflow and preferences, i too am very interested
in how to achieve this!


Alexis.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Dedicated window troubles
  2015-02-19 12:35 ` Alexis
@ 2015-02-19 13:26   ` Tassilo Horn
  2015-02-19 13:32     ` Tassilo Horn
  0 siblings, 1 reply; 4+ messages in thread
From: Tassilo Horn @ 2015-02-19 13:26 UTC (permalink / raw)
  To: Alexis; +Cc: help-gnu-emacs

Alexis <flexibeast@gmail.com> writes:

> TH> But since wide displays are so common nowadays, there must be an TH> easy
> way to achieve what I'm looking for, no?
>
> Given my own workflow and preferences, i too am very interested in how
> to achieve this!

FWIW, since nobody replied within 10 minutes, that's what I'm using now:

--8<---------------cut here---------------start------------->8---
(setq split-width-threshold 152
      split-height-threshold 60)

(defun th/split-window-sensibly (&optional window)
  "Split WINDOW in a way suitable for `display-buffer'.
Like `split-window-sensibly' but first try horizontal splits,
then vertical splits, and also try not to split dedicated
windows."
  (let ((window (or (and window (not (window-dedicated-p window)))
		    (selected-window))))
    (or (and (window-splittable-p window t)
	     ;; Split window horizontally.
	     (with-selected-window window
	       (split-window-right)))
	(and (window-splittable-p window)
	     ;; Split window vertically.
	     (with-selected-window window
	       (split-window-below)))
	(and (eq window (frame-root-window (window-frame window)))
	     (not (window-minibuffer-p window))
	     ;; If 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))
	       (when (window-splittable-p window)
		 (with-selected-window window
		   (split-window-below))))))))

(setq split-window-preferred-function #'th/split-window-sensibly)
--8<---------------cut here---------------end--------------->8---

That works fine so far.  I also modified it so that it is less likely to
split dedicated windows.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Dedicated window troubles
  2015-02-19 13:26   ` Tassilo Horn
@ 2015-02-19 13:32     ` Tassilo Horn
  0 siblings, 0 replies; 4+ messages in thread
From: Tassilo Horn @ 2015-02-19 13:32 UTC (permalink / raw)
  To: Alexis; +Cc: help-gnu-emacs

Argh,

never fiddle with code in an email message.  It can only be wrong.  So
here's a corrected version:

--8<---------------cut here---------------start------------->8---
(defun th/split-window-sensibly (&optional window)
  "Split WINDOW in a way suitable for `display-buffer'.
Like `split-window-sensibly' but first try horizontal splits,
then vertical splits, and also try not to split dedicated
windows."
  (let ((window (or (and window (not (window-dedicated-p window)) window)
		    (selected-window))))
    (or (and (window-splittable-p window t)
	     ;; Split window horizontally.
	     (with-selected-window window
	       (split-window-right)))
	(and (window-splittable-p window)
	     ;; Split window vertically.
	     (with-selected-window window
	       (split-window-below)))
	(and (eq window (frame-root-window (window-frame window)))
	     (not (window-minibuffer-p window))
	     ;; If 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))
	       (when (window-splittable-p window)
		 (with-selected-window window
		   (split-window-below))))))))
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-02-19 13:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-19 10:06 Dedicated window troubles Tassilo Horn
2015-02-19 12:35 ` Alexis
2015-02-19 13:26   ` Tassilo Horn
2015-02-19 13:32     ` Tassilo Horn

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.