Skip to content

Emacs: dedicated windows

Here’s something I had been wanting to do for a long time and could never find the right docs for.

When you perform some operation in Emacs, it often puts stuff (search results, some new buffer, etc.) in a window other than the current one. (I’m using window in the Emacs sense, to mean a portion of what you might call a window but it calls a frame.) But I have a huge Emacs frame, and always want to keep some buffers present in particular positions while rotating the rest of it around. In my case, it’s my org-mode windows, which keep track of most everything about my work day, but you could imagine it being some documentation reference or something. Because I have these buffers up for long stretches of time but rarely actually go to them and edit them, Emacs thinks they’re not important and is happy to reuse their windows when it has new data to display. How to stop it from doing so?

It turns out that what I want is a dedicated window (if I had realized this, I could have found the answer a lot faster). The details are in the Emacs Lisp docs or you can just put this trivial but handy code in your .emacs, and use the Pause key to toggle the dedication of the current window:

(defun toggle-current-window-dedication ()
 (let* ((window    (selected-window))
        (dedicated (window-dedicated-p window)))
   (set-window-dedicated-p window (not dedicated))
   (message "Window %sdedicated to %s"
            (if dedicated "no longer " "")

(global-set-key [pause] 'toggle-current-window-dedication)