fix(workspaces): "none" workspace

Doom removes the "none" workspace from persp-mode's default list of
perspectives, because it is a special case that doesn't behave
identically to other persps in the list, making it a pain to deal with.

This worked fine up until a change to `persp-update-names-cache` (in
Bad-ptr/persp-mode.el@0d6cacc) made it re-insert this "none" workspace
into `persp-names-cache` whenever it is called, undoing our hack; this
commit adapts to that change.

Ref: Bad-ptr/persp-mode.el@0d6caccab3
Ref: Bad-ptr/persp-mode.el@b2e68f97cb
Fix: #7986
Amend: 7f3412e317
This commit is contained in:
Henrik Lissner 2024-08-09 15:42:54 -04:00
parent 7f3412e317
commit b3bea23331
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 12 additions and 15 deletions

View file

@ -63,20 +63,20 @@ error if NAME doesn't exist."
"Get the name of the current workspace."
(safe-persp-name (+workspace-current)))
;;;###autoload
(defun +workspace-list-names ()
"Return the list of names of open workspaces."
(cl-remove persp-nil-name persp-names-cache :count 1))
;;;###autoload
(defun +workspace-list ()
"Return a list of workspace structs (satisifes `+workspace-p')."
;; We don't use `hash-table-values' because it doesn't ensure order in older
;; versions of Emacs
(cl-loop for name in persp-names-cache
(cl-loop for name in (+workspace-list-names)
if (gethash name *persp-hash*)
collect it))
;;;###autoload
(defun +workspace-list-names ()
"Return the list of names of open workspaces."
persp-names-cache)
;;;###autoload
(defun +workspace-buffer-list (&optional persp)
"Return a list of buffers in PERSP.
@ -193,7 +193,7 @@ throws an error."
(let ((old-name (+workspace-current-name)))
(unless (equal old-name name)
(setq +workspace--last
(or (and (not (string= old-name persp-nil-name))
(or (and (not (+workspace--protected-p old-name))
old-name)
+workspaces-main))
(persp-frame-switch name))
@ -398,7 +398,7 @@ end of the workspace list."
"Cycle n workspaces to the right (default) or left."
(interactive (list 1))
(let ((current-name (+workspace-current-name)))
(if (equal current-name persp-nil-name)
(if (+workspace--protected-p current-name)
(+workspace-switch +workspaces-main t)
(condition-case-unless-debug ex
(let* ((persps (+workspace-list-names))
@ -446,9 +446,10 @@ the next."
(interactive "p")
(let* ((current-name (+workspace-current-name))
(count (or count 1))
(index (- (cl-position current-name persp-names-cache :test #'equal)
(persps (+workspace-list-names))
(index (- (cl-position current-name persps :test #'equal)
count))
(names (remove current-name persp-names-cache)))
(names (remove current-name persps)))
(unless names
(user-error "Only one workspace"))
(let ((index (min (max 0 index) (length names))))
@ -575,7 +576,7 @@ This be hooked to `projectile-after-switch-project-hook'."
(unwind-protect
(if (and (not (null +workspaces-on-switch-project-behavior))
(or (eq +workspaces-on-switch-project-behavior t)
(equal (safe-persp-name (get-current-persp)) persp-nil-name)
(+workspace--protected-p (safe-persp-name (get-current-persp)))
(+workspace-buffer-list)))
(let* ((persp
(let ((project-name (doom-project-name +workspaces--project-dir)))

View file

@ -73,10 +73,6 @@ stored in `persp-save-dir'.")
"Ensure a main workspace exists."
(when persp-mode
(let (persp-before-switch-functions)
;; Try our best to hide the nil perspective.
(when (equal (car persp-names-cache) persp-nil-name)
(pop persp-names-cache))
;; ...and create a *real* main workspace to fill this role.
(unless (or (persp-get-by-name +workspaces-main)
;; Start from 2 b/c persp-mode counts the nil workspace
(> (hash-table-count *persp-hash*) 2))