What I Learned Today

I love emacsclient for opening files in Emacs from the command line, but closing those windows drives me nuts. I expect it just to work like killing any other buffer. With the help of some Googling, I put together this code today to close client buffers by using C-x k.

(defun close-client-window ()
  (interactive)
  (if (y-or-n-p "Close client window? ")
       (server-edit)))

(add-hook 'server-switch-hook 
          (lambda ()
            (when (current-local-map)
              (use-local-map (copy-keymap (current-local-map))))
            (local-set-key (kbd "C-x k") 'close-client-window)))

Published: 09 Dec 2009