Kungsgeten / ryo-modal

Roll your own modal mode
MIT License
222 stars 14 forks source link

Weird behavior with :name and objed #25

Closed jhenahan closed 5 years ago

jhenahan commented 5 years ago

Not totally sure where to go looking for this one, as it's quite strange.

I've recently been trying to port my existing RYO bindings for expand-region to use objed.

The following work:

(bind-key "H-r w" objed-word-object)
(ryo-modal-keys
       ("m"
        (("w" "H-r w"))
        :name "region"))
(ryo-modal-keys
       ("m"
        (("w" objed-word-object))
        :name "region"))

But if I add :name on either of those bindings, all the docstrings are right but the key does nothing. I can't for the life of me figure out why. Any ideas?

Kungsgeten commented 5 years ago

Hi! Sorry for the very late reply. I'm no objed user myself (even though I think it looks interesting). I looked at its code and it seems like objed-word-object (and other objects) are defined with a macro named objed-define-object. The way RYO works, when modifying commands (adding names, etc), is that it creates a new command and in its definition use call-interactively to call the original command. In this case the original command is objed-word-object.

I tried objed and tried to used M-x eval-expression with (call-interactively 'objed-word-object), but that did nothing. @clemera Do you know why call-interactively doesn't work with objed objects?

clemera commented 5 years ago

@Kungsgeten You would have to adjust the value of real-this-command. This is to guard against accidental activation internally. You could do:

(let ((real-this-command 'objed-word-object))
  (call-interactively 'objed-word-object))
Kungsgeten commented 5 years ago

@clemera Thanks! I've updated so that real-this-command is set before calling interactively. Hopefully this doesn't break anything else ;)

jhenahan commented 5 years ago

Awesome! I'll give it a look and see if that gets me any further. Thanks!

clemera commented 5 years ago

If there are further problems integrating with objed let me know, I'm glad to help!