feat(workspaces): add +workspace/delete

For deleting saved workspaces (saved with `+workspace/save` or
`+workspace-save`).

Also binds `SPC TAB D` (for evil users) and `C-c w K` (for non-evil
users) to it.

Fix: #4399
Close: #7869
Co-authored-by: sriramsk1999 <sriramsk1999@users.noreply.github.com>
This commit is contained in:
Henrik Lissner 2024-07-29 19:46:42 -04:00
parent 04efd82590
commit 9cdcfdac36
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
3 changed files with 37 additions and 0 deletions

View file

@ -122,6 +122,24 @@ Returns t on success, nil otherwise."
(and (member name (persp-list-persp-names-in-file fname))
t)))
;;;###autoload
(defun +workspace-delete (workspace)
"Delete WORKSPACE from the saved workspaces in `persp-save-dir'.
Return t if WORKSPACE was successfully deleted. Throws error if WORKSPACE is not
found or wasn't saved with `+workspace-save'."
(let* ((fname (expand-file-name +workspaces-data-file persp-save-dir))
(workspace-name (if (stringp workspace) workspace (persp-name workspace)))
(workspace-names (persp-list-persp-names-in-file fname))
(workspace-idx (cl-position workspace-name workspace-names :test #'equal)))
(unless workspace-idx
(error "Couldn't find saved workspace '%s'" workspace-name))
(doom-file-write
fname (list (cl-remove-if (lambda (ws) (equal workspace-name (nth 1 ws)))
(doom-file-read fname :by 'read)
:count 1)))
(not (member name (persp-list-persp-names-in-file fname)))))
;;;###autoload
(defun +workspace-new (name)
"Create a new workspace named NAME. If one already exists, return nil.
@ -267,6 +285,23 @@ workspace to delete."
(+workspace-message (format "Deleted '%s' workspace" name) 'success)))
('error (+workspace-error ex t))))
;;;###autoload
(defun +workspace/delete (name)
"Delete a saved workspace in `persp-save-dir'.
Can only selete workspaces saved with `+workspace/save' or `+workspace-save'."
(interactive
(list
(completing-read "Delete saved workspace: "
(cl-loop with wsfile = (doom-path persp-save-dir +workspaces-data-file)
for p in (persp-list-persp-names-in-file wsfile)
collect p))))
(and (condition-case-unless-debug ex
(or (+workspace-delete name)
(+workspace-error (format "Couldn't delete '%s' workspace" name)))
('error (+workspace-error ex t)))
(+workspace-message (format "Deleted '%s' workspace" name) 'success)))
;;;###autoload
(defun +workspace/kill-session (&optional interactive)
"Delete the current session, all workspaces, windows and their buffers."