I am trying to figure out if we can disable a particular window from switching the buffer it contains. If anyone has achieved that please share.


Yes. It's called a dedicated window.

See the Elisp manual, node Dedicated Windows.

C-h f set-window-dedicated-p tells you:

set-window-dedicated-p is a built-in function in C source code.

(set-window-dedicated-p WINDOW FLAG)

Mark WINDOW as dedicated according to FLAG.

WINDOW must be a live window and defaults to the selected one. FLAG non-nil means mark WINDOW as dedicated to its buffer. FLAG nil means mark WINDOW as non-dedicated. Return FLAG.

When a window is dedicated to its buffer, display-buffer will refrain from displaying another buffer in it. get-lru-window and get-largest-window treat dedicated windows specially. delete-windows-on, replace-buffer-in-windows, quit-window, quit-restore-window and kill-buffer can delete a dedicated window and the containing frame.

As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to its buffer. Functions like set-window-buffer may change the buffer displayed by a window, unless that window is strongly dedicated to its buffer. If and when set-window-buffer displays another buffer in a window, it also makes sure that the window is no more dedicated.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.