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

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

Re: Create a directory when saving a file


From: Kevin Rodgers
Subject: Re: Create a directory when saving a file
Date: Fri, 29 Oct 2004 10:10:18 -0600
User-agent: Mozilla Thunderbird 0.8 (X11/20040916)

Kevin Rodgers wrote:
> That function isn't very useful, and you might want to restrict the
> keybinding to commands that are reading file names:
>
> (add-hook 'minibuffer-setup-hook
>           (lambda ()
> (when (eq minibuffer-completion-table 'read-file-name-internal)
>               (local-set-key [(control return)]
>                              'leon-create-dir-from-minibuffer))))

Better would be:

(add-hook 'minibuffer-setup-hook
          (lambda ()
            (when minibuffer-completing-file-name
              (local-set-key [(control return)]
                             'minibuffer-make-directory))))

> That's a useful command.  But I think since it's got "minibuffer" in its
> name you may as well use the utility function provided to get the
> minibuffer's text, and I don't know that you need to discard any text
> properties from the string before you pass it to file-name-directory or
> make-directory (so I've left the -no-properties part off):
>
> (defun leon-create-dir-from-minibuffer()
>   (interactive)
>   (make-directory (file-name-directory (minibuffer-contents)) t))

Better would be:

(defun minibuffer-make-directory ()
  "*Create the directory named from the minibuffer contents.
Also create any nonexistent parent directories."
  (interactive)
  (let* ((file (minibuffer-contents))
         (directory (if (equal (file-name-as-directory file) file)
                        file
                      (file-name-directory file))))
    (make-directory directory t)))

--
Kevin Rodgers


reply via email to

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