From f96f565d548521a87e0f3a23bfab7f5b836e4640 Mon Sep 17 00:00:00 2001 From: Chris Feng Date: Thu, 22 Sep 2016 19:10:38 +0800 Subject: [PATCH] Add support for keyboard macro * exwm-core.el (exwm--kmacro-map): New keymap used when executing keyboard macros. (exwm-mode): Use `exwm--kmacro-map' to override the default keymap. * exwm-input.el (exwm-input--on-KeyPress-line-mode): Send extra key events when defining keyboard macros. --- exwm-core.el | 31 +++++++++++++++++++++++++++++++ exwm-input.el | 6 +++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/exwm-core.el b/exwm-core.el index e65ad51..8f5299f 100644 --- a/exwm-core.el +++ b/exwm-core.el @@ -26,6 +26,8 @@ ;;; Code: +(require 'kmacro) + (require 'xcb) (require 'xcb-icccm) (require 'xcb-ewmh) @@ -78,6 +80,12 @@ (logior xcb:EventMask:StructureNotify xcb:EventMask:PropertyChange)) "Event mask set on all managed windows.") +(defvar exwm-input--during-key-sequence) +(defvar exwm-input--global-prefix-keys) +(defvar exwm-input-prefix-keys) +(defvar exwm-input--simulation-prefix-keys) + +(declare-function exwm-input--fake-key "exwm-input.el" (event)) (declare-function exwm-input--on-KeyPress-line-mode "exwm-input.el" (key-press raw-data)) @@ -140,6 +148,26 @@ map) "Keymap for `exwm-mode'.") +(defvar exwm--kmacro-map + (let ((map (make-sparse-keymap))) + (define-key map [t] + (lambda () + (interactive) + (cond + ((or exwm-input--during-key-sequence + ;; Do not test `exwm-input--during-command'. + (active-minibuffer-window) + (memq last-input-event exwm-input--global-prefix-keys) + (memq last-input-event exwm-input-prefix-keys) + (memq last-input-event exwm-input--simulation-prefix-keys)) + (set-transient-map (make-composed-keymap (list exwm-mode-map + global-map))) + (push last-input-event unread-command-events)) + (t + (exwm-input--fake-key last-input-event))))) + map) + "Keymap used when executing keyboard macros.") + ;; This menu mainly acts as an reminder for users. Thus it should be as ;; detailed as possible, even some entries do not make much sense here. ;; Also, inactive entries should be disabled rather than hidden. @@ -226,6 +254,9 @@ ;; Kill buffer -> close window (add-hook 'kill-buffer-query-functions #'exwm-manage--kill-buffer-query-function nil t) + ;; Redirect events when executing keyboard macros. + (push `(executing-kbd-macro . ,exwm--kmacro-map) + minor-mode-overriding-map-alist) (setq buffer-read-only t left-margin-width nil right-margin-width nil diff --git a/exwm-input.el b/exwm-input.el index dd65b6e..8101cbd 100644 --- a/exwm-input.el +++ b/exwm-input.el @@ -454,7 +454,11 @@ This value should always be overwritten.") :propagate 0 :destination (slot-value key-press 'event) :event-mask xcb:EventMask:NoEvent - :event raw-data)))) + :event raw-data))) + ;; Make Emacs aware of this event when defining keyboard macros. + (when (and defining-kbd-macro event) + (set-transient-map '(keymap (t . (lambda () (interactive))))) + (exwm-input--unread-event event))) (xcb:+request exwm--connection (make-instance 'xcb:AllowEvents :mode mode