Emacs background autostart: Difference between revisions

From 清冽之泉
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 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" line>
<syntaxhighlight lang="bash">
sudo touch /etc/systemd/system/emacs.service
systemctl --user stop emacs-user.service   # 停止服务
sudo chmod 664 /etc/systemd/system/emacs.service
systemctl --user disable emacs-user.service # 禁用自动启动
[Unit]
rm ~/.config/systemd/user/emacs-user.service
Description=Emacs: the extensible, self-documenting text editor
systemctl --user daemon-reload
[Service]
Type=forking
ExecStart=/usr/bin/emacs --daemon
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"
Environment=SSH_AUTH_SOCK=%t/keyring/ssh
Restart=always
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable emacs.service
sudo systemctl start emacs.service
</syntaxhighlight>
</syntaxhighlight>
感谢 DeepSeek,上边全是他教的。从此以后,就可以随时启动 emacsclient 了。
 
这是在用户层面自启,对 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 了。