From dd004dea79ffb3be7a26585c9bbc529f83b48593 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 1 Dec 2019 15:02:38 +0700 Subject: [PATCH 1/3] Easier creation of named workspaces When a user tries to switch to a named workspace that doesn't exist, creat it, instead of just failing. Signed-off-by: Rudi Grinberg --- modules/ui/workspaces/autoload/workspaces.el | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/ui/workspaces/autoload/workspaces.el b/modules/ui/workspaces/autoload/workspaces.el index 7821c19af..be87f477a 100644 --- a/modules/ui/workspaces/autoload/workspaces.el +++ b/modules/ui/workspaces/autoload/workspaces.el @@ -318,9 +318,7 @@ end of the workspace list." (error "No workspace at #%s" (1+ index))) (+workspace-switch dest))) ((stringp index) - (unless (member index names) - (error "No workspace named %s" index)) - (+workspace-switch index)) + (+workspace-switch index t)) (t (error "Not a valid index: %s" index))) (unless (called-interactively-p 'interactive) From 4b77b413c59dead37cdfafc0ef43d88f68d94c53 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 1 Dec 2019 16:13:40 +0700 Subject: [PATCH 2/3] Add ivy command for workspace switching --- modules/ui/workspaces/autoload/workspaces.el | 31 +++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/modules/ui/workspaces/autoload/workspaces.el b/modules/ui/workspaces/autoload/workspaces.el index be87f477a..438962e14 100644 --- a/modules/ui/workspaces/autoload/workspaces.el +++ b/modules/ui/workspaces/autoload/workspaces.el @@ -299,13 +299,10 @@ workspace, otherwise the new workspace is blank." (+workspace/display))) ((debug error) (+workspace-error (cadr e) t)))) -;;;###autoload -(defun +workspace/switch-to (index) - "Switch to a workspace at a given INDEX. A negative number will start from the -end of the workspace list." - (interactive - (list (or current-prefix-arg - (completing-read "Switch to workspace: " (+workspace-list-names))))) + +(defun +workspace--switch-to (index &optional skip-warnings) + "Generic workspace switching action. It is used by both the ivy and normal +command." (when (and (stringp index) (string-match-p "^[0-9]+$" index)) (setq index (string-to-number index))) @@ -322,11 +319,29 @@ end of the workspace list." (t (error "Not a valid index: %s" index))) (unless (called-interactively-p 'interactive) - (if (equal (+workspace-current-name) old-name) + (if (and (not skip-warnings) (equal (+workspace-current-name) old-name)) (+workspace-message (format "Already in %s" old-name) 'warn) (+workspace/display)))) ('error (+workspace-error (cadr ex) t)))) +;;;###autoload +(defun +ivy/workspace/switch-to () + (interactive) + (ivy-read "Switch to workspace: " + (+workspace-list-names) + :caller #'+ivy/workspace/switch-to + :preselect (+workspace-current-name) + :action (lambda (w) (+workspace--switch-to w t)))) + +;;;###autoload +(defun +workspace/switch-to (index) + "Switch to a workspace at a given INDEX. A negative number will start from the +end of the workspace list." + (interactive + (list (or current-prefix-arg + (completing-read "Switch to workspace: " (+workspace-list-names))))) + (+workspace/switch-to index)) + ;;;###autoload (dotimes (i 9) (defalias (intern (format "+workspace/switch-to-%d" i)) From 7b7cf327abf789f0396be0b2da47a0612fae05b3 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 1 Dec 2019 16:17:33 +0700 Subject: [PATCH 3/3] Use ivy to switch workspaces when user uses ivy --- modules/config/default/+evil-bindings.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index 31ea50ce7..599985089 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -298,7 +298,8 @@ (:when (featurep! :ui workspaces) (:prefix-map ("TAB" . "workspace") :desc "Display tab bar" "TAB" #'+workspace/display - :desc "Switch workspace" "." #'+workspace/switch-to + :desc "Switch workspace" "." + (if (featurep! :completion ivy) #'ivy/workspace/switch-to #'+workspace/switch-to) :desc "Switch to last workspace" "`" #'+workspace/other :desc "New workspace" "n" #'+workspace/new :desc "Load workspace from file" "l" #'+workspace/load