2024-07-13 Dedicated windows

There are some features of Emacs which you can read about in the manual and go “huh? what is that about? who’d ever need it?”, and then later turn out to need exactly them.

Recently I learned that dedicated windows are just like that. I generally tend to stay away from configuring display-buffer, which is famously flexible but infamously complex. If I really want my window configuration not to disappear, I store it in a register.

A few days ago, however, I learned a new trick (which is in fact new, in the sense that you need to be on master to use it – it will become available in Emacs 30). You can press C-x w d in a window and that window becomes dedicated to the buffer it is displaying. (Note: dedicated windows have been in Emacs for quite some time IIRC, but there was no UI for making a window dedicated.)

The precise meaning and behavior of deidacted windows seems a bit complex, but the main idea is that Emacs generally won’t reuse a dedicated window for anything unless explicitly told to. Here is my use-case. Imagine you are studying a book (in a pdf file, using pdf-tools, or in and epub file, using nov.el). Since the book is a technical manual or textbook, you want to try out code snippets while reading, so you open two side-by-side windows – one with the book itself and one with an Org file with your notes. You put the code snippets in source blocks – but then, when you run the code snippet and something is wrong, a buffer with the error shows in place of the book, which is not very nice.

Now, if you make the window displaying the book dedicated (and it will be possible with C-x w d in Emacs 30), this won’t happen anymore! Now the error buffer is shown in another window, and you book will be still visible. You can also make a window strongly dedicated, which means Emacs won’t let you change the buffer when inside that window.

This is still not ideal – for example, org-edit-special (C-c ') doesn’t seem to respect the “dedicated” status – but it is a big help. From now on I will try to remember to use C-x w d in this situation (and perhaps a few others), when I want some window to show a given buffer all (or at least most) of the time without Emacs suddenly deciding to show something else there.

CategoryEnglish, CategoryBlog, CategoryEmacs