[Bjonnh.net]# _

Article / Creating folders in helm when saving a file >


category computer tags emacs helm notmuch

I use Notmuch to manage my emails (and that’s just wonderfully fast) and use the Emacs frontend for it. But when I wanted to save attachements, it was not that easy to create folders. I had to exit the save, open a terminal, a dired or whatever create the folder… I use Helm for managing completion in emacs (and that’s a nice piece of software too).

To avoid that and with the help of Sacha Chua, I managed to add a shortcut in helm read file:

(setq enable-recursive-minibuffers t)
(minibuffer-depth-indicate-mode 1)
(define-key helm-read-file-map (kbd "C-c c") 'my-helm-make-folder)
(defun my-helm-make-folder (str)
  "Make folders from helm save"
  (interactive 
    (list
      (read-from-minibuffer "Create folder: "
        (minibuffer-contents-no-properties) nil nil nil)))
  (make-directory str t)
)

You have to enable the minibuffer recursive mode (and I added the recursive counter too) for it to work as it asks you for the creation of the folder.

By removing the /interactive/ arguments and function arguments, it will create the folder directly without asking and you will be able to avoid activating the /minibuffer recursive mode/ (I wonder why it’s not activated by default you can mail me).