gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lisp to create dirs when using write-region and write-file.


From: Tom Wurgler
Subject: lisp to create dirs when using write-region and write-file.
Date: Tue, 30 Oct 2001 08:25:49 -0500 (EST)

I am all the time trying to write a region or a file to a non-existing
directory.  So here is some code to allow the creation of the dirs as
needed.  I like it alot, thought someone else may find it useful too.


Add to your .emacs:

(defvar allow-writes-to-create-dirs nil
  "If t, user can do a write-file or write-region even to non-existing paths.
All non-existing parent dirs are created.")

(defadvice write-file (before check-dirname-file activate)
  "If `allow-writes-to-create-dirs', create any nonexistent parent dirs needed."
  (if allow-writes-to-create-dirs
      (let ((dir (file-name-directory filename)))
        (if (not (file-exists-p dir))
          (make-directory dir t)))))

(defadvice write-region (before check-dirname-region activate)
  "If `allow-writes-to-create-dirs', create any nonexistent parent dirs needed."
  (if allow-writes-to-create-dirs
      (let ((dir (file-name-directory filename)))
        (if (not (file-exists-p dir))
          (make-directory dir t)))))

(setq allow-writes-to-create-dirs t)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]