about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Feng <chris.w.feng@gmail.com>2018-03-03T17·36+0800
committerChris Feng <chris.w.feng@gmail.com>2018-03-03T17·36+0800
commitcc974555db6056ac799b3ce67234aec4e019cf84 (patch)
tree074fd755aac03201a824ed85fd6c309b66056181
parente141ee684763d93cba02022d76274aeaaba407e5 (diff)
Add prefix arguments support for various commands
* exwm-workspace.el (exwm-workspace-switch)
(exwm-workspace-switch-create, exwm-workspace-move)
(exwm-workspace-move-window): Add prefix arguments support.
-rw-r--r--exwm-workspace.el57
1 files changed, 41 insertions, 16 deletions
diff --git a/exwm-workspace.el b/exwm-workspace.el
index b423b26fe1b8..0651b575d8b4 100644
--- a/exwm-workspace.el
+++ b/exwm-workspace.el
@@ -500,12 +500,18 @@ workspace frame as the first option or making use of the rest options are
 for internal use only."
   (interactive
    (list
-    (unless (and (eq major-mode 'exwm-mode)
-                 ;; The prompt is invisible in fullscreen mode.
-                 (memq xcb:Atom:_NET_WM_STATE_FULLSCREEN exwm--ewmh-state))
-      (let ((exwm-workspace--prompt-add-allowed t)
-            (exwm-workspace--prompt-delete-allowed t))
-        (exwm-workspace--prompt-for-workspace "Switch to [+/-]: ")))))
+    (cond
+     ((null current-prefix-arg)
+      (unless (and (eq major-mode 'exwm-mode)
+                   ;; The prompt is invisible in fullscreen mode.
+                   (memq xcb:Atom:_NET_WM_STATE_FULLSCREEN exwm--ewmh-state))
+        (let ((exwm-workspace--prompt-add-allowed t)
+              (exwm-workspace--prompt-delete-allowed t))
+          (exwm-workspace--prompt-for-workspace "Switch to [+/-]: "))))
+     ((and (integerp current-prefix-arg)
+           (<= 0 current-prefix-arg (exwm-workspace--count)))
+      current-prefix-arg)
+     (t 0))))
   (let* ((frame (exwm-workspace--workspace-from-frame-or-index frame-or-index))
          (old-frame exwm-workspace--current)
          (index (exwm-workspace--position frame))
@@ -600,7 +606,14 @@ for internal use only."
   "Switch to workspace INDEX or creating it first if it does not exist yet.
 
 Passing a workspace frame as the first option is for internal use only."
-  (interactive)
+  (interactive
+   (list
+    (cond
+     ((integerp current-prefix-arg)
+      current-prefix-arg)
+     (t 0))))
+  (unless frame-or-index
+    (setq frame-or-index 0))
   (if (or (framep frame-or-index)
           (< frame-or-index (exwm-workspace--count)))
       (exwm-workspace-switch frame-or-index)
@@ -654,12 +667,18 @@ Passing a workspace frame as the first option is for internal use only."
 When called interactively, prompt for a workspace and move current one just
 before it."
   (interactive
-   (unless (and (eq major-mode 'exwm-mode)
-                ;; The prompt is invisible in fullscreen mode.
-                (memq xcb:Atom:_NET_WM_STATE_FULLSCREEN exwm--ewmh-state))
-     (list exwm-workspace--current
-           (exwm-workspace--position
-            (exwm-workspace--prompt-for-workspace "Move workspace to: ")))))
+   (cond
+    ((null current-prefix-arg)
+     (unless (and (eq major-mode 'exwm-mode)
+                  ;; The prompt is invisible in fullscreen mode.
+                  (memq xcb:Atom:_NET_WM_STATE_FULLSCREEN exwm--ewmh-state))
+       (list exwm-workspace--current
+             (exwm-workspace--position
+              (exwm-workspace--prompt-for-workspace "Move workspace to: ")))))
+    ((and (integerp current-prefix-arg)
+          (<= 0 current-prefix-arg (exwm-workspace--count)))
+     (list exwm-workspace--current current-prefix-arg))
+    (t (list exwm-workspace--current 0))))
   (let ((pos (exwm-workspace--position workspace))
         flag start end index)
     (if (= nth pos)
@@ -723,9 +742,15 @@ INDEX must not exceed the current number of workspaces."
 (defun exwm-workspace-move-window (frame-or-index &optional id)
   "Move window ID to workspace FRAME-OR-INDEX."
   (interactive (list
-                (let ((exwm-workspace--prompt-add-allowed t)
-                      (exwm-workspace--prompt-delete-allowed t))
-                  (exwm-workspace--prompt-for-workspace "Move to [+/-]: "))))
+                (cond
+                 ((null current-prefix-arg)
+                  (let ((exwm-workspace--prompt-add-allowed t)
+                        (exwm-workspace--prompt-delete-allowed t))
+                    (exwm-workspace--prompt-for-workspace "Move to [+/-]: ")))
+                 ((and (integerp current-prefix-arg)
+                       (<= 0 current-prefix-arg (exwm-workspace--count)))
+                  current-prefix-arg)
+                 (t 0))))
   (let ((frame (exwm-workspace--workspace-from-frame-or-index frame-or-index))
         old-frame container)
     (unless id (setq id (exwm--buffer->id (window-buffer))))