Emacs background autostart: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
mkdir -p ~/.config/systemd/user | mkdir -p ~/.config/systemd/user | ||
nano ~/.config/systemd/user/emacs.service | nano ~/.config/systemd/user/emacs-user.service | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 21: | Line 21: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
systemctl --user daemon-reload | systemctl --user daemon-reload | ||
systemctl --user enable emacs.service | systemctl --user enable emacs-user.service | ||
systemctl --user start emacs.service | systemctl --user start emacs-user.service | ||
systemctl --user status emacs.service | systemctl --user status emacs-user.service | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="bash" | <syntaxhighlight lang="bash"> | ||
systemctl --user stop emacs-user.service # 停止服务 | |||
systemctl --user disable emacs-user.service # 禁用自动启动 | |||
rm ~/.config/systemd/user/emacs-user.service | |||
systemctl --user daemon-reload | |||
</syntaxhighlight> | </syntaxhighlight> | ||
感谢 | |||
这是在用户层面自启,对 sudo 用户也自启,请看下一篇。 | |||
感谢 ChatGPT,上边是他教的。从此以后,就可以随时启动 emacsclient 了。 |
Latest revision as of 11:31, 14 May 2025
mkdir -p ~/.config/systemd/user
nano ~/.config/systemd/user/emacs-user.service
[Unit] Description=Emacs text editor as a daemon Documentation=info:emacs man:emacs(1) [Service] Type=forking ExecStart=/usr/bin/emacs --daemon ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)" Restart=on-failure [Install] WantedBy=default.target
systemctl --user daemon-reload
systemctl --user enable emacs-user.service
systemctl --user start emacs-user.service
systemctl --user status emacs-user.service
systemctl --user stop emacs-user.service # 停止服务
systemctl --user disable emacs-user.service # 禁用自动启动
rm ~/.config/systemd/user/emacs-user.service
systemctl --user daemon-reload
这是在用户层面自启,对 sudo 用户也自启,请看下一篇。
感谢 ChatGPT,上边是他教的。从此以后,就可以随时启动 emacsclient 了。