 
 (autoload 'consult--multi "consult")
 ;;;###autoload
-(defun +vertico/switch-workspace-buffer ()
+(defun +vertico/switch-workspace-buffer (buffers &optional force-same-workspace)
   "Switch to another buffer in the same workspace.
 
 Type the workspace's number (starting from 1) followed by a space to display its
-buffer list."
-  (interactive)
-  ;; FIXME Open buffers in other workspaces in their respective workspace
+buffer list. Selecting a buffer in another workspace will switch to that
+workspace instead. If FORCE-SAME-WORKSPACE (the prefix arg) is non-nil, that
+buffer will be opened in the current workspace instead."
+  (interactive "P")
   (when-let (buffer (consult--multi (+vertico--workspace-generate-sources)
                                     :require-match
                                     (confirm-nonexistent-file-or-buffer)

              (cl-incf i)
              `(:name     ,name
                :hidden   ,(not (string= active-workspace name))
                :narrow   ,(nth i key-range)
                :category buffer
                :state    consult--buffer-state
                :items    ,(lambda ()
                             (consult--buffer-query
                              :sort 'visibility

                                                    (+workspace-current-name))
                                    :history 'consult--buffer-history
                                    :sort nil))
    (let ((origin-workspace (plist-get (cdr buffer) :name)))
      ;; Switch to the workspace the buffer belongs to, maybe
      (if (or (equal origin-workspace (+workspace-current-name))
              force-same-workspace)
          (funcall consult--buffer-display (car buffer))
        (+workspace-switch origin-workspace)
        (message "Switched to %S workspace" origin-workspace)
        (if-let (window (get-buffer-window (car buffer)))
            (select-window window)
          (funcall consult--buffer-display (car buffer)))))))

;;;###autoload
(defun +vertico/embark-open-in-new-workspace (x)
