From b3bea23331f548b02682fda1170c439560a5fb64 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 9 Aug 2024 15:42:54 -0400 Subject: [PATCH] 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@0d6caccab302 Ref: Bad-ptr/persp-mode.el@b2e68f97cbe0 Fix: #7986 Amend: 7f3412e3174d --- modules/ui/workspaces/autoload/workspaces.el | 23 ++++++++++---------- modules/ui/workspaces/config.el | 4 ---- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/modules/ui/workspaces/autoload/workspaces.el b/modules/ui/workspaces/autoload/workspaces.el index 1a182be62..39874bafa 100644 --- a/modules/ui/workspaces/autoload/workspaces.el +++ b/modules/ui/workspaces/autoload/workspaces.el @@ -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))) diff --git a/modules/ui/workspaces/config.el b/modules/ui/workspaces/config.el index 540c76977..941786282 100644 --- a/modules/ui/workspaces/config.el +++ b/modules/ui/workspaces/config.el @@ -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))