chewy959 · 2022-08-04 04:38
I have a question in regards to buffers when using multiple windows. Let's say I have my frame split into 2 windows. Then, I have *Buffer A* displaying in Window 1. If I were to open *Buffer A* in Window 2, I am able to do so with no change to Window 1, etc.
This could be a odd late night thought, but is there a way to make *Buffer A* only displayed in one Window at a time? In my above example, Window 2 currently would display *Buffer A* and so would Window 1. I want Window 1 to display *something else,* perhaps another buffer I have opened or even some default value when *Buffer A* is opened in Window 2.
Thanks in Advance.
\~ Chewy959
Salvarath · 2022-08-04 08:19
It’s late but I’ll give you some stuff to get the ball rolling.
Display buffer alist - allows user to control how and where the buffer is displayed. There are lots of options. I believe there is even a dedicated option where you can dedicate a buffer to a window. There are also other buffer displaying related things in the docs that you’ll find and more ways of doing things but this should put you in the right direction.
Indirect buffers - allows two buffers to share the same text. Additionally these two buffers although sharing the same text are entirely separate meaning they do not need to be in the same mode, have the same name, share variables or the point. Therefore you can make all kinds of custom viewers or editors for a given buffer. For example, a read only view, an org mode table of content of sorts, multiple “granularity” views of an outline, etc.
side windows - there are also four dedicated windows in the top, bottom, and sides of the eMacs frame I’ve been meaning to mess with. I’ve been considering dedicating a buffer to a certain side window and keeping it open always and toggling it with a custom bind. I don’t believe eMacs puts things there by default so using that could prevent things from taking over your window without setting up custom buffer displaying rules.
Edit: Just found [this](https://www.reddit.com/r/emacs/comments/i8ypjw/display_buffer_bottom/g1d508w/?utm_source=share&utm_medium=ios_app&utm_name=iossmf&context=3) about switching buffers respecting display buffer alist. Also [this](https://www.reddit.com/r/emacs/comments/tvfneo/creating_a_toggleable_left_hand_sidebar_of/i3c6t9w/?utm_source=share&utm_medium=ios_app&utm_name=iossmf&context=3) comment shows how to make a dedicated side window buffer that won’t be used by others.
I hope that helps.
[deleted] · 2022-08-04 09:27
[deleted]
arthurno1 · 2022-08-04 11:12
> I want Window 1 to display something else, perhaps another buffer I have opened or even some default value when Buffer A is opened in Window 2.
You could do this easily with some simple lisp coding. For example, you may advise splitting function to open the previous buffer in the list or whichever choice of yours you think would be useful to you in most cases. But you are really fighting Emacs for no good reason here.
I am not sure, but what I believe is your consideration here, is when you split a window (regardless of split), Emacs displays the same buffer in both the old window and new split. This behavior is simply a result of Emacs not knowing what to display after the split.
I don't think there is any meaningful strategy that would please and work for everyone in every situation. In such case, it is probably better to do what Emacs does - nothing and let user take further action, i.e. navigate in which window you want to whichever buffer you want.
Edit: I quoted wrong sentence when I posted it, didn't notice.
_viz_ · 2022-08-04 12:22
If you set the dedicated flag in window 1 (see set-window-dedicated-p), then you can't change its buffer further. However, I don't think there's a way to disallow setting window 2's buffer to buffer A. I would suggest you to skim through the Windows section in the Elisp manual: (info "(elisp) Windows").
00-11 · 2022-08-04 15:38
Setting the dedicated flag to `t` does what you say: you can't show a different buffer in that window. Setting it to another non-`nil` value doesn't do that. See (elisp) [Dedicated Windows](https://www.gnu.org/software/emacs/manual/html_node/elisp/Dedicated-Windows.html).
arthurno1 · 2022-08-04 18:12
> However, I don't think there's a way to disallow setting window 2's buffer to buffer A.
That is correct, there is not. It would be possible, relatively easily, to build one - I say easy, but I haven't tried :). However, I wonder what would be the use-case for such a rule? The case Op describes does not need "exclusive right" to just one window at all, and is solvable without "exclusiveness".