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.
This commit is contained in:
duli
2025-05-24 12:31:43 +08:00
committed by Henrik Lissner
parent 24aec7cd2b
commit 361eec11a4

View File

@ -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)