Kungsgeten / ryo-modal

Roll your own modal mode

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does prefix key support lambda?

WeissP opened this issue · comments

commented

So I want to add some lambda functions for the keys in the prefix key map, like:

  (ryo-modal-key
   "<escape>" '(("s" (lambda () (interactive) (insert "123")))
                ("b" ibuffer-list-buffers)))

But it shows that Error (use-package): ryo-modal/:config: Wrong type argument: listp, lambda

And then i want to add tag :then to make lambdas work, like:

  (ryo-modal-key
   "<escape>" '(("s" left-char :then '(left-char))
                ("b" ibuffer-list-buffers)))

But it seems like prefix key doesn't support tag :then?

Hi! Unfortunately lambdas can't be used as the target of bindings. The documentation is wrong here, since it says commands and interactive lambdas are commands. I'd like to support lambdas, but I'm not sure what name the generated function should have, so please leave a suggestion if you have any!

Regarding your second example it is a bit unintuitive when using prefix keys. Since the "target" here is already quoted, the :then list doesn't need to be quoted itself. So this works:

  (ryo-modal-key
   "<escape>" '(("s" left-char :then (left-char))
                ("b" ibuffer-list-buffers)))
commented

the :then list doesn't need to be quoted itself.

Oh you are right, thanks :)

About the lambdas i can define them like this:

  (ryo-modal-key
   "<escape>" '(
                ("p"  ignore
                 :then ((lambda () (interactive) (insert "&&&[IMG]pictures/.png"))) 
                 :name "insert karat pic")
                ("j"  xah-insert-paren))

It's ugly but it at least works.