2

I want to use hydra (in Emacs 24.5.1 on Windows 10) to create a pop-up list of directories that I often use. Selecting one of the directories in the list, using a single key, should cause it to open in Dired.

For example, the plan is that once the hydra menu is active hitting "a" will open in "g:/foo/bar/grob" and hitting "b" will open "c:/longername/short/utilities/morestuff/utilities" and so on.

I have run into difficulties with something I thought would have been obvious, namely opening a buffer in Dired. My idea was to have the hydra trigger the relevant Dired command, that I assumed would exist and look like:

dired-read-buffer "c:/emacs"

As far as I can see, there is no such command in the section in the GNU Emacs manual on invoking Dired. There is more than one way to interactively call Dired, but I want something more programmatic.

How can I implement this?

SlowLearner
  • 245
  • 2
  • 6
  • 2
    Implement? What is there to implement? `C-h f dired` tells you all you need to know: the function (command) accepts the directory name as argument. **Ask Emacs.** – Drew Oct 11 '15 at 18:19
  • Your comment is basically at the same level as [LMGTFY](http://meta.stackexchange.com/questions/15650/ban-lmgtfy-let-me-google-that-for-you-links) responses. As my question makes quite clear, I *did* read the parts of the help system that I thought would/should contain the information. No, I didn't think of using `C-h f dired`, perhaps because unlike yourself I do not live in Emacs, I just visit every other week. Fortunately the question was answered by somebody else so that the next person who comes looking will hopefully find the answer - which is what SO is for. – SlowLearner Oct 12 '15 at 20:29
  • 1
    That is what SO is for, yes. But what *Emacs* is for, as part of its proclaimed raison d'etre (the *self-documenting* editor), is to answer this kind of question directly. There is nothing wrong with asking on SO, certainly. But if you want to learn Emacs, the best advice I can give is to **ask Emacs**, and to learn to ask it better. You won't regret it, I'm guessing. Just a suggestion. – Drew Oct 13 '15 at 02:09

1 Answers1

6

You can pass the directory name to dired:

(defhydra hydra-dired (:exit t)
  "dired"
  ("w" (dired "~/Downloads") "Downloads")
  ("d" (dired "~/Documents") "Documents"))
(global-set-key (kbd "C-c C-d") 'hydra-dired/body)
abo-abo
  • 13,943
  • 1
  • 29
  • 43