From 361eec11a4da3dd9ee16a05468a0a7e6a1ce4046 Mon Sep 17 00:00:00 2001 From: duli Date: Sat, 24 May 2025 12:31:43 +0800 Subject: [PATCH] fix(workspaces): avoid duplicate workspace creation when no frame exists When Emacs is started as a daemon and no frames exist, `emacsclient -c` should simply switch to the main workspace. However, before `+workspaces-associate-frame-fn` is called, the new frame is already added to the frame list, which causes `persp-frame-list-without-daemon` to always return a non-empty list. A new workspace will be created instead of switching to the main one. --- modules/ui/workspaces/autoload/workspaces.el | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/ui/workspaces/autoload/workspaces.el b/modules/ui/workspaces/autoload/workspaces.el index b83f1784d..2579aed13 100644 --- a/modules/ui/workspaces/autoload/workspaces.el +++ b/modules/ui/workspaces/autoload/workspaces.el @@ -532,16 +532,16 @@ created." (defun +workspaces-associate-frame-fn (frame &optional _new-frame-p) "Create a blank, new perspective and associate it with FRAME." (when persp-mode - (if (not (persp-frame-list-without-daemon)) - (+workspace-switch +workspaces-main t) - (with-selected-frame frame - (+workspace-switch (format "#%s" (+workspace--generate-id)) t) - (unless (doom-real-buffer-p (current-buffer)) - (switch-to-buffer (doom-fallback-buffer))) - (set-frame-parameter frame 'workspace (+workspace-current-name)) - ;; ensure every buffer has a buffer-predicate - (persp-set-frame-buffer-predicate frame)) - (run-at-time 0.1 nil #'+workspace/display)))) + (with-selected-frame frame + (if (not (cdr-safe (persp-frame-list-without-daemon))) + (+workspace-switch +workspaces-main t) + (+workspace-switch (format "#%s" (+workspace--generate-id)) t)) + (unless (doom-real-buffer-p (current-buffer)) + (switch-to-buffer (doom-fallback-buffer))) + (set-frame-parameter frame 'workspace (+workspace-current-name)) + ;; ensure every buffer has a buffer-predicate + (persp-set-frame-buffer-predicate frame)) + (run-at-time 0.1 nil #'+workspace/display))) ;;;###autoload (defun +workspaces-switch-to-project-h (&optional dir)