Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hgersen opened this issue Jan 18, 2018 · 5 comments

Comments

@hgersen
Copy link
Contributor

hgersen commented Jan 18, 2018

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
Copy link
Owner

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
Copy link
Contributor Author

hgersen commented Jan 19, 2018

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
Copy link
Contributor Author

hgersen commented Jan 21, 2018

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
Copy link
Owner

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
Copy link
Contributor Author

hgersen commented Jan 25, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants