unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* undoing define-key
@ 2012-12-18 17:46 jpkotta
  2012-12-19  0:45 ` Stefan Monnier
       [not found] ` <mailman.15643.1355877970.855.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 3+ messages in thread
From: jpkotta @ 2012-12-18 17:46 UTC (permalink / raw)
  To: help-gnu-emacs

How can I unbind a key in a keymap such that it acts like it was never defined?  The docs make it sound like binding to nil, e.g. (define-key map (kbd "<key>") nil), will do what I want, but it doesn't.

Example (works with emacs -q):

(define-minor-mode foo-mode
  :global t
  :keymap (let ((map (make-sparse-keymap)))
            (define-key map (kbd "M-j") 'left-char)
            (define-key map (kbd "M-k") 'next-line)
            (define-key map (kbd "M-l") 'right-char)
            (define-key map (kbd "M-i") 'previous-line)
            map)
  )
(foo-mode 1)

;; Now M-[ijkl] act like the arrow keys
;; I can do an isearch and they will exit the search just like the arrows

(define-key isearch-mode-map (kbd "M-j") nil)

;; Now M-j does not exit isearch, and it behaves like whatever it was bound to outside of foo-mode.  M-j still does left-char outside of isearch-mode.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-12-19 16:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-18 17:46 undoing define-key jpkotta
2012-12-19  0:45 ` Stefan Monnier
     [not found] ` <mailman.15643.1355877970.855.help-gnu-emacs@gnu.org>
2012-12-19 16:05   ` jpkotta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).