martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.19k stars 259 forks source link

Print keybindings starting with space correctly #1111

Closed MaxGyver83 closed 11 months ago

MaxGyver83 commented 11 months ago

Bug fix for #1060.

rnpnr commented 11 months ago

Hi Max, thanks for the patch!

This fixes one of the issues listed in #1060 but doesn't replace any additional spaces with . Are you able to address that as well? Maybe a local 18 char buffer to copy key into while replacing ` with␣`,

MaxGyver83 commented 11 months ago

Hi Randy, sure. I didn't think about this.

I have updated this pull request. I hope it's not too complicated. The main difficulty is that spaces (1 byte each) get replaced with which is 3 bytes but only 1 character. I have limited the number of space replacements to 3 because otherwise the destination string might grow in an unpredictable way.

rnpnr commented 11 months ago

Definitely a little more complicated then I was expecting but its partially because I forgot how to count bytes. It's on the right track though so I'll leave some comments inline.

rnpnr commented 11 months ago

Applied! Thanks for your work getting this patch in shape!

erf commented 11 months ago

I get the following warning when building the latest version with this change:

In file included from sam.c:1813:
./vis-cmds.c:663:34: warning: field width should have type 'int', but argument has type 'unsigned long' [-Wformat]
        return text_appendf(data, "  %-*s\t%s\n", 18+invisiblebytes, buf, (char*)value);
                                     ~~~^         ~~~~~~~~~~~~~~~~~
./vis-cmds.c:673:34: warning: field width should have type 'int', but argument has type 'unsigned long' [-Wformat]
        return text_appendf(data, "  %-*s\t%s\n", 18+invisiblebytes, buf, desc ? desc : "");
MaxGyver83 commented 11 months ago

I get the following warning when building the latest version with this change:

In file included from sam.c:1813:
./vis-cmds.c:663:34: warning: field width should have type 'int', but argument has type 'unsigned long' [-Wformat]
        return text_appendf(data, "  %-*s\t%s\n", 18+invisiblebytes, buf, (char*)value);
                                     ~~~^         ~~~~~~~~~~~~~~~~~
./vis-cmds.c:673:34: warning: field width should have type 'int', but argument has type 'unsigned long' [-Wformat]
        return text_appendf(data, "  %-*s\t%s\n", 18+invisiblebytes, buf, desc ? desc : "");

Oh, looks like I missed this. I'll change the type of invisiblebytes to int!

rnpnr commented 11 months ago

Fixed in 599ced0. Sorry about that I don't know how I missed it.