7

I am using workgroups and I have the following code in my init.el:

 (defun my-start-emacs (_)
   (interactive)
   (message "HI")
   (sleep-for 1)
   (if (daemonp)
       (progn
         (if (not (boundp 'server-wg))
             (progn
               (wg-create-workgroup "server")
               (setq server-wg (wg-current-workgroup)))
           (progn
             (setq current-wg (condition-case nil
                                  (wg-current-workgroup)
                                (error nil)))
             (if (not current-wg)
                 (wg-switch-to-workgroup server-wg)
               (if (not (eq current-wg server-wg))
                   (wg-switch-to-workgroup server-wg))))))))

 (add-to-list 'after-make-frame-functions #'my-start-emacs)

The my-start-emacs function creates the "server" workgroup if it does not exist, and loads it if it does. Using it manually via M-x my-start-emacs works perfectly, however for some reason even though it is called when I start the emacsclient -t (attach to server after emacs --daemon), nothing happens (i.e. the server workgroup is created, but is not changed to)... Why?

Dan
  • 32,584
  • 6
  • 98
  • 168
space_voyager
  • 709
  • 5
  • 19

1 Answers1

8

That FRAME argument to after-make-frame-functions that you're explicitly ignoring? Don't ignore it.

(defun my-start-emacs (frame)
  "Switch client frames of an emacs daemon to the 'server' workgroup."
  (interactive)
  (with-selected-frame frame
    (when (daemonp)
      (if (not (boundp 'server-wg))
          (progn
            (wg-create-workgroup "server")
            (setq server-wg (wg-current-workgroup)))
        (setq current-wg (condition-case nil
                             (wg-current-workgroup)
                           (error nil)))
        (if (not current-wg)
            (wg-switch-to-workgroup server-wg)
          (if (not (eq current-wg server-wg))
              (wg-switch-to-workgroup server-wg)))))))
phils
  • 48,657
  • 3
  • 76
  • 115