Kungsgeten / ryo-modal

Roll your own modal mode
MIT License
224 stars 16 forks source link

Usage with (cdr (assoc "wq" evil-ex-commands)) #44

Closed shadowrylander closed 3 years ago

shadowrylander commented 3 years ago

Hello!

I would like some help in configuring your package, via use-package, to run a command from the evil-ex-commands alist, using ("ll" (cdr (assoc "wq" evil-ex-commands))); however, I'm getting the Error (use-package): ryo-modal/:config: Wrong type argument: listp, cdr error. Here is the whole ryo-modal + use-package code I'm using:

    (use-package ryo-modal
        :demand t
        :general
            (:keymaps 'override
                (general-chord "kk") 'start-ryo)
        :config
            (ryo-modal-keys
                ;; First argument to ryo-modal-keys may be a list of keywords.
                ;; These keywords will be applied to all keybindings.
                (:norepeat t)

                ;; Adapted From The Comments:
                ;; Answer: https://emacs.stackexchange.com/a/21364
                ;; User: https://emacs.stackexchange.com/users/8578/pyrocrasty
                ;; ("pp" save-buffers-kill-emacs)
                ;; ("pp" (cdr (assoc "q" evil-ex-commands)))
                ;; ("oo" save-buffer)
                ;; ("oo" (cdr (assoc "w" evil-ex-commands)))

                ("ll" (cdr (assoc "wq" evil-ex-commands)))

                ;; ("qq" kill-emacs)
                ;; ("qq" (cdr (assoc "q!" evil-ex-commands)))
                ("kk" start-ryo)
            )
        :straight
            (:host github :repo "kungsgeten/ryo-modal" :branch "master"))

Any help would be greatly appreciated!

Kungsgeten commented 3 years ago

I think the cdr part might be quoted inside the macro, and therefore is evaluated as a list instead of the result of the function call. Try using ryo-modal-key instead and see if that works.

shadowrylander commented 3 years ago

I attempted the following, but it gave me the same error:

(ryo-modal-key "ll" '(cdr (assoc "wq" evil-ex-commands)))

I also tried an interactive lambda, but that gave me the same error with lambda instead of cdr.

shadowrylander commented 3 years ago

Should I perhaps put them in a let statement and then assign them to the keys?

shadowrylander commented 3 years ago

Fascinating; so it worked after I did the following:

  1. Wrap ryo-modal-key[s] in a let statement, and moving the cdr statement to a let variable, then
  2. Move it to the config section of evil-mode

I think this should allow me to use ryo-modal's use-package keyword, correct?

Kungsgeten commented 3 years ago

I'm not sure, I haven't used the use-package keyword myself. However I think that you shouldn't quote the cdr statement, since I guess you're trying to get an element from the evil-ex-commands alist. Does the following work?

(ryo-modal-key "ll" (cdr (assoc "wq" evil-ex-commands)))

shadowrylander commented 3 years ago

Ah; yes, yes it does. However, I'm still getting a Error (use-package): ryo-modal/:config: Symbol’s value as variable is void: evil-ex-commands error when putting it in the ryo-modal config section; putting it in the evil-mode section works. I do want to implement it using the :ryo keyword, though, and none of the following work; the first gives no error, but just flat out doesn't work, while the latter two are giving me the same errors as before:

:ryo
    (let ((wq (cdr (assoc "wq" evil-ex-commands))))
        ("ll" wq))

:ryo ("ll" (cdr (assoc "wq" evil-ex-commands)))

:ryo ("ll" '(cdr (assoc "wq" evil-ex-commands)))
shadowrylander commented 3 years ago

Oh, and neither does this work; same effect as the first example in the previous message:

:ryo
    (let ((wq (cdr (assoc "wq" evil-ex-commands))))
        ("ll" 'wq))
Kungsgeten commented 3 years ago

The reason for the Error (use-package): ryo-modal/:config: Symbol’s value as variable is void: evil-ex-commands is probably that ryo-modal is loaded before evil-ex-commands is known.

shadowrylander commented 3 years ago

I surmised as much; however, I still cannot use your use-package keyword.

shadowrylander commented 3 years ago

This user on reddit mentions using the eval method from your prefix keys section; could you possibly explain that to me? I don't quite understand it.

shadowrylander commented 3 years ago

The aforementioned reddit user gave me this snippet that works:

(eval
 `(ryo-modal-keys
   ("l l" ,(general-simulate-key ":wq <RET>") :first '(evil-normal-state) :name "wq")
   ("l p" ,(general-simulate-key ":q <RET>") :first '(evil-normal-state) :name "q")
   ("l o" ,(general-simulate-key ":w <RET>") :first '(evil-normal-state) :name "w")
   ("l q" ,(general-simulate-key ":q! <RET>") :first '(evil-normal-state) :name "q!"))

Could you show me how to convert this to a use-package keyword format, i.e. using :ryo?

Kungsgeten commented 3 years ago

I don't use the :ryo keyword in use-package myself, and if I remember correctly it was submitted as a pull request by another user. So I'm sorry, I can not.

shadowrylander commented 3 years ago

Ah; that is understandable. I may have a solution for the keyword on hand, so I'll post that here in a little bit if it works!

shadowrylander commented 3 years ago

Unfortunately, the keyword solution didn't work. But thank you kindly for all the help! I'll go ahead and close this, then!