Marcin Borkowski, mbork, posted a handy snippet of Elisp to automatically create parent directories if they don’t already exist. It’s similar to mkdir -p
in that if intermediate directories don’t already exist they are created for you.
That turns out to be easy because the Elisp function make-directory
will do this if the second argument is non-nil. All you need do add a hook function to find-file-not-found-functions
that calls make-directory
with the required non-nil second argument. See mbork’s post for an example of the simple code needed to do this.