abo-abo / hydra

make Emacs bindings that stick around
1.84k stars 112 forks source link

Aliases for defhydra #397

Open enisozgen opened 3 years ago

enisozgen commented 3 years ago

Hello Oleh,

First thanks for this awesome tool which increase Emacs usability.

I want to make some request related with hydra.

TLDR

Giving aliases for auto generated interactive functions can make the tool more user friendly.

Explanation

Every defhydra functions like this

(defhydra hydra/feature-request ()
  ("i" (insert "foo") "insert foo")
  ("a" (progn
         (org-agenda nil "t")
         (message "Agenda is ready"))
   "Open agenda and say agenda is ready"
   :exit t)
  ("mcs" (progn
           (more)
           (if something
               (complex)
             (stuff)))
   "More complex stuff"
   :exit t))

Produces some interactive Lambda functions which are visible in M-x. Even they are ready to serve for their purpose. I must say that those lambda function names are not human friendly since they are not memorable. Therefore, I guess nobody uses it via M-x.

Picture

image

We can always define different aliases like in below or we can use standalone functions in hydra but I have better idea.

(defalias 'insert-foo         'hydra/feature-request/lambda-i)
(defalias 'my-agenda-todo     'hydra/feature-request/lambda-a-and-exit)
(defalias 'more-complex-stuff 'hydra/feature-request/lambda-mcs-and-exit)

My request

It can be good to define alias in the defhydra functions so users can reach by using aliases in M-x buffer

Ex:

((defhydra hydra/feature-request ()
  ("i" (insert "foo")
   :alias "insert-foo"
   "insert foo")
  ("a" (progn
         (org-agenda nil "t")
         (message "Agenda is ready"))
   :exit t
   :alias "my-agenda-todo"
   "Open agenda and say agenda is ready")
  ("mcs" (progn
           (more)
           (if something
               (complex)
             (stuff)))
   :alias "more-complex-stuff"
   :exit t
 "More complex stuff"))

Best Regards, Enis