Issue: I have a personalized loading function for using workgroups2 exclusively when running runing as daemon (i.e. using emacsclient to connect to a running emacs server started with emacs --daemon).
Working workflow
workgroups2 setup:
(use-package workgroups2
;; Restore layout. I use it only for keeping a persistent layout
;; for an emacs --daemon server
:ensure t
:config
(if (daemonp)
(workgroups-mode 1) ;; turn on workgroups mode when running as daemon
)
(setq wg-morph-on nil) ;; No silly workgroup switching animation
;; Start function
(defun my-start-emacs ()
"Switch client frames of an emacs daemon to the 'server' workgroup."
(interactive)
(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)
)
)
)
)
)
)
)
;; Exit function
(defun my-exit-emacs ()
"Leaves session and saves all workgroup states. Will not continue if there is no w\
orkgroups open."
(interactive)
(if (daemonp)
(progn
;;(wg-update-all-workgroups)
(save-buffers-kill-terminal)
)
(save-buffers-kill-terminal)
))
(global-set-key (kbd "C-x C-c") 'my-exit-emacs)
)
Then I connect to server by running emacsclient -e '(my-start-emacs)' -s <SERVER_NAME> -t. The window layout is restored between connections and the buffers are correctly assigned (i.e. a file opened in window A on a previous session remains in window A upon the next connection to the session).
Workflow that doesn't work (the issue)
I slightly modify the above code to remove the -e '(my-start-emacs)' part of the emacsclient terminal command by calling the my-start-emacs function via a hook to after-make-frame-functions:
(use-package workgroups2
;; Restore layout. I use it only for keeping a persistent layout
;; for an emacs --daemon server
:ensure t
:config
(if (daemonp)
(workgroups-mode 1) ;; turn on workgroups mode when running as daemon
)
(setq wg-morph-on nil) ;; No silly workgroup switching animation
;; Start function
(defun my-start-emacs (frame)
"Switch client frames of an emacs daemon to the 'server' workgroup."
(interactive)
(select-frame frame)
(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)
;; Exit function
(defun my-exit-emacs ()
"Leaves session and saves all workgroup states. Will not continue if there is no workgroups open."
(interactive)
(if (daemonp)
(progn
;;(wg-update-all-workgroups)
(save-buffers-kill-terminal)
)
(save-buffers-kill-terminal)
))
(global-set-key (kbd "C-x C-c") 'my-exit-emacs)
)
Connecting to a running server with emacsclient -e -s <SERVER_NAME> -t restored the window layout, but does not assign buffers to the windows (i.e. if window A held some foo.txt file in the previous session, it now holds the scratch buffer). Illustration:
Previous session:
After disconnecting from the above session (C-x C-c) and reconnecting to it (above emacsclient command), I get:
Notice that the ansi-term buffer was restored corrected, but the .bash_aliases got replaced by sratch (even though it is still in the buffer list!).
Expected behavior
The buffers should be correctly assigned to their windows (e.g. in the above example, .bash_aliases should still be open). This is the case for the first workflow, but not for the second - and I do not know why.
Emacs 24.5.1 Ubuntu 14.04
Issue: I have a personalized loading function for using workgroups2 exclusively when running runing as daemon (i.e. using
emacsclient
to connect to a running emacs server started withemacs --daemon
).Working workflow
workgroups2 setup:
Then I connect to server by running
emacsclient -e '(my-start-emacs)' -s <SERVER_NAME> -t
. The window layout is restored between connections and the buffers are correctly assigned (i.e. a file opened in window A on a previous session remains in window A upon the next connection to the session).Workflow that doesn't work (the issue)
I slightly modify the above code to remove the
-e '(my-start-emacs)'
part of the emacsclient terminal command by calling themy-start-emacs
function via a hook toafter-make-frame-functions
:Connecting to a running server with
emacsclient -e -s <SERVER_NAME> -t
restored the window layout, but does not assign buffers to the windows (i.e. if window A held some foo.txt file in the previous session, it now holds the scratch buffer). Illustration:C-x C-c
) and reconnecting to it (above emacsclient command), I get:Notice that the ansi-term buffer was restored corrected, but the .bash_aliases got replaced by sratch (even though it is still in the buffer list!).
Expected behavior
The buffers should be correctly assigned to their windows (e.g. in the above example, .bash_aliases should still be open). This is the case for the first workflow, but not for the second - and I do not know why.