help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

undoing define-key


From: jpkotta
Subject: undoing define-key
Date: Tue, 18 Dec 2012 09:46:41 -0800 (PST)
User-agent: G2/1.0

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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]