protecting an emacs buffer window from being split or replaced...

i’m a big fan of IRC and we use it in our distributed team to stay in touch and also coordinate testing and upgrades. as i’m also a big fan of the ur-IDE emacs i’m using emacs’s rcirc mode for my IRC needs. typically i have a small buffer window at the bottom of my emacs frame dedicated to IRC. quite nice…

…until you start sbt or do some git work in egg as then those modes try to acquire some screen real-estate and without scruples either “recycle” my IRC buffer for their content :-( or split it into two :-(

this being emacs there had to be a way to get that IRC buffer window protected. and there is :-) digging into the emacs info docs and looking at the underlying emacs lisp files this is what i came up with:

 [sourcecode language="text"]
 (defun rcirc-toggle-current-window-dedication ()
   (let* ((window (selected-window))
          (dedicated (window-dedicated-p window)))
     (set-window-dedicated-p window (not dedicated))
     (setq window-size-fixed (not window-size-fixed))
     (message "Window %sdedicated to %s"
              (if dedicated "no longer " "")

 (global-set-key (kbd "<Scroll_Lock>") 'rcirc-toggle-current-window-dedication)

this will toggle the window-dedicated-p and window-size-fixed bits of the window in which you press the scroll-lock key — and, hey, presto! — no more pirating of the IRC buffer window.