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

1

1

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.

Fluctuate answered 27/1, 2015 at 16:24 Comment(0)
S
1

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"))
Secundine answered 27/1, 2015 at 16:35 Comment(2)
Recursive file search isn't a straightforward task, if you want to be fast. See projectile, for instance.Secundine
After edit, this is exactly what I wanted, thanks! =]Fluctuate

© 2022 - 2024 — McMap. All rights reserved.