From 35ce37532b106322c906f1c14f61894abb41938c Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 1 Dec 2019 05:10:40 -0500 Subject: [PATCH] ui/workspaces: merge +ivy/workspace/switch-to into +workspace/switch-to Relevant to #2127 Closes #2130 --- modules/config/default/+evil-bindings.el | 3 +- modules/ui/workspaces/autoload/workspaces.el | 36 +++++++------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index 1282622c0..31ea50ce7 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -298,8 +298,7 @@ (:when (featurep! :ui workspaces) (:prefix-map ("TAB" . "workspace") :desc "Display tab bar" "TAB" #'+workspace/display - :desc "Switch workspace" "." - (if (featurep! :completion ivy) #'+ivy/workspace/switch-to #'+workspace/switch-to) + :desc "Switch workspace" "." #'+workspace/switch-to :desc "Switch to last workspace" "`" #'+workspace/other :desc "New workspace" "n" #'+workspace/new :desc "Load workspace from file" "l" #'+workspace/load diff --git a/modules/ui/workspaces/autoload/workspaces.el b/modules/ui/workspaces/autoload/workspaces.el index 438962e14..349c6ddfd 100644 --- a/modules/ui/workspaces/autoload/workspaces.el +++ b/modules/ui/workspaces/autoload/workspaces.el @@ -299,10 +299,18 @@ workspace, otherwise the new workspace is blank." (+workspace/display))) ((debug error) (+workspace-error (cadr e) t)))) - -(defun +workspace--switch-to (index &optional skip-warnings) - "Generic workspace switching action. It is used by both the ivy and normal -command." +;;;###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 + (if (featurep! :completion ivy) + (ivy-read "Switch to workspace: " + (+workspace-list-names) + :caller #'+workspace/switch-to + :preselect (+workspace-current-name)) + (completing-read "Switch to workspace: " (+workspace-list-names)))))) (when (and (stringp index) (string-match-p "^[0-9]+$" index)) (setq index (string-to-number index))) @@ -319,29 +327,11 @@ command." (t (error "Not a valid index: %s" index))) (unless (called-interactively-p 'interactive) - (if (and (not skip-warnings) (equal (+workspace-current-name) old-name)) + (if (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))