Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to make Emacs not just bury a buffer but kill it too when I press q in a *Completions*/*Help*/etc buffer. I can't get the substitute-key-definition function to work. I'm running Emacs24 on OSX.

Here's what I have:

        'quit-window '(lambda () (interactive) (quit-window "KILL")) global-map)
share|improve this question
Have you got any particular reason for also wanting to kill it? – N.N. Mar 7 '12 at 17:13
@N.N E.g. once i've seen a completion i dont need it to be still open after quitting the window its in. – bneil Mar 7 '12 at 21:09
up vote 5 down vote accepted

The other answer actually gives slightly incompatible behavior. Consider a situation where you already have a frame split into two windows, then you open a help buffer and quit it. quit-window is smart enough to know that it shouldn't kill the window, just the buffer. It actually even has a few more clever tricks up its sleeve so our best bet is to work with it and just tweak it a bit. Here's a simple way of achieving what you want:

(defadvice quit-window (before quit-window-always-kill)
  "When running `quit-window', always kill the buffer."
  (ad-set-arg 0 t))
(ad-activate 'quit-window)
share|improve this answer

Just redefining the function seemed to have worked for me ie

(defun quit-window () 
 "modified quit window"

I've never understood the purpose of having a completion or help buffer still available when you are switching buffers after you pressed q to quit it previously.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .