emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/exwm a50058b 1/4: Add Customize interface for global ke


From: Chris Feng
Subject: [elpa] externals/exwm a50058b 1/4: Add Customize interface for global keys
Date: Sun, 25 Feb 2018 11:28:23 -0500 (EST)

branch: externals/exwm
commit a50058be786bfa58d24c839dd1c9b9267f10003f
Author: Chris Feng <address@hidden>
Commit: Chris Feng <address@hidden>

    Add Customize interface for global keys
    
    * exwm-input.el (exwm-input--set-key): New function for actually
    setting the binding.
    (exwm-input-global-keys): New user option for customizing global keys.
    (exwm-input-set-key): Update `exwm-input-global-keys' and call
    `exwm-input--set-key'
    (exwm-input--init): Initialize global keys.
---
 exwm-input.el | 39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

diff --git a/exwm-input.el b/exwm-input.el
index ea3d659..edb7eb3 100644
--- a/exwm-input.el
+++ b/exwm-input.el
@@ -464,15 +464,45 @@ ARGS are additional arguments to CALLBACK."
           (xcb:+request exwm--connection req))))
     (xcb:flush exwm--connection)))
 
+(defun exwm-input--set-key (key command)
+  (global-set-key key command)
+  (cl-pushnew key exwm-input--global-keys))
+
+(defcustom exwm-input-global-keys nil
+  "Global keys.
+
+It is an alist of the form (key . command), meaning giving KEY (a key
+sequence) a global binding as COMMAND.
+
+Notes:
+* Setting the value directly (rather than customizing it) after EXWM
+  finishes initialization has no effect."
+  :type '(alist :key-type key-sequence :value-type function)
+  :set (lambda (symbol value)
+         (when (boundp symbol)
+           (dolist (i (symbol-value symbol))
+             (global-unset-key (car i))))
+         (set symbol value)
+         (setq exwm-input--global-keys nil)
+         (dolist (i value)
+           (exwm-input--set-key (car i) (cdr i)))
+         (when exwm--connection
+           (exwm-input--update-global-prefix-keys))))
+
 ;;;###autoload
 (defun exwm-input-set-key (key command)
   "Set a global key binding.
 
 The new key binding only takes effect in real time when this command is
-called interactively.  Only invoke it non-interactively in configuration."
+called interactively, and is lost when this session ends unless it's
+specifically saved in the Customize interface for `exwm-input-global-keys'.
+
+In configuration you should customize or set `exwm-input-global-keys'
+instead."
   (interactive "KSet key globally: \nCSet key %s to command: ")
-  (global-set-key key command)
-  (cl-pushnew key exwm-input--global-keys)
+  (setq exwm-input-global-keys (append exwm-input-global-keys
+                                       (list (cons key command))))
+  (exwm-input--set-key key command)
   (when (called-interactively-p 'any)
     (exwm-input--update-global-prefix-keys)))
 
@@ -871,6 +901,9 @@ Its usage is the same with 
`exwm-input-set-simulation-keys'."
                                          :name-len (length atom)
                                          :name atom))
                       'atom)))
+  ;; Initialize global keys.
+  (dolist (i exwm-input-global-keys)
+    (exwm-input--set-key (car i) (cdr i)))
   ;; Initialize simulation keys.
   (when exwm-input-simulation-keys
     (exwm-input-set-simulation-keys exwm-input-simulation-keys))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]