[Toybox] [PATCH] Ex commands in vi.c slightly improved + Error Fix

enh enh at google.com
Mon Sep 25 09:34:56 PDT 2023


On Sun, Sep 24, 2023, 22:45 Oliver Webb via Toybox <toybox at lists.landley.net>
wrote:

> I have been changing the ex command processor in vi.c to have things like
> line
> ranges, commands like g, v, d, and p (and s but I haven't gotten to
> even starting that yet), System commands and the ability to pipe text into
> them
> and put it back into your file, etc. I have a half finished version of
> line range
> implementation. But rather then submit that half finished version, I'll
> just submit
> the things required for that to work, along with some other small things
>
> The main thing is that strncmp() or just cmd[num] == 'char' (To find a
> command at a specific location)
> be used instead of strstr() (Which finds any mention of the string in the
> command)
>

i haven't looked at the patch, but the toybox strstart() function is often
useful for writing this kind of thing clearly.

Commands like ":%s/wq!/set nolist/g" would break otherwise.
>
> I added the ability to jump to lines with :[NUMBER], go to the bottom of
> the file with ":$" and delete lines with the d command,
> I know that these commands can be replicated in normal mode (the d command
> just calls run_vi_command("dd"))
> but when combined with things like the g command that I plan to submit in
> later patches
> They can add some power to the text processing capabilities of the editor
> (Example: ":g/\s*#/d" to delete all lines with only "#" style comments,
> ":%d" to clear the buffer)
>
> Other then that, I fixed a error that happens whenever ":w " is inputted
> by changing
> xrename() to rename(), preventing a early exit without properly setting
> the terminal
> back to normal beforehand.
>
> Last thing I did was replacing stuff like 0x20 with ' ', 0x0A with '\n',
> etc. To make it more clear we
> are checking for certain characters. '\t' Conveys more info then 0x09
> anyways even _if_
> you know the ASCII control codes and their hexadecimal values anyways.
> And stuff like "0x4" conveys nothing by being hexadecimal.


yeah, i've added a `CTRL()` macro in a few places to be able to make the
('d'-'@') a bit more intention-revealing. personally i'd like to promote
that to one of the global headers so we can just consistently write
CTRL('x') or whatever without worrying about mental arithmetic...

_______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20230925/d1d45c85/attachment.htm>


More information about the Toybox mailing list