aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2014-01-01 20:13:51 +0100
committerGravatar Tom Willemse2014-01-01 20:13:51 +0100
commit9ca2d33ab71c600cc8cba52af0b8bf087cdcb309 (patch)
treee6f6c24be83af5146eb11002f11c18ac83259427
parent515f65df7d90928c623ea43c8a7233621714c1a3 (diff)
downloadtransient-navigation-9ca2d33ab71c600cc8cba52af0b8bf087cdcb309.tar.gz
transient-navigation-9ca2d33ab71c600cc8cba52af0b8bf087cdcb309.zip
Add another keymap, simplify mode en-/disabling
The new keymap is based on some `M-' keybindings. Instead of specifying each keybinding to enable or disable by hand, map through a new hashtable which contains function->wrapper mappings.
-rw-r--r--transient-navigation.el39
1 files changed, 21 insertions, 18 deletions
diff --git a/transient-navigation.el b/transient-navigation.el
index fb94ad2..b11d7a2 100644
--- a/transient-navigation.el
+++ b/transient-navigation.el
@@ -26,17 +26,21 @@
;;; Code:
(defvar transient-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)
"Bind KEY in MAP to FUNC with a transient map."
- (let ((funcname (intern (concat "transient-" (symbol-name func)))))
+ (let* ((ofuncname (symbol-name func))
+ (funcname (intern (concat "transient-" ofuncname))))
`(progn
- (defun ,funcname (&optional n)
+ (defun ,funcname (&rest args)
(interactive)
- (ignore n)
+ (ignore args)
(call-interactively #',func)
- (set-transient-map transient-navigation-map t))
- (define-key ,map (kbd ,key) #',funcname))))
+ (set-transient-map ,map t))
+ (define-key ,map (kbd ,key) #',func)
+ (setf (gethash ',func transient-function-map) ',funcname))))
(transnav-make-transient "f" transient-navigation-map forward-char)
(transnav-make-transient "b" transient-navigation-map backward-char)
@@ -45,24 +49,23 @@
(transnav-make-transient "e" transient-navigation-map end-of-line)
(transnav-make-transient "a" transient-navigation-map beginning-of-line)
+(transnav-make-transient "f" transient-word-navigation-map forward-word)
+(transnav-make-transient "b" transient-word-navigation-map backward-word)
+(transnav-make-transient "e" transient-word-navigation-map forward-sentence)
+(transnav-make-transient "a" transient-word-navigation-map backward-sentence)
+
;;;###autoload
(define-minor-mode transient-navigation-mode
"Remap certain navigation commands to ones with a transient map."
nil nil nil
(if transient-navigation-mode
- (progn
- (define-key global-map [remap forward-char] #'transient-forward-char)
- (define-key global-map [remap backward-char] #'transient-backward-char)
- (define-key global-map [remap next-line] #'transient-next-line)
- (define-key global-map [remap previous-line] #'transient-previous-line)
- (define-key global-map [remap end-of-line] #'transient-end-of-line)
- (define-key global-map [remap beginning-of-line] #'transient-beginning-of-line))
- (define-key global-map [remap transient-forward-char] #'forward-char)
- (define-key global-map [remap transient-backward-char] #'backward-char)
- (define-key global-map [remap transient-next-line] #'next-line)
- (define-key global-map [remap transient-previous-line] #'previous-line)
- (define-key global-map [remap transient-end-of-line] #'end-of-line)
- (define-key global-map [remap transient-beginning-of-line] #'beginning-of-line)))
+ (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)
;;; transient-navigation.el ends here