在windows中使用emacs --daemon 这要怎么解决啊

在windows中使用emacs --daemon 这要怎么解决啊

C:\Users\huayu>wsl emacs --daemon

Warning: due to a long standing Gtk+ bug

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.
Starting Emacs daemon. Unable to start the daemon. Another instance of Emacs is running the server, either as daemon or interactively. You can use emacsclient to connect to that Emacs process. Error: server did not start correctly

报错说的是server已启动。

看下$XDG_RUNTIME_DIR/emacs里面有没有叫server的文件(socket)。

ls -l "$XDG_RUNTIME_DIR"/emacs

windows wsl2 ubuntu 系统;使用nix安装的emacs28,daemon启动正常无任何bug。

有具体的安装教程吗?

直接按照官网教程装就行了,装single user的即可。

我是把 nix 当包管理器用的,那些高级的配置可重复、可回滚之类的特性我都不用。

主要就是 ubuntu 的默认源的包都太老了,我也不愿意装野生 deb 包,更不喜欢从源码编译包,因为要自己手动装一大堆依赖没办法靠 autoremove 自动清理他们(go 和 rust 之类的纯静态编译的编程语言自己编译倒是无所谓)。那 linux 里好用的第三方包管理器只有 homebrew 和 nix咯,homebrew又不能装gui program只能装命令行程序,那我就选择了nix。

使用nix安装,emacs --daemon不报错了. 但是我这里使用emacsclient没法连接emacs server了,找不到server

主楼的这个报错不用管啊,不影响正常使用的。就开daemon使提醒你一下而已。

运行这个命令看下输出这个文件名是什么,然后看看这个文件夹里有没有东西

$ emacs --fg-daemon=test \
        -l server \
        --eval '(message "%s/%s" server-socket-dir server-name)'

你为啥是 root 用户啊?我记得 nix 是禁止 root 用户 安装的啊。你没有设置一个自己的非 root 用户吗?

$ emacs --fg-daemon=test \
        -l server \
        --eval '(message "%s/%s" server-socket-dir server-name)'

运行了这个命令后输出

huyu01@huyu01:/mnt/c/Users/huyu$ emacs --fg-daemon=test \
>         -l server \
>         --eval '(message "%s/%s" server-socket-dir server-name)'
Starting Emacs daemon.
~/.emacs.d/server/server



image 这是输出 再输入emacsclient a后还是无法找到emac server

huyu01@huyu01:/mnt/c/Users/huyu$ emacsclient a
emacsclient: can't find socket; have you started the server?
emacsclient: To start the server in Emacs, type "M-x server-start".
emacsclient: No socket or alternate editor.  Please use:

        --socket-name
        --server-file      (or environment variable EMACS_SERVER_FILE)
        --alternate-editor (or environment variable ALTERNATE_EDITOR)
huyu01@huyu01:/mnt/c/Users/huyu$ emacs --daemon
Starting Emacs daemon.
Unable to start the daemon.
Another instance of Emacs is running the server, either as daemon or interactively.
You can use emacsclient to connect to that Emacs process.
Error: server did not start correctly
huyu01@huyu01:/mnt/c/Users/huyu$

现在server文件夹,我在init.el配置放到了.emacs.d中,但是emacsclient找不到

linux我没有使用过,但是windows使用emacs server需要配置环境变量,linux是否也需要配置环境变量

emacsclient 用着就很多问题,配合 wsl 问题更多。
所以我直接换成msys2编译的emacs了,速度挺不错的,没必要wsl

完全不需要的.

可以看我的小教程: <https://github.com/shynur/.emacs.d/blob/main/docs/Emacs-use_daemon.md>.

如果有错误或者可以改进的地方欢迎提 issue, 谢谢.


@junmoxiao :

有啥问题? 我一直用着挺舒服的.

1 个赞

很久没用了,我记得好像是通过emacsclient打开文件的话,字体,窗口大小和预设的不一致。之前也没仔细研究过能不能解决

可以参考一下stackexchange关于emacs client讨论

你这个问题确实存在, 但是是 defined behavior.

这里的回答讲得 (也许) 很清楚:


@LongTu :

他说的是 face 之类的设定问题.

嗯,不过从emacs29之后本身emacs打开的速度就很快,就一直用着了

可能是我配置写得垃圾, 我要启动五六秒, 运气不好就是十秒…

什么? 一两秒? Client 打开不到半秒, 而且我还在 Windows 上的任务管理器里给 daemon 开了 效能模式.

是啊,一直没找到解决办法