4

How to use Emacs desktop functionality with emacs daemon + emacsclient instances?

I've enabled (desktop-save-mode 1) in my init file, and when I start the daemon I see messages like this:

Desktop: 1 frame, 2 buffers restored.

However, it does not restart any of emacsclient instances I have. When I start an emacsclient instance it's blank.

Is there a way to restore the desktop manually once I open a new emacsclient instance? Or is there a way to make this work another way?

Galder Zamarreño
  • 1,527
  • 2
  • 12
  • 21

1 Answers1

4

I suspect you have unremoved desktop lockfiles, which will usually be in your config dir/folder, which is hopefully ~/.emacs.d/. Here's a procedure for testing my hypothesis from a commandline (e.g. a Bash shell running in a terminal app under Linux):

  1. Ensure you have no emacs* processes running: i.e., there should be null response to

    pgrep -l emacs
    

    If you do get a response, like

    $ pgrep -l emacs
    29422 emacs
    

    you will need to manually close your Emacsen, or brutally kill them with (e.g.)

    pkill -9 emacs
    
  2. Check for desktop lockfiles in your config dir with, e.g.,

    find ~/.emacs.d/ -name '*lock*'
    

If there is null response to the 2nd commandline && my hypothesis is correct, you should be able to start Emacs and see your desktop (i.e., all those buffers will be auto-open'ed). Note the preferred way to start both a fresh daemon and client is either

# create a GUI frame
emacsclient --alternate-editor '' --create-frame &

or

# start a TUI Emacs in current terminal
emacsclient --alternate-editor '' --tty

If there is not a null response to the 2nd commandline--i.e., you get something like

$ find ~/.emacs.d/ -name '*lock*'
/home/you/.emacs.d/.emacs.desktop.lock

in your shell, then delete those lockfiles, e.g.

find ~/.emacs.d/ -name '*lock*' | xargs rm

Then rerun

find ~/.emacs.d/ -name '*lock*'

until you get a null response, then retest my hypothesis. (I.e., start a fresh Emacs--if you see your desktop buffers, I'm correct, else I'm not.)

TomRoche
  • 592
  • 3
  • 20