Simplify key bindings for transient-navigation

Instead of binding each key in the global map, bind it in a map for the
minor mode, so they automatically disappear when the mode is turned off.
This should also prevent the key bindings from taking over in all
buffers.
This commit is contained in:
Tom Willemse 2014-01-01 20:20:29 +01:00
parent 9ca2d33ab7
commit bd71872693

View file

@ -25,9 +25,9 @@
;;; Code: ;;; Code:
(defvar transient-navigation-mode-map (make-sparse-keymap))
(defvar transient-navigation-map (make-sparse-keymap)) (defvar transient-navigation-map (make-sparse-keymap))
(defvar transient-word-navigation-map (make-sparse-keymap)) (defvar transient-word-navigation-map (make-sparse-keymap))
(defvar transient-function-map (make-hash-table))
(defmacro transnav-make-transient (key map func) (defmacro transnav-make-transient (key map func)
"Bind KEY in MAP to FUNC with a transient map." "Bind KEY in MAP to FUNC with a transient map."
@ -40,7 +40,8 @@
(call-interactively #',func) (call-interactively #',func)
(set-transient-map ,map t)) (set-transient-map ,map t))
(define-key ,map (kbd ,key) #',func) (define-key ,map (kbd ,key) #',func)
(setf (gethash ',func transient-function-map) ',funcname)))) (define-key transient-navigation-mode-map
[remap ,func] #',funcname))))
(transnav-make-transient "f" transient-navigation-map forward-char) (transnav-make-transient "f" transient-navigation-map forward-char)
(transnav-make-transient "b" transient-navigation-map backward-char) (transnav-make-transient "b" transient-navigation-map backward-char)
@ -57,15 +58,7 @@
;;;###autoload ;;;###autoload
(define-minor-mode transient-navigation-mode (define-minor-mode transient-navigation-mode
"Remap certain navigation commands to ones with a transient map." "Remap certain navigation commands to ones with a transient map."
nil nil nil nil nil transient-navigation-mode-map)
(if transient-navigation-mode
(maphash (lambda (k v)
(define-key global-map (vector 'remap k) v))
transient-function-map)
(maphash (lambda (k v)
(ignore v)
(define-key global-map (vector 'remap k) nil))
transient-function-map)))
(provide 'transient-navigation) (provide 'transient-navigation)
;;; transient-navigation.el ends here ;;; transient-navigation.el ends here