Discussion:
Any way to prevent window splits for a window or a major-mode
Robert Weiner
2017-12-01 21:35:06 UTC
Permalink
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
Eric Abrahamsen
2017-12-01 21:40:14 UTC
Permalink
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
Drew Adams
2017-12-01 21:57:38 UTC
Permalink
Post by Robert Weiner
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.
martin rudalics
2017-12-02 10:17:05 UTC
Permalink
Post by Robert Weiner
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.
Post by Robert Weiner
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
Robert Weiner
2017-12-04 13:44:35 UTC
Permalink
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
martin rudalics
2017-12-05 08:53:38 UTC
Permalink
​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
Robert Weiner
2017-12-05 17:04:51 UTC
Permalink
Post by martin rudalics
Post by Robert Weiner
​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
martin rudalics
2017-12-06 08:56:35 UTC
Permalink
​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,
(set-window-parameter (selected-window) 'no-delete-other-windows t)
Indeed, see Bug#27999.

martin
Robert Weiner
2017-12-06 15:44:03 UTC
Permalink
Post by martin rudalics
Post by Robert Weiner
​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.
​
Post by martin rudalics
​​
​​
​​
Post by Robert Weiner
If you don't want delete-other-windows to delete this window,
​​
​​
​​
Post by Robert Weiner
(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
martin rudalics
2017-12-07 09:27:29 UTC
Permalink
Post by martin rudalics
`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
Robert Weiner
2017-12-05 22:45:26 UTC
Permalink
Post by Robert Weiner
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
martin rudalics
2017-12-06 08:56:52 UTC
Permalink
Post by Robert Weiner
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
Richard Stallman
2017-12-06 18:11:52 UTC
Permalink
[[[ 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.
Continue reading on narkive:
Loading...