Skip to content

Non-recursive Macros #198

Description

@nilrem3

introduction

Vim/neovim macros can either be recursive (default) or non-recursive. Non-recursive macros do not trigger other macros during their execution, instead falling back on the default (non-macro) behavior of any inputs they contain. From what I can tell, modalkit macros are always recursive (the macro_command function on the KeyManager struct simply puts the keys contained by the macro action right back into the keystack).

I have some ideas about how non-recursive macros might be implemented and I will probably try to write a PR for this at some point, but I wanted to get some high level feedback before I get too far in.

plan

Here is my basic plan for how I would implement this, in case anyone has suggestions about how it should be done differently. Here are the changes I am planning to make:

  1. Create two new types of macro action corresponding to beginning and ending a non-recursive macro. These would probably be handled in KeyManager::macro_command.
  2. Treat macro actions as unmapped when we are in a non-recursive macro. This could either be by having steps that contain macros return true from is_unmapped, or perhaps by having them return 0 actions causing ModalMachine.step to ignore them.

questions

First of all, is modalkit even the correct place to implement this functionality? It's possible that it would be better to simply delegate this behavior to be implemented by each application that uses modalkit & wants it. This is my first time working on any modalkit-related projects so I'm not really sure what the recommendation here is.

Second, the state (whether we are in a non-recursive macro) needs to be stored somewhere. I can't tell where the best place to do that would be, any suggestions would be appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions