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

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

Create a directory when saving a file


From: Juan-Leon
Subject: Create a directory when saving a file
Date: 28 Oct 2004 10:38:11 -0700

Hi,

Often (specially when saving mail attachments) I decide to create a
new directory for a file I want to save. I did not know how to make
this quickly from emacs, so I wrote this piece of code that maybe
somebody could find useful:

;; Use C-RET to create a directory from minibuffer while you are
;; writing the name (it does not matter if the name portion has been
;; already typed)
(add-hook 'minibuffer-setup-hook 'leon-add-keybinding-for-create-dir)

(defun leon-add-keybinding-for-create-dir()
  (interactive)
  (local-set-key [(control return)] 'leon-create-dir-from-minibuffer))

(defun leon-create-dir-from-minibuffer()
  (interactive)
  (save-excursion
    (beginning-of-line)
    (make-directory
     (file-name-directory
      (buffer-substring-no-properties (point) (point-max)))
     t)))

Press C-RET when you have typed the complete file name (and beffore
hitting RET key) and directory is created. Then press RET to
write/open the file. I wonder if this already exist, but it was faster
to write it that to search it.

Have fun!

Juan-Leon


reply via email to

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