Merge pull request #2127 from rgrinberg/create-workspaces-switch
ui/workspaces: auto-create named workspace
This commit is contained in:
commit
6dbf8510c2
2 changed files with 26 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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)))
|
||||
|
@ -318,17 +315,33 @@ 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)
|
||||
(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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue