0

I recently managed to get Emacs server to work. But after I worked on my init file and changed some code in one elpa package, the changes were not visible.

I did the load-file for ~/.emacs, and bytecompiled the elpa directory. After this I could see the changes when I started emacs -nw from the terminal, but now when using emacsclient.

How could this be resolved? If I have to shut down and rerun the server, how do I do it? ( I set it to start at login with systemd)

  • M-x eval-buffer? – Swedgin Jan 9 at 12:57
  • The Emacs server is a service provided by your current Emacs instance. Emacs reads your init file when it starts, not every time after you change it, but you can run Emacs Lisp code at any time with C-x C-e and friends. To start Emacs from fresh, you can restart Emacs. I'm sure systemd provides method to restart a service. – xuchunyang Jan 9 at 15:16
  • As you've "set it to start at login with systemd" I presume you can ask systemd to stop and start the service manually. – phils Feb 26 at 4:14
2

Assuming you started it with systemctl --user enable emacs.service, you can restart it with:

systemctl --user restart emacs

That would kill all instances of emacsclient connected to the systemd emacs dameon, and restart the daemon.

All other systemctl commands work similarly, you can do systemctl --user status emacs to see logs.

| improve this answer | |
0

The reason why emacs -nw worked, was because you started an complete new emacs instance which read the the whole config. The command 'emacs' from bash would have done the same.

Beside restarting the whole emacs server and loosing all open buffers (as mentioned in another answer), you can also eval the recently changed code, from within an emacs client.

Functions like M-x eval-buffer, M-x eval-defun (C-M-x) or M-x eval-last-sexp (C-x C-e) will help you with that.

Evaling defuns again will owerwrite their old definition. When evaluating elisp code again, there are some catches because things like defvar behave special. (i.e. defvar does not change the value if it is non void)

So, restarting the whole emacs server would be the 100% solution unless you know what you are doing.

| improve this answer | |
0
  $ systemctl --user restart (or stop) emacs

is the kosher way from the pov of systemd.

For the Emacs user however, it will abruptly terminate the "service" losing all unsaved buffers – particularly the currently not visible ones.

Since this is highly undesirable, what I have is kill-emacs bound to a char (X) in Buffer-menu-mode-map.

Then instead of C-x C-c (which doesn't work as a full-kill for emacs-as-a-service) I use C-x C-b (look around) And X if all-clear.


Added later

...but should have started with this :
C-x C-c which normally does save-buffers-kill-emacs instead does save-buffers-kill-terminal for emacs-service. This makes C-x C-c ineffective for a "reboor". M-x kill-emacs will however do what you wish but risks losing unsaved buffers.

| improve this answer | |
0

One way you can do it manually assuming systemctl isn't configured for emacs as suggested previously is to connect to the server instance using emacsclient as you usually do and then close it down:-

I use this:-

    (defun server-shutdown () 
      "Save buffers, Quit, and Shutdown (kill) server" 
      (interactive) 
      (save-some-buffers) 
      (kill-emacs))

    (global-set-key (kbd "C-c x") 'server-shutdown)

Note, you can't hope to realistically update a running instance fully and properly without restarting. You are inviting trouble. Re-reading your startup will almost certainly not work for you.

As a side note, I hadn't realised that emacs26 on Debian 10 was indeed configured as a systemctl service - it is. Nice. Note that that call to (kill-emacs) is what the emacs.service "stop" directive actually calls too when invoking the following:-

systemctl --user stop emacs

Note that if you use the code I listed above to (kill-emacs) from a key binding AND emacs is configured and started as a service then it will automatically restart unless you use systemctl to stop it as shown just above.

For those that have an emacs.service in /usr/lib/systemd/user then you can enable this to autostart when you login (on Debian so your mileage may vary):-

systemctl --user enable emacs

And this will install a local use specific service link.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.