[Toybox] [PATCH] vi.c: line ranges, fixed line gotos, CTRL-D, etc

Jarno Mäkipää jmakip87 at gmail.com
Sun Oct 1 05:50:19 PDT 2023


Hello Oliver

ex mode command parsing is not something that has been designed
carefully. Its more of hack to accept write file and exit commands in
order to make editor somewhat usable. Even the vi mode command
execution is not very good. At least one issue is that it has function
dispatch table that handles most of the commands and also switch case
that handles some... It should probably have only one or the other and
not both...

I see that you added some direct calls to run_vi_cmd() in ex mode and
other places. I am not sure is that going to work out since run_vi_cmd
was supposed to be only called when in vi mode. I don’t really use ex
commands other than r, w, q so I don’t really have idea how they work.
But if you wish to implement some commonly used ones, you could try to
implement better parsing logic for ex commands so that they are parsed
similar logic as vi mode: do movement, execute action based on
movement, repeat if counter has been given.

If you plan to add features you could add some tests into /tests/vi.test

While tests don’t cover how buffer looks visually in terminal
emulator, it can cover how buffer is edited and stored on output file.
This can detect at least some regressions.

-Jarno

On Sun, Oct 1, 2023 at 7:55 AM Oliver Webb via Toybox
<toybox at lists.landley.net> wrote:
>
> Heya, I have been working a few days on vi.c and have managed to
> add a few things. I have a barely-working version of the "g" command
> which I have ultimately decided to omit from this patch.
>
> First thing I added was line ranges, the ability to specify
> stuff like "10,45d" and have it delete lines 10-45, and also "%"
> so you can do stuff like "%d" (and "%s" if I can get that working)
> It only supports plain numbers and doesn't do anything fancy like "+NUMBER" yet.
> To get line ranges to work properly, The page has to be re-drawn or else the frame
> breaks (At least while deleting lines, the only thing I can do with these features as of now)
>
> Also, after some testing I realized that the line gotos that I
> implemented didn't work in some circumstances, such as at the
> top or bottom of a file and/or after moving around in a file using
> the cursor keys. I don't know why it does this... my code called
> vi_go() and after some testing, calls it in the exact same
> way that the "G" command does. I fixed this by making all line goto's run the
> "G" command and let that do whatever it does to prevent that.

This is where unit tests would be useful. To test all the corner
cases. There might be also some underlying bug relating to arrow keys
since they are handled bit different than some other commands.

>
> I have added in the support for "Go down half a page" CTRL-D,
> and added in the CTL macro after
> <enh at google.com> mentioned it. and replaced "27" with "\e"
>
> - Oliver Webb <aquahobbyist at proton.me>
> _______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net


-Jarno


More information about the Toybox mailing list