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

Refactored the key binding system and implemented generic procedures #237

Merged
merged 7 commits into from
Oct 28, 2024

Conversation

br1tney5pear5
Copy link
Contributor

@br1tney5pear5 br1tney5pear5 commented Oct 22, 2024

My goal was to tackle 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 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.

br1tney5pear5 and others added 4 commits October 23, 2024 00:08
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.
@liquidaty
Copy link
Owner

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 clang-format -i for each C and header file that was touched?

@iamazeem
Copy link
Collaborator

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 clang-format -i for each C and header file that was touched?

CI is currently using clang-format 15.0.7.
After installing clang-format-15, and creating the symlink clang-format, run:

./scripts/ci-run-clang-format.sh

and, commit/push the changes.

@br1tney5pear5
Copy link
Contributor Author

@iamazeem Should be all good now.

@liquidaty liquidaty merged commit 1b36fcd into liquidaty:main Oct 28, 2024
10 checks passed
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

Successfully merging this pull request may close these issues.

3 participants