-
Notifications
You must be signed in to change notification settings - Fork 16
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
Refactored the key binding system and implemented generic procedures #237
Conversation
My goal was to implement the key binding todos. - vim bindings - alternative bindings - register cmds before extension cmds - add subcommand invocation by name I found the current program to be fairly messy and hard to extend: for exmaple completely different handling builtin and extension bindings. Bindings were also tighly tied their with their functionality preventing e.g. key rebinding. It was also not clear how the certain key bound functinalities could be in the future extended to be supported from the commandline. I took the emacs approach where every functionality is a certain defined procedure which can, but doesn't have to, be bound to a key. Each can also be given a name so the future implementation of subcommands should be very easy. I chose the name 'procedure' as there was already a lot of ambiguity with the word 'command'. I kept all the existing key bindings, although I modified some to align them with vim. I also added a incomplete emacs profile just to showcase how bindings can be changed. One thing I didn't do was to register builtin bindings & procedures before running extension init as it involves a lot of unnecessary macros. Although I didn't look at the extension code in detail I have a feeling it could use a rework too. I wrote as capable yet simpler dll extension systems before. There might be some omissions in typing and error handling, some of the obsolete code might've been left in and admittedly the key binding system could be more sophisticated e.g. allow for registering key chords without additional logic and allow for binding some of the keys that are currently captured by the terminal but I don't want to spend more time on this before getting some feedback.
- Converted procedures & key-bindings to fixed size arrays instead of using darray. - Procedure array also now functions as a lookup table so iteration when e.g. invoking a procedure isn't necessary.
Thank you. So that CI tests pass (see e.g. https://github.com/liquidaty/zsv/actions/runs/11529370751/job/32097691822?pr=237 from above), could you please run |
CI is currently using clang-format 15.0.7. ./scripts/ci-run-clang-format.sh and, commit/push the changes. |
@iamazeem Should be all good now. |
My goal was to tackle the key binding todos.
I found the current program to be fairly messy and hard to extend: for example completely different handling builtin and extension bindings. Bindings were also tightly tied their with their functionality preventing e.g. key rebinding. It was also not clear how the certain key bound functionalities could be in the future extended to be supported from the commandline.
I took the emacs approach where every functionality is a certain defined procedure which can, but doesn't have to, be bound to a key. Each can also be given a name so the future implementation of subcommands should be very easy. I chose the name 'procedure' as there was already a lot of ambiguity with the word 'command'. procedures are meant to be called from key bindings, editor subcommand (vim ':', emacs 'C-x') and possible future .zsvsheet scripts or config. New procedures and key bindings can still be registered from within sheet and from extensions.
I kept all the existing key bindings, although I modified some to align them with vim. I also added an incomplete emacs profile just to showcase how bindings can be changed.
Current handling code was moved around but mostly unchanged as it was beyond the scope of this PR.
One thing I didn't do was to register builtin bindings & procedures before running extension init as it involves a lot of unnecessary macros. Although I didn't look at the extension code in detail I have a feeling it could use a rework too. I wrote as capable yet simpler dll extension systems before.
There might be some omissions in typing and error handling, some of the obsolete code might've been left in and admittedly the key binding system could be more sophisticated e.g. allow for registering key chords without additional logic and allow for binding some of the keys that are currently captured by the terminal but I don't want to spend more time on this before getting some feedback. I suggest starting the review from procedure.c/h files, key-bindings and app/sheet.c.