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.
This commit is contained in:
parent
515f65df7d
commit
9ca2d33ab7
1 changed files with 21 additions and 18 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue