abo-abo / hydra

make Emacs bindings that stick around
1.85k stars 113 forks source link

Jumping to register bookmarks #33

Closed srid closed 9 years ago

srid commented 9 years ago

I'm currently have bookmarks for frequently accessed files:

  (mapcar
   (lambda (r)
     (set-register (car r) (cons 'file (cdr r))))
   '((?i . "~/.emacs.d/Srid.org")
     (?p . "~/Dropbox/Notes/Productive.org")
     (?w . "~/Dropbox/Notes/Work.org")))

Is this something I can use a hydra for (to save keystrokes)? Specifically I want to invoke C-M-j and hit p or w to directly go to the file. Please let me know if there is a better place to ask this kind of questions instead of opening a GitHub issue.

srid commented 9 years ago

To clarify, I would like to know if I can avoid having to hardcode the register enumeration here:

      (global-set-key
       (kbd "C-M-j")
       (defhydra hydra-jump-to-register ()
         "scroll"
         ("j" (lambda () (interactive) (jump-to-register ?i)) "Srid.org" :color blue)
         ("p" (lambda () (interactive) (jump-to-register ?p)) "Productive.org" :color blue)
         ("w" (lambda () (interactive) (jump-to-register ?w)) "Work.org" :color blue)))

i.e., can the hydra automatically populate the actions based what's in the emacs register?

abo-abo commented 9 years ago

Please let me know if there is a better place to ask this kind of questions instead of opening a GitHub issue.

A Github issue is the place to ask, since it's very easy to paste snippets here and it generates sort of a FAQ.

Here's something you can try:

(global-set-key
 (kbd "C-M-j")
 (defhydra hydra-bmk ()
   ("i" (find-file "~/.emacs.d/Srid.org") "Srid")
   ("p" (find-file "~/Dropbox/Notes/Productive.org") "Productive")
   ("w" (find-file "~/Dropbox/Notes/Work.org") "Work")))

See my post on how I'm dealing with bookmarks. I think that approach is more flexible than using defhydra.

srid commented 9 years ago

Ah, yes. This is what I ended up doing just now before seeing your comment, except I had to wrap find-file with lambda and (interactive).