5

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?

5

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)))))))
  • Perfect, it works now! – space_voyager Mar 10 '17 at 22:15
  • Actually... even though this method manages to restore the window layout - the buffers are not being assigned to the windows... do you know why? – space_voyager Mar 13 '17 at 6:30
  • I'm afraid not. I don't actually use the workgroups library, so I'd need to dig through the code/documentation to figure that one out. – phils Mar 13 '17 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.