3

Is there a way to edit a file only once? So that for example: I open it and its closed (the buffer is killed) after the window closes. A clarification: I usually have an Emacs deamon running and open windows with emacsclient -nc [file], but I don't want to have every file in my buffer list and I dont want to open a single instance for every file I only edit once.

Any ideas?

  • The question seems to suggest that you want to close the window too, not just kill the buffer. AFAIK, neither C-x # nor C-x k close the window, and just closing the window does not kill the buffer. – Drew Jul 10 '16 at 16:56
  • @Drew If emacsclient is launched with -c (but not with -n), it will open the file in a new frame. Doing C-x # there will kill buffer and close the new frame that launched (and thus the window too). – Kaushal Modi Jul 10 '16 at 21:24
  • @KaushalModi: I see. Is that true for C-x k also (I don't think so). – Drew Jul 10 '16 at 22:24
  • There is also C-x 4 0 (kill-buffer-and-window), which has the same effect as C-x k (kill-buffer) in emacsclient, but additionally has the desired behaviour under "normal" Emacs operation (for some definition thereof). – Basil Oct 12 '17 at 15:33
3

Instead of using emacsclient -nc [file], if you remove the -n argument and do just emacsclient -c [file], you can quickly close the popped frame and buffer by calling server-edit, which is bound to C-x # by default.


For instance, my workflow for editing crontab files would be:

  1. crone (aliased to setenv VISUAL emacsclient && crontab -e (tcsh)) in terminal.
  2. Update the crontab
  3. C-x #

Notice that I choose to not use even the -c argument. I like the file to pop up in my one and only emacsclient frame (already open). When I am done editing that file, C-x # will save the file (update crontab), kill the buffer, and I will be back to where I was in my emacsclient frame before I called crone from the terminal.

1

You can end the edit session of such files by killing their buffer (e.g. C-x k RET).

-1

You can use M-x delete-frame. This will close the actual frame.

  • But it won't close the buffer, which was the point of the question. – Gilles Oct 11 '17 at 23:24

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.