title: in Emacs, what's the best way for keyboard-escape-quit not destroy other windows?
body: <p><strong>EDIT:</strong> I understand there is keyboard-quit (which is normally bound to C-g); but I'm more interested to know about how one deals with editing functions that come with Emacs (like in this case). I run into this kind of situations from time to time when I want to change just a little bit of some build-in functions.</p>
  
  <p>In emacs, when you hit M-ESC ESC (or ESC three times), you can get out of a lots of situations like transient-mark, etc. But I habitually hit the escape key (I actually remap this to a single hit of the escape key) more than I intended, and that ends up killing my windows configuration, which is quite annoying. The function  keyboard-escape-quit is defined in simple.el:</p>
  
  <pre><code>(defun keyboard-escape-quit ()
    "Exit the current \"mode\" (in a generalized sense of the word).
  This command can exit an interactive command such as `query-replace',
  can clear out a prefix argument or a region,
  can get out of the minibuffer or other recursive edit,
  cancel the use of the current buffer (for special-purpose buffers),
  or go back to just one window (by deleting all but the selected window)."
    (interactive)
    (cond ((eq last-command 'mode-exited) nil)
      ((&gt; (minibuffer-depth) 0)
       (abort-recursive-edit))
      (current-prefix-arg
       nil)
      ((and transient-mark-mode mark-active)
       (deactivate-mark))
      ((&gt; (recursion-depth) 0)
       (exit-recursive-edit))
      (buffer-quit-function
       (funcall buffer-quit-function))
      ((not (one-window-p t))
       (delete-other-windows))
      ((string-match "^ \\*" (buffer-name (current-buffer)))
       (bury-buffer))))
  </code></pre>
  
  <p>And I can see that I don't want the lines:</p>
  
  <pre><code>    ((not (one-window-p t))
       (delete-other-windows))
  </code></pre>
  
  <p>But what is the best way to modify this function? I can see only two ways: 1) modify simple.el 2) copy this function to my .emacs file and do the modifications there. Both ways are not really <em>good</em>; ideally I would like to see something on the line of defadvice, but I can't see how I can do it in this case.</p>