Any way to prevent window splits for a window or a major-mode

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Any way to prevent window splits for a window or a major-mode

Robert Weiner-2
I have looked through the Windows sections of the Elisp manual but did not see an option that would do this specifically, though I imagine it must be there.

For a window, I would like to be able to mark it so it is never split.
For a major mode, I would like to say for any windows displaying buffers in this major mode, don't split them.

Is there a simple way to program that?

Thanks,

Bob

Reply | Threaded
Open this post in threaded view
|

Re: Any way to prevent window splits for a window or a major-mode

Eric Abrahamsen-2
Robert Weiner <[hidden email]> writes:

> I have looked through the Windows sections of the Elisp manual but did not see an option that would do this specifically, though I imagine it must be there.
>
> For a window, I would like to be able to mark it so it is never split.
> For a major mode, I would like to say for any windows displaying buffers in this major mode, don't split them.
>
> Is there a simple way to program that?

You might look at the Atomic Windows and Preserving Window Sizes
sections of the manual. My guess is something in there would do it.

Yours,
Eric


Reply | Threaded
Open this post in threaded view
|

RE: Any way to prevent window splits for a window or a major-mode

Drew Adams
In reply to this post by Robert Weiner-2
> I have looked through the Windows sections of the Elisp
> manual but did not see an option that would do this
> specifically, though I imagine it must be there.
>
> For a window, I would like to be able to mark it so it
> is never split.
>
> For a major mode, I would like to say for any windows
> displaying buffers in this major mode, don't split them.
>
> Is there a simple way to program that?

I'm no expert on this.  I just took a look at predicate
`window-splittable-p', and a first impression tells me
that you can set `window-size-fixed' to `t' in a given
buffer/mode to make it unsplittable.  But it apparently
applies to all windows showing the buffer, and I see no
way to apply that to a single window.

I see too (in (elisp) `Splitting Windows') that there is
window parameter `split-window', which it seems like
you can use to prevent a given window from being split.

Someone more familiar with this stuff will hopefully
chime in.

Reply | Threaded
Open this post in threaded view
|

Re: Any way to prevent window splits for a window or a major-mode

martin rudalics
In reply to this post by Robert Weiner-2
 > For a window, I would like to be able to mark it so it is never split.

The most simple approach is the one Drew mentioned, something like

(set-window-parameter nil 'split-window #'ignore)

for the selected window.  But this might be too strong with functions
(like `display-buffer') that expect a window to be splittable if it's
just large enough.  So fixing the window size by setting its buffer's
`window-size-fixed' variable or the window's 'window-preserved-size'
parameter as Eric suggested could be more appropriate.  But maybe you
should tell us more about the case where you need such a property -
`split-window' is just the Emacs paradigm for creating a new window
adjacent to an existing one.

 > For a major mode, I would like to say for any windows displaying buffers in
 > this major mode, don't split them.
 >
 > Is there a simple way to program that?

You will have to put a function on `window-configuration-change-hook'
which runs through every window and, if it displays a buffer in that
major mode, sets the 'split-window' parameter of that window to 'ignore'
or preserves that window's size.  And obviously the major mode hook
would have to add/remove that parameter for every window showing a
buffer where that mode is turned on/off.

martin

Reply | Threaded
Open this post in threaded view
|

Re: Any way to prevent window splits for a window or a major-mode

Robert Weiner-2
>  But maybe you should tell us more about the case where you need such a property -
> `split-window' is just the Emacs paradigm for creating a new window adjacent to an
> existing one.

​The Treemacs package displays a full-frame height window at
the left of the frame that can be used to browse directories
in an outline fashion.  It has some features that make it
attractive at times beyond just using Dired (it also can be
used in tandem with Dired).

Treemacs uses treemacs-mode for its buffers.  So I want any
window with a buffer in that mode to be non-splittable since
it is narrow and it doesn't make sense to split it in either
dimension.

Thanks for the initial pointers.  Martin's pointers sound
promising.

Bob


Reply | Threaded
Open this post in threaded view
|

Re: Any way to prevent window splits for a window or a major-mode

martin rudalics
 > ​The Treemacs package displays a full-frame height window at
 > the left of the frame that can be used to browse directories
 > in an outline fashion.  It has some features that make it
 > attractive at times beyond just using Dired (it also can be
 > used in tandem with Dired).
 >
 > Treemacs uses treemacs-mode for its buffers.  So I want any
 > window with a buffer in that mode to be non-splittable since
 > it is narrow and it doesn't make sense to split it in either
 > dimension.

You might consider two opportunities here: If the treemacs window is
"frame bound", then it's probably best to make it a side window so that
C-x 1 does not delete it and it does not become the sole window of the
frame.  If the treemacs window is "window bound" (so that two or more
treemacs windows may appear simultaneously on a frame), it might be
better to attach the treemacs window to some other "normal" window and
make these two windows atomic.

martin


Reply | Threaded
Open this post in threaded view
|

Re: Any way to prevent window splits for a window or a major-mode

Robert Weiner-2
On Tue, Dec 5, 2017 at 3:53 AM, martin rudalics <[hidden email]> wrote:
> ​The Treemacs package displays a full-frame height window at
> the left of the frame that can be used to browse directories
> in an outline fashion.  It has some features that make it
> attractive at times beyond just using Dired (it also can be
> used in tandem with Dired).
>
> Treemacs uses treemacs-mode for its buffers.  So I want any
> window with a buffer in that mode to be non-splittable since
> it is narrow and it doesn't make sense to split it in either
> dimension.

You might consider two opportunities here: If the treemacs window is
"frame bound", then it's probably best to make it a side window so that
C-x 1 does not delete it and it does not become the sole window of the
frame.
​​

​It is frame-bound.  I tested display-buffer-in-side-window
and that did the trick.  Thanks.  Is set-window-dedicate-p
also needed or does the side window setup take care of that?

If you don't want delete-other-windows to delete this window,
then also add:

(set-window-parameter (selected-window) 'no-delete-other-windows t)

Bob

Reply | Threaded
Open this post in threaded view
|

Re: Any way to prevent window splits for a window or a major-mode

Robert Weiner-2
In reply to this post by Robert Weiner-2
On Fri, Dec 1, 2017 at 4:35 PM, Robert Weiner <[hidden email]> wrote:
I have looked through the Windows sections of the Elisp manual but did not see an option that would do this specifically

​Now that we have resolved this issue by utilizing display-buffer-in-side-window, I went back to the Elisp manual to see why I did not
find this.  I was looking for information related to preserving the display of a window and window splitting.  That led me to
both the sections on "Preserving Window Sizes" and "Splitting Windows" neither of which have references to the sections on
Side Windows or Atomic Windows.

The last two paragraphs in the "Displaying Buffers in Side Windows" section are key to understanding that one would want
to use a side window when a non-splittable window is desired.  I think a mention of that (and/or link) should be added near the
beginning of the "Splitting Windows" section.  It might save others a lot of time.

Regards,

Bob
Reply | Threaded
Open this post in threaded view
|

Re: Any way to prevent window splits for a window or a major-mode

martin rudalics
In reply to this post by Robert Weiner-2
 > ​It is frame-bound.  I tested display-buffer-in-side-window
 > and that did the trick.  Thanks.  Is set-window-dedicate-p
 > also needed or does the side window setup take care of that?

`set-window-dedicated-p' (with a "d") is not needed.  Another buffer may
appear in this window if and only if it has been set up to use the same
side and slot.

 > If you don't want delete-other-windows to delete this window,
 > then also add:
 >
 > (set-window-parameter (selected-window) 'no-delete-other-windows t)

Indeed, see Bug#27999.

martin


Reply | Threaded
Open this post in threaded view
|

Re: Any way to prevent window splits for a window or a major-mode

martin rudalics
In reply to this post by Robert Weiner-2
 > The last two paragraphs in the "Displaying Buffers in Side Windows" section
 > are key to understanding that one would want
 > to use a side window when a non-splittable window is desired.  I think a
 > mention of that (and/or link) should be added near the
 > beginning of the "Splitting Windows" section.  It might save others a lot
 > of time.

I added such links now.  However, keep in mind that due to its anarchic
nature Emacs will never allow to disallow splitting an existing window.
Categorically, at least.

martin

Reply | Threaded
Open this post in threaded view
|

Re: Any way to prevent window splits for a window or a major-mode

Robert Weiner-2
In reply to this post by martin rudalics
On Wed, Dec 6, 2017 at 3:56 AM, martin rudalics <[hidden email]> wrote:
> ​It is frame-bound.  I tested display-buffer-in-side-window
> and that did the trick.  Thanks.  Is set-window-dedicate-p
> also needed or does the side window setup take care of that?

`set-window-dedicated-p' (with a "d") is not needed.  Another buffer may
appear in this window if and only if it has been set up to use the same
side and slot.

​Great.

In the doc string for display-buffer-in-side-window, it says: "Unless ‘display-buffer-mark-dedicated’ is non-nil, softly
dedicate the side window used to BUFFER."

No one will know what 'softly dedicate' means.  If it means what you said above, that should be explained in the doc string too.
​​

​​

​​
> If you don't want delete-other-windows to delete this window,
​​
> then also add:
​​
>
​​
> (set-window-parameter (selected-window) 'no-delete-other-windows t)
​​

​​
Indeed, see Bug#27999.

​Thanks for the pointer to some of the thinking that went into the design of the side window feature.
It is working well for me in use with the Treemacs package.

Bob

Reply | Threaded
Open this post in threaded view
|

Re: Any way to prevent window splits for a window or a major-mode

Richard Stallman
In reply to this post by Robert Weiner-2
[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

In general, the Emacs facilities for controlling which windows can be split
need to be smarter.

--
Dr Richard Stallman
President, Free Software Foundation (https://gnu.org, https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)
Skype: No way! See https://stallman.org/skype.html.


Reply | Threaded
Open this post in threaded view
|

Re: Any way to prevent window splits for a window or a major-mode

martin rudalics
In reply to this post by Robert Weiner-2
 >> `set-window-dedicated-p' (with a "d") is not needed.  Another buffer may
 >> appear in this window if and only if it has been set up to use the same
 >> side and slot.
 >
 >
 > ​Great.
 >
 > In the doc string for display-buffer-in-side-window, it says: "Unless
 > ‘display-buffer-mark-dedicated’ is non-nil, softly
 > dedicate the side window used to BUFFER."
 >
 > No one will know what 'softly dedicate' means.  If it means what you said
 > above, that should be explained in the doc string too.

It doesn't mean what I said above.  Setting the window's dedicated flag
makes sure that no other action functions reuse that window.

I hopefully managed to clarify the doc-string now.

Many thanks for your careful reading of doc and doc-strings, martin