0

I have this line in my init.el:

(global-set-key (kbd "C-c g") (lambda() (interactive) (find-file "~/Dropbox/myorgfiles")))

So when I type C-c g I get the directory contents of the myorgfiles folder. But I would like to be able to start typing and get search results for that pattern within that myorgfiles folder. How could I manage to do this? At the moment the individual keyboard strokes have different functions.

Drew
  • 77,472
  • 10
  • 114
  • 243
Emmanuel Goldstein
  • 1,014
  • 8
  • 18
  • So C-x C-f and start typing - what am I missing? – NickD Jul 05 '20 at 17:45
  • I see that C-x C-f is binded to helm-find-files, and actually that is the function I could use. Instead, my function above calls find-file, and this function does not allow for start typing. I just fixed my above function like this: (global-set-key (kbd "C-c g") (lambda() (interactive) (helm-find-files "~/Dropbox/myorgfiles"))), and it WORKS! – Emmanuel Goldstein Jul 06 '20 at 05:33

1 Answers1

3

As @NickD said in a comment, what you want is just to call find-file interactively. But you want it to do its thing in folder ~/Dropbox/myorgfiles.

So you just need to bind default-directory to ~/Dropbox/myorgfiles/.

(global-set-key (kbd "C-c g")
                (lambda ()
                  (interactive)
                  (let ((default-directory  "~/Dropbox/myorgfiles/"))
                    (call-interactively #'find-file))))
Drew
  • 77,472
  • 10
  • 114
  • 243