I'm automating some work tasks, and many of them consist of calling kubectl edit on different objects.

kubectl edit basically opens your $EDITOR which I have configured to be emacsclient.

My question is, how can I, from elisp run a command like kubectl edit that consists on a blocking call (waits for completion) to emacsclient, have all the edits I need done with emacsclient and then continue the execution of the elisp function?

Or maybe, instead of using $EDITOR to emacsclient can I set $EDITOR to something like: "the current running Emacs instance"?

I've found this answer that seem to be similar to my problem. But I wanted to know if there's a way for Emacs to understand that a command is calling $EDITOR and use the current instance, instead of doing it through emacsclient.

  • 1
    I think that Magit does something similar, with git. I think it start the external command in async mode, let it run emacsclient. It triggers Emacs to open a commit window. When the user is done, emacsclient is notified so that the external process can exit. (Reservation: I'm not an expert on Magit, so my understanding might be oversimplified, or even plain wrong.) Mar 13 at 10:49

1 Answer 1


You're looking for the with-editor library (which is what @Lindydancer is alluding to in the comment about Magit).


It provides the commands with-editor-async-shell-command and with-editor-shell-command, which are intended as replacements for async-shell-command and shell-command. They automatically export $EDITOR making sure the executed command uses the current Emacs instance as "the editor".


(defun my-crontab-edit ()
  "Edit crontab."
  (require 'with-editor)
  (with-editor-async-shell-command "crontab -e"))

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.