Search code examples
emacselispemacs-helm

emacs ow can I helm-find with default directory pre-specified?


I use emacs for notes mainly. All my notes are in: ~/Dropbox/Uni/Notes

I want to tie a keyboard shortcut (e.g C-f12) to do a helm-find that always starts in the above dir irrelevant of the source buffer.

I have tried:

(global-set-key (kbd "C-<f2>") (lambda () (interactive) (helm-find "~/Dropbox/Uni/Notes/")))

But when I run it, it still prompts me for 'DefaultDirectory' which is usually the same as the current buffer.

?

[edit]
I made a hack-around:

(global-set-key (kbd "<C-f2>")
    (lambda ()
      (interactive)
      (find-file "~/Dropbox/Uni/Notes/leo.org")
      (helm-find nil)))

That opens a file and then when I do a helm-find, it's relative to leo.org's location. But a better solution would be preferred.

[edit] Below solution works perfectly.


Solution

  • Here you go:

    (defmacro helm-find-note (dir)
      `(defun ,(intern (format "helm-find-note-%s" dir)) ()
         (interactive)
         (let ((default-directory ,dir))
           (helm-find nil))))
    
    (global-set-key (kbd "C-M-3") (helm-find-note "~/Downloads"))