Kungsgeten / ryo-modal

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

Vim style bindings - is there a way to put numerical argument between verb and text-object?' #18

Open hgersen opened 6 years ago

hgersen commented 6 years ago

The current macro-example in the readme to get vim-like verbs and text-objects is very neat and makes it easy to get close to Vim-style editing. In particular as it also works with numerical arguments in front, so the following grammar works:

<number> <command> <text object or motion>

However when I use Vim I tend to remember operations that apply to multiple text-objects with the number after the command. Simply because "delete 3 words" makes more sense as a sentence than "3 delete words". So I tend to use the grammar as

<command> <number> <text object or motion>

Any thoughts on whether there would be a way that allows keybindings that has the numerical arguments in front of the text objects or motion?

Kungsgeten commented 6 years ago

I don't think there's a way to do that with the normal Emacs keybinding scheme. It probably works in evil-mode, but they have "real" text objects and motions.

hgersen commented 6 years ago

This indeed works in evil-mode, but I was hoping that this aspect would be possible to replicate somehow using ryo-modal as this is the only bit I find missing (although I'm sure I can either get used to it or work around it).

hgersen commented 6 years ago

I think I figured out a work-around using a hydra as that code has the universal arguments parts from from the emacs code integrated. This makes a hydra work as expected for things like d3w.

Unfortunately doing this cleanly using a hydra for text-objects to be able to reuse it shows that the :then keyword added in response to #14 doesn't work as expected. The thing that goes wrong is that the command after :then gets executed immediately not when the hydra exits.

Code that shows that the :then doesn't work as expected:

(defun my-message ()
  (interactive)
  (message "called when entering hydra"))

(defhydra hydra-text-objects (:exit t :post (message "called after hitting w") )
  "A hydra for text objects"
  ("w" mark-word "to next word"))

(ryo-modal-keys
 (:norepeat t)
 ("g" hydra-text-objects/body :then '(my-message) )
 ("t" hydra-text-objects/body :name "select"))

btw) obviously using :post in the defhydra itself would work to implement this, but having :then work as expected would lead to far less duplication.

Kungsgeten commented 6 years ago

I don't think I can fix the issue with the hydras. Ryo would need to know that the command is a hydra command, and then somehow change the command based on the :then keyword. Sorry!

hgersen commented 6 years ago

For clarity the timing is actually not with the :defhydra in contrast to what I thought when I wrote the above. But I guess you had spotted that already. In any case it is mainly surprising behavior if one takes the :then literally.

btw) A hydra would end with "/body" in the function call, so it should be possible to detect it is a hydra call. Beyond that it is far from obvious and I doubt it is worth fixing.