Usually, when you open a file, Emacs prompts you to run M-x make-directory RET RET if the directory doesn't exist.

However, after writing my own advice, I realized that opening files in directories that don't exist was giving me a lot of errors. After digging a bit, I found that apparently make-process tries to set the current directory to the buffer's default-directory. Since it doesn't exist yet, it fails with an error saying that setting the directory didn't work.

Is there a way to prevent this, and still have the make-process command work? I looked at the keyword arguments, but I couldn't find any that would prevent the working directory from being set.

  • 1
    If you can control the keyword arguments you can also wrap make-process into a let-form binding default-directory locally to the name of an existing directory.
    – Tobias
    Commented Jun 13, 2018 at 8:52

2 Answers 2


Reading in make-process comments about "current buffer's current directory", assume this is a bug. Can't see why a buffer connected to a process must have a file resp. filename. Seems worth a bug-report.

  • To make sure I explained this correctly, let me elaborate a bit. I meant that when you create a process with make-process, Emacs tries to set the working directory of the process to the default directory of the current buffer. I didn't mean that the buffer it creates (i.e. the buffer key in the arguments) has that set as its default directory. Reading your answer, I thought you might have thought I meant the second one, and not the first. Commented Jun 14, 2018 at 9:59
  • @ParhamDoustdar AFAIU make-process assumes an existing buffer-file-name leading to determine the current directory. But such assumption isn't justified when just creating a buffer. Commented Jun 14, 2018 at 10:58

The straightforward solution seems to be to simply wrap the call-process or make-process call with with-existing-directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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