about summary refs log tree commit diff
path: root/exwm-workspace.el
diff options
context:
space:
mode:
authorAdrián Medraño Calvo <adrian@medranocalvo.com>2016-07-17T12·00+0000
committerAdrián Medraño Calvo <adrian@medranocalvo.com>2016-07-17T12·00+0000
commit2de2d42586a0a8866e7f5447d490a0c345c7ce10 (patch)
treef64979edc552c4af8be5a4eecf08cd4f4f273659 /exwm-workspace.el
parent07120a0562e4a09e189899ef8523aba927cbea0f (diff)
Factor out prompt for workspace
	* exwm-workspace.el (exwm-workspace--prompt-for-workspace): New
	function to interactively ask the user for a workspace.
	(exwm-workspace-switch, exwm-workspace-move-window): Use it.
Diffstat (limited to 'exwm-workspace.el')
-rw-r--r--exwm-workspace.el35
1 files changed, 14 insertions, 21 deletions
diff --git a/exwm-workspace.el b/exwm-workspace.el
index 346e89809e27..21a415eb813e 100644
--- a/exwm-workspace.el
+++ b/exwm-workspace.el
@@ -92,6 +92,18 @@ NIL if FRAME is not a workspace"
 (defvar exwm-workspace--switch-history-outdated nil
   "Non-nil to indicate `exwm-workspace--switch-history' is outdated.")
 
+(defun exwm-workspace--prompt-for-workspace ()
+  "Prompt for a workspace, returning the workspace frame."
+  (exwm-workspace--update-switch-history)
+  (let* ((current-idx (exwm-workspace--position exwm-workspace--current))
+         (history-add-new-input nil)  ;prevent modifying history
+         (history-idx (read-from-minibuffer
+                       "Workspace: " (elt exwm-workspace--switch-history current-idx)
+                       exwm-workspace--switch-map nil
+                       `(exwm-workspace--switch-history . ,(1+ current-idx))))
+         (workspace-idx (cl-position history-idx exwm-workspace--switch-history :test #'equal)))
+    (elt exwm-workspace--list workspace-idx)))
+
 (defun exwm-workspace--update-switch-history ()
   "Update the history for switching workspace to reflect the latest status."
   (when exwm-workspace--switch-history-outdated
@@ -317,15 +329,7 @@ The optional FORCE option is for internal use only."
   (interactive
    (list
     (unless (and (eq major-mode 'exwm-mode) exwm--fullscreen) ;it's invisible
-      (exwm-workspace--update-switch-history)
-      (let* ((current-idx (exwm-workspace--position exwm-workspace--current))
-             (history-add-new-input nil)  ;prevent modifying history
-             (history-idx (read-from-minibuffer
-                           "Workspace: " (elt exwm-workspace--switch-history current-idx)
-                           exwm-workspace--switch-map nil
-                           `(exwm-workspace--switch-history . ,(1+ current-idx))))
-             (workspace-idx (cl-position history-idx exwm-workspace--switch-history :test #'equal)))
-        (elt exwm-workspace--list workspace-idx)))))
+      (exwm-workspace--prompt-for-workspace))))
   (let* ((frame (exwm-workspace--workspace-from-frame-or-index frame-or-index))
          (index (exwm-workspace--position frame))
          (workspace (frame-parameter frame 'exwm-workspace))
@@ -419,18 +423,7 @@ The optional FORCE option is for internal use only."
 ;;;###autoload
 (defun exwm-workspace-move-window (frame-or-index &optional id)
   "Move window ID to workspace FRAME-OR-INDEX."
-  (interactive
-   (list
-    (progn
-      (exwm-workspace--update-switch-history)
-      (let* ((current-idx (exwm-workspace--position exwm-workspace--current))
-             (history-add-new-input nil)  ;prevent modifying history
-             (history-idx (read-from-minibuffer
-                           "Workspace: " (elt exwm-workspace--switch-history current-idx)
-                           exwm-workspace--switch-map nil
-                           `(exwm-workspace--switch-history . ,(1+ current-idx))))
-             (workspace-idx (cl-position history-idx exwm-workspace--switch-history :test #'equal)))
-        (elt exwm-workspace--list workspace-idx)))))
+  (interactive (list (exwm-workspace--prompt-for-workspace)))
   (let ((frame (exwm-workspace--workspace-from-frame-or-index frame-or-index)))
     (unless id (setq id (exwm--buffer->id (window-buffer))))
     (with-current-buffer (exwm--id->buffer id)