about summary refs log tree commit diff
path: root/exwm-workspace.el
diff options
context:
space:
mode:
authorChris Feng <chris.w.feng@gmail.com>2019-03-17T00·00+0000
committerChris Feng <chris.w.feng@gmail.com>2019-03-17T00·00+0000
commitdd96fffb52a4e7e5b506b28881b518b0359375c4 (patch)
treef03e757be6c5e20783203e928eac75b8b78b3598 /exwm-workspace.el
parentb12c67de2ed10e2528b1c494aa08d51b43e563dd (diff)
Add extra keys for selecting workspace
* exwm-workspace.el (exwm-workspace--switch-map)
(exwm-workspace--init): Avoid initializing the keymap when loading.
(exwm-workspace--init-switch-map): Initialize
`exwm-workspace--switch-map' and also add extra keybindings when
`exwm-workspace-index-map' has been customized.
Diffstat (limited to 'exwm-workspace.el')
-rw-r--r--exwm-workspace.el20
1 files changed, 17 insertions, 3 deletions
diff --git a/exwm-workspace.el b/exwm-workspace.el
index 783287366a..f6b8fbac06 100644
--- a/exwm-workspace.el
+++ b/exwm-workspace.el
@@ -157,7 +157,10 @@ NIL if FRAME is not a workspace"
   "Return non-nil if FRAME is an emacsclient frame."
   (frame-parameter frame 'client))
 
-(defvar exwm-workspace--switch-map
+(defvar exwm-workspace--switch-map nil
+  "Keymap used for interactively selecting workspace.")
+
+(defun exwm-workspace--init-switch-map ()
   (let ((map (make-sparse-keymap)))
     (define-key map [t] (lambda () (interactive)))
     (define-key map "+" #'exwm-workspace--prompt-add)
@@ -165,6 +168,17 @@ NIL if FRAME is not a workspace"
     (dotimes (i 10)
       (define-key map (int-to-string i)
         #'exwm-workspace--switch-map-nth-prefix))
+    (unless (eq exwm-workspace-index-map #'number-to-string)
+      ;; Add extra (and possibly override) keys for selecting workspace.
+      (dotimes (i 10)
+        (let ((key (funcall exwm-workspace-index-map i)))
+          (when (and (stringp key)
+                     (= (length key) 1)
+                     (<= 0 (elt key 0) 127))
+            (define-key map key
+              `(lambda ()
+                 (interactive)
+                 (exwm-workspace--switch-map-select-nth ,i)))))))
     (define-key map "\C-a" (lambda () (interactive) (goto-history-element 1)))
     (define-key map "\C-e" (lambda ()
                              (interactive)
@@ -180,8 +194,7 @@ NIL if FRAME is not a workspace"
     ;; Alternative keys
     (define-key map [right] #'previous-history-element)
     (define-key map [left] #'next-history-element)
-    map)
-  "Keymap used for interactively switch workspace.")
+    (setq exwm-workspace--switch-map map)))
 
 (defun exwm-workspace--workspace-from-frame-or-index (frame-or-index)
   "Retrieve the workspace frame from FRAME-OR-INDEX."
@@ -1557,6 +1570,7 @@ applied to all subsequently created X frames."
 (defun exwm-workspace--init ()
   "Initialize workspace module."
   (exwm--log)
+  (exwm-workspace--init-switch-map)
   ;; Prevent unexpected exit
   (setq exwm-workspace--fullscreen-frame-count 0)
   (exwm-workspace--modify-all-x-frames-parameters