How can I force Emacs to keep a certain file in a particular window? For example, if I am editing a LaTeX file and there is a compile error, I want to inspect the error in another window. I essentially want to "freeze" a file in a window until I explicitly delete the window.

The expected behavior would also open up new files with C-x C-f in a different window, even if the command was initiated in my "frozen" window. Is there a way to do this?

What I want to do is something like this:

  1. With two windows open, use one to edit a file.
  2. With some command, freeze that window so that it always displays the file that I have just opened.
  3. In the "frozen" window, execute a command such as find-file (C-x C-f) to open a new file. This should open the file in the other window.
  • 1
    This is not clear, probably because you don't use the right terminology. Maybe you mean "window" instead of "buffer"? Providing a more extended explanation and an example of exactly what you are doing, what you see and what you would like to see instead, might help.
    – NickD
    Jan 31 at 16:20
  • 1
    The question only makes sense if you assume that they meant window.
    – db48x
    Jan 31 at 16:25
  • What @NickD said. I suspect that making the buffer's window dedicated is what you're looking for. That prevents other buffers from being displayed in that window. (set-window-dedicated-p (get-buffer-window) t)
    – Drew
    Jan 31 at 16:26
  • 1
    Edited to use the correct terminology Jan 31 at 16:31

1 Answer 1


Guessing you meant window instead of buffer... Do this when the file's buffer is current:

(set-window-dedicated-p (get-buffer-window) t)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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