hubisan / emacs-wsl

Install and run Emacs with the Windows Subsystem for Linux (WSL 2) in Windows 10 or 11.
571 stars 42 forks source link

Using emacsclient #53

Closed vermiculus closed 2 years ago

vermiculus commented 2 years ago

Has anyone had luck getting emacsclient to work? I often switch networks, which VcXsrv does not handle well -- usually disconnecting emacs and losing in-progress work.

If I modify wsl-2_4-*.ps1 to instead start emacs --daemon instead of emacs, the daemon launches successfully:

Warning: due to a long standing Gtk+ bug
https://gitlab.gnome.org/GNOME/gtk/issues/221
Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.
Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.
Loading ~/.emacs.d/init-custom.el (source)...
Loading ~/.emacs.d/init-custom.el (source)...done
[Treemacs] Warning: coudn’t find default background colour for icons, falling back on #2d2d31.
[Treemacs] Warning: couldn’t find hl-line-mode’s background color for icons, falling back on #2d2d31.
[yas] Prepared just-in-time loading of snippets (but no snippets found).
Starting Emacs daemon.

With an additional modified version of wsl-2_4-*.ps1 to start emacsclient . instead of emacs:

wsl -d Ubuntu bash -c "export DISPLAY=$wslip`:0.0 export LIBGL_ALWAYS_INDIRECT=1 && setsid emacsclient ~"

I don't see a window (or any debugging information). Using emacsclient -d with the display's IP similarly has no effect.

Using just wsl emacsclient . will launch effectively give me emacs -nw just fine. I just can't get it to use an X display ☹️

hubisan commented 2 years ago

Tried the following:

Started the WSL terminal (using WSL1):

emacs --daemon
exit

Then I launched another terminal and successfully launched emacsclient:

export DISPLAY=:0.0
export LIBGL_ALWAYS_INDIRECT=1
setsid emacsclient --create-frame ~ && exit

Used the --create-frame (alias is just -c) option to Create a new frame instead of trying to use the current Emacs frame to make sure a frame is created.

You can probably change the line in the first script from

wsl -d Ubuntu-20.04 bash -c "export DISPLAY=$wslip`:0.0 export LIBGL_ALWAYS_INDIRECT=1 && setsid emacs"

to

wsl -d Ubuntu-20.04 bash -c "emacs --daemon"

And in the second to:

wsl -d Ubuntu-20.04 bash -c "export DISPLAY=$wslip`:0.0 export LIBGL_ALWAYS_INDIRECT=1 && setsid emacsclient -c ~"
hubisan commented 2 years ago

Closing this as there was no follow up for almost a month.