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 ()
(interactive)
(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 " "")
(buffer-name))))
(global-set-key [pause] 'toggle-current-window-dedication)
Tags: emacs
May 2nd, 2010 at 7:11 pm
Thanks for the snippet, Dan!
June 1st, 2010 at 7:16 pm
Thanks for this. Solved my problem. Emacs looks more palatable now.
November 18th, 2010 at 8:01 am
Thanks, Dan. This is just what I was looking for.
April 27th, 2011 at 12:02 am
[...] simple Google search resulted in a more concise solution, but I’m really happy that I was able to figure things out on my own and write the function. [...]
September 26th, 2011 at 12:56 pm
Props, dear emacs comrade.