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))