diff --git a/modules/feature/workspaces/autoload/workspaces.el b/modules/feature/workspaces/autoload/workspaces.el index bc061960a..362b7eae5 100644 --- a/modules/feature/workspaces/autoload/workspaces.el +++ b/modules/feature/workspaces/autoload/workspaces.el @@ -17,9 +17,32 @@ ;;;###autoload (defun +workspace-list () - "Retrieve a list of names of open workspaces (strings)." + "Return a list of workspace structs." + (mapcar #'persp-get-by-name (+workspace-list-names))) + +;;;###autoload +(defun +workspace-list-names () + "Return a list of workspace names (strings)." (delete persp-nil-name (persp-names-current-frame-fast-ordered))) +;;;###autoload +(defun +workspace-buffer-list (&optional persp) + "Return a list of buffers in PERSP (defaults to the current perspective). + +PERSP can be a string (name of a workspace) or a perspective hash (satisfies +`+workspace-p'). + +If PERSP is t, then return a list of orphaned buffers associated with no +perspectives." + (cond ((not persp) + (persp-buffer-list-restricted)) + ((eq persp t) + (cl-remove-if #'persp--buffer-in-persps (doom-buffer-list))) + ((+workspace-p persp) + (safe-persp-buffers persp)) + ((stringp persp) + (safe-persp-buffers (+workspace-get persp t))))) + ;;;###autoload (defun +workspace-p (obj) "Return t if OBJ is a perspective hash table." @@ -34,7 +57,7 @@ (setq name (symbol-name name))) (unless (stringp name) (error "Expected a string, got a %s" (type-of name))) - (member name (+workspace-list))) + (member name (+workspace-list-names))) ;;;###autoload (defun +workspace-get (name &optional noerror) @@ -133,7 +156,7 @@ perspective or its hash table." (persp-frame-switch name)) (defun +workspace--generate-id () - (or (cl-loop for name in (+workspace-list) + (or (cl-loop for name in (+workspace-list-names) when (string-match-p "^#[0-9]+$" name) maximize (string-to-number (substring name 1)) into max finally return (if max (1+ max))) @@ -189,7 +212,7 @@ workspace." (list (if current-prefix-arg (+workspace-current-name) - (completing-read "Workspace to save: " (+workspace-list))))) + (completing-read "Workspace to save: " (+workspace-list-names))))) (if (+workspace-save name) (+workspace-message (format "'%s' workspace saved" name) 'success) (+workspace-error (format "Couldn't save workspace %s" name)))) @@ -232,7 +255,7 @@ workspace to delete." (list (if current-prefix-arg (completing-read (format "Delete workspace (default: %s): " current-name) - (+workspace-list) + (+workspace-list-names) nil nil current-name) current-name)))) (condition-case ex @@ -248,7 +271,8 @@ workspace to delete." (defun +workspace/kill-session () "Delete the current session, clears all workspaces, windows and buffers." (interactive) - (unless (cl-every '+workspace-delete (delete +workspaces-main (+workspace-list))) + (unless (cl-every #'+workspace-delete + (delete +workspaces-main (+workspace-list-names))) (+workspace-error "Could not clear session")) (+workspace-switch +workspaces-main t) (doom/kill-all-buffers) @@ -288,12 +312,12 @@ pre-existing workspace." end of the workspace list." (interactive (list (or current-prefix-arg - (completing-read "Switch to workspace: " (+workspace-list))))) + (completing-read "Switch to workspace: " (+workspace-list-names))))) (when (and (stringp index) (string-match-p "^[0-9]+$" index)) (setq index (string-to-number index))) (condition-case ex - (let ((names (+workspace-list)) + (let ((names (+workspace-list-names)) (old-name (+workspace-current-name))) (cond ((numberp index) (let ((dest (nth index names))) @@ -316,7 +340,7 @@ end of the workspace list." (defun +workspace/switch-to-last () "Switch to the last workspace." (interactive) - (+workspace/switch-to (car (last (+workspace-list))))) + (+workspace/switch-to (car (last (+workspace-list-names))))) ;;;###autoload (defun +workspace/cycle (n) @@ -326,7 +350,7 @@ end of the workspace list." (if (equal current-name persp-nil-name) (+workspace-switch +workspaces-main t) (condition-case ex - (let* ((persps (+workspace-list)) + (let* ((persps (+workspace-list-names)) (perspc (length persps)) (index (cl-position current-name persps))) (when (= perspc 1) @@ -356,7 +380,7 @@ the workspace and move to the next." (if (bound-and-true-p evil-mode) (evil-window-delete) (delete-window))) - ((> (length (+workspace-list)) 1) + ((> (length (+workspace-list-names)) 1) (+workspace/delete current-persp-name)))))) ;;;###autoload @@ -376,7 +400,7 @@ the workspace and move to the next." ;; (defun +workspace--tabline (&optional names) - (let ((names (or names (+workspace-list))) + (let ((names (or names (+workspace-list-names))) (current-name (+workspace-current-name))) (mapconcat #'identity