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

Support for repeat-map #552

Open
ashlineldridge opened this issue Aug 17, 2023 · 2 comments
Open

Support for repeat-map #552

ashlineldridge opened this issue Aug 17, 2023 · 2 comments

Comments

@ashlineldridge
Copy link

ashlineldridge commented Aug 17, 2023

Does general.el provide any support for Emacs's repeat-map? If not, would you consider supporting it? (I understand there is a rewrite coming which may affect appetite for new features.)

general.el does have a :repeat property but AFAICT this only applies to Evil-style keybindings. I would love to be able to specify something like the following:

(general-def 'flymake-mode-map
  :prefix "M-i"
  "ld" #'flymake-show-buffer-diagnostics
  "lD" #'flymake-show-project-diagnostics
  "ln" #'flymake-goto-next-error :repeat t
  "lp" #'flymake-goto-prev-error :repeat t)

And have the :repeat property result in the flymake-goto-next-error and flymake-goto-prev-error be added to repeat-map such that the n and p keys could repeatedly invoke them.

Currently I'm using general-def (or a custom definer) to bind the keys to the regular keymap and then duplicating the repeatable keys in another keymap that I then map into repeat-map and it feels like there should be a more efficient way of doing this using general.el (if there already is a way, please point me to it).

Thank you.

@noctuid
Copy link
Owner

noctuid commented Aug 20, 2023

I don't plan an adding any new significant features to general but would accept a PR. There are various packages meant to simplify this (define-repeat-map, repeaters, etc.), though I haven't tried any of them and don't know if any will simplify your use case.

Currently, yes, it will have to be two steps. Maybe a slightly better alternative if the repeat map is a subset of what you want to bind under M-i l in this example would be to first bind M-i l to a new keymap that inherits from your repeat map or copies it and then bind only the additional keys in that.

@m4xxed
Copy link

m4xxed commented Oct 17, 2024

  (add-to-list 'general-extended-def-keywords ':repeat-map)
  (defun general-extended-def-:repeat-map (_state _keymap _key edef kargs)
    "Use `put` to set the :repeat-map property for commands.
    The repeat property should be specified with :repeat-map in either EDEF or KARGS."
    (general-with-eval-after-load 'evil
      (let ((repeat-map-property (general--getf edef kargs :repeat-map))
            (command (cl-getf edef :def)))
        (put command 'repeat-map repeat-map-property))))

For me, this just works...

Example usage:

(use-package emacs
    :after org
    :general-config
    ( :keymaps '(outline-mode-map
                 outline-minor-mode-map)
      :states '(normal visual insert)
      :repeat-map 'structural-movement-map
      [remap structural-up] 'my/outline-backward-heading
      [remap structural-down] 'my/outline-forward-heading
      [remap structural-left] 'outline-up-heading
      [remap structural-right] 'my/outline-down-heading))

structural-* are just placeholders in a generic keymap called structural-movement-map and these placeholders get remapped by whatever command I want to use for structural / outline movement in a mode...

I don't know whether this is a good or useful way... and I am looking into a way to make remapping commands inherit the :repeat-map property from the command they are remapped onto... but haven't been successful yet. So yeah, might work for you, might not...

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

3 participants