0

I run emacs --daemon and emacsclient. When I C-x C-c from emacsclient, it will show the prompt

Save file /dir/filename.txt? (y, n, !, ., q, C-r, d or C-h)

for each file that has changes that haven't been saved.

If I enter n, emacsclient will exit, but then the next time I open emacsclient, it will ask me again if I want to save changes. Typically when I enter n I want to disacard the changes so that next time I run emacsclient, that file will be reverted to its state on disk.

How can I discard all unsaved changes when exiting emacsclient?

Current behavior:

  • emacsclient -a "" -t filename.txt
  • Make changes
  • C-x C-c
  • Save file /dir/filename.txt? (y, n, !, ., q, C-r, d or C-h)
  • n
  • emacsclient -a "" -t filename.txt
  • C-x C-c
  • Save file /dir/filename.txt? (y, n, !, ., q, C-r, d or C-h)
  • n

Desired behavior:

  • emacsclient -a "" -t filename.txt
  • Make changes
  • C-x C-c
  • Save file /dir/filename.txt? (y, n, !, ., q, C-r, d or C-h)
  • n (changes are discarded)
  • emacsclient -a "" -t filename.txt
  • C-x C-c (emacsclient exits)
1

When done with a file opened through emacsclient, close it with C-x# (which runs server-edit), not C-xC-c.

You can also define a function that closes all remaining server files:

(defun close-all-server-files ()
  "Close all server files"
  (interactive)
  (while (not(server-edit))))

Just bind it to a key and run it when needed.

  • my workflow will often involve opening many buffers (10+) over the course of a few hours. Then when I want to quit, I want to discard everything I haven't saved. So switching to each buffer and executing C-x # seems too tedious to me. Is there another way? – mark Jun 23 '16 at 21:20
  • @mark: Check the update. – choroba Jun 23 '16 at 21:35
  • I added that function to my .emacs file, then opened a couple of files, edited them, and then ran M-x close-all-server-files. It produced the message No server buffers remain to edit. Then when I entered C-x C-c it prompted me about whether to save each file before exiting. – mark Jun 27 '16 at 23:46
0

A simple solution is to simply delete your current emacsclient frame with C-x 5 0. The daemon will continue to run and you won't be prompted about saving each buffer.

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.