From 4a1b177bceb7e47ea75ddf779bf609d563713ffe Mon Sep 17 00:00:00 2001 From: Chris Feng Date: Fri, 17 Jun 2016 18:45:34 +0800 Subject: [PATCH] Allow buffer-local simulation keys * exwm-input.el (exwm-input-set-local-simulation-keys): New function for setting buffer-local simulation keys. (exwm-input--local-simulation-keys): New internal variable. (exwm-input--update-simulation-prefix-keys): Modify either `exwm-mode-map' or the local keymap accordingly. --- exwm-input.el | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/exwm-input.el b/exwm-input.el index 4307a187a..e786f0def 100644 --- a/exwm-input.el +++ b/exwm-input.el @@ -453,11 +453,16 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.") ;; (unless (listp last-input-event) ;not a key event ;; (exwm-input--fake-key last-input-event))) +(defvar exwm-input--local-simulation-keys nil + "Whether simulation keys are local.") + (defun exwm-input--update-simulation-prefix-keys () "Update the list of prefix keys of simulation keys." (setq exwm-input--simulation-prefix-keys nil) (dolist (i exwm-input--simulation-keys) - (define-key exwm-mode-map (car i) #'exwm-input-send-simulation-key) + (if exwm-input--local-simulation-keys + (local-set-key (car i) #'exwm-input-send-simulation-key) + (define-key exwm-mode-map (car i) #'exwm-input-send-simulation-key)) (cl-pushnew (elt (car i) 0) exwm-input--simulation-prefix-keys))) (defun exwm-input-set-simulation-keys (simulation-keys) @@ -469,6 +474,16 @@ SIMULATION-KEYS is an alist of the form (original-key . simulated-key)." (cl-pushnew `(,(vconcat (car i)) . ,(cdr i)) exwm-input--simulation-keys)) (exwm-input--update-simulation-prefix-keys)) +(defun exwm-input-set-local-simulation-keys (simulation-keys) + "Set buffer-local simulation keys. + +Its usage is the same with `exwm-input-set-simulation-keys'." + (make-local-variable 'exwm-input--simulation-keys) + (make-local-variable 'exwm-input--simulation-prefix-keys) + (use-local-map (copy-keymap exwm-mode-map)) + (let ((exwm-input--local-simulation-keys t)) + (exwm-input-set-simulation-keys simulation-keys))) + ;;;###autoload (defun exwm-input-send-simulation-key (times) "Fake a key event according to last input key sequence."