ui/workspaces: merge +ivy/workspace/switch-to into +workspace/switch-to

Relevant to #2127
Closes #2130
This commit is contained in:
Henrik Lissner 2019-12-01 05:10:40 -05:00
parent bf0efe81ae
commit 35ce37532b
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 14 additions and 25 deletions

View file

@ -298,8 +298,7 @@
(:when (featurep! :ui workspaces) (:when (featurep! :ui workspaces)
(:prefix-map ("TAB" . "workspace") (:prefix-map ("TAB" . "workspace")
:desc "Display tab bar" "TAB" #'+workspace/display :desc "Display tab bar" "TAB" #'+workspace/display
:desc "Switch workspace" "." :desc "Switch workspace" "." #'+workspace/switch-to
(if (featurep! :completion ivy) #'+ivy/workspace/switch-to #'+workspace/switch-to)
:desc "Switch to last workspace" "`" #'+workspace/other :desc "Switch to last workspace" "`" #'+workspace/other
:desc "New workspace" "n" #'+workspace/new :desc "New workspace" "n" #'+workspace/new
:desc "Load workspace from file" "l" #'+workspace/load :desc "Load workspace from file" "l" #'+workspace/load

View file

@ -299,10 +299,18 @@ workspace, otherwise the new workspace is blank."
(+workspace/display))) (+workspace/display)))
((debug error) (+workspace-error (cadr e) t)))) ((debug error) (+workspace-error (cadr e) t))))
;;;###autoload
(defun +workspace--switch-to (index &optional skip-warnings) (defun +workspace/switch-to (index)
"Generic workspace switching action. It is used by both the ivy and normal "Switch to a workspace at a given INDEX. A negative number will start from the
command." 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) (when (and (stringp index)
(string-match-p "^[0-9]+$" index)) (string-match-p "^[0-9]+$" index))
(setq index (string-to-number index))) (setq index (string-to-number index)))
@ -319,29 +327,11 @@ command."
(t (t
(error "Not a valid index: %s" index))) (error "Not a valid index: %s" index)))
(unless (called-interactively-p 'interactive) (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-message (format "Already in %s" old-name) 'warn)
(+workspace/display)))) (+workspace/display))))
('error (+workspace-error (cadr ex) t)))) ('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 ;;;###autoload
(dotimes (i 9) (dotimes (i 9)
(defalias (intern (format "+workspace/switch-to-%d" i)) (defalias (intern (format "+workspace/switch-to-%d" i))