commit 1e4bc498ceeced65a0c628df0ea0fbb6a57db10a from: Omar Polo date: Sun Jul 15 18:29:03 2018 UTC Closing #1 -- Also C-w now works well with multi-byte string commit - c392d7270046bfa46e5891c9b6f4c731fbd56a4d commit + 1e4bc498ceeced65a0c628df0ea0fbb6a57db10a blob - 266875cba3b98cf503e950e78d53e73adc8e9458 blob + b24e17704aa3eb3d4d86402c260bd355b9c37a37 --- README.md +++ README.md @@ -82,11 +82,6 @@ should be enough. - Improve the filtering process of the completions - - Improve UTF8 support - - The whole UTF8 support is still kinda naïve and should definitely - be improved. - - Opacity support ## Scripts blob - 30172d531c4e6ecb5843222e3dd95f94a1ce98f2 blob + 8a923b24966f085bec28c4d164617200f57f98fc --- mymenu.1 +++ mymenu.1 @@ -201,9 +201,6 @@ with the % sign is supplied, then the default value fo will be treated as a percentage. Since this is a misuse of the resources this behavior isn't strictly considered a bug. .It -C-w (delete last word) does not work well with multi-byte string. The -whole UTF-8 support is still kinda naïve and should be improved. -.It Keep in mind that sometimes the order of the options matter. First are parsed (if any) the xrdb options, then the command line flags .Sy in the provided order! blob - 11461dc55c32d53b0ec151ac8ee391cf9ef1ade8 blob + 6ecbe3714c2f20f59d4a1877e065a438678f074f --- mymenu.1.md +++ mymenu.1.md @@ -299,9 +299,6 @@ C-i will be treated as a percentage. Since this is a misuse of the resources this behavior isn't strictly considered a bug. -* C-w (delete last word) does not work well with multi-byte string. The - whole UTF-8 support is still kinda naïve and should be improved. - * Keep in mind that sometimes the order of the options matter. First are parsed (if any) the xrdb options, then the command line flags **in the provided order!** blob - 637c9fc52c07bdb82eb7c29d6845deb53a0982a0 blob + f5789da33349677611233547d7155d13b669856e --- mymenu.c +++ mymenu.c @@ -305,13 +305,13 @@ int pushc(char **p, int maxlen, char c) { return maxlen; } - // remove the last rune from the *utf8* string! This is different from -// just setting the last byte to 0 (in some cases ofc). -void popc(char *p) { +// just setting the last byte to 0 (in some cases ofc). Return a +// pointer (e) to the last non zero char. If e < p then p is empty! +char* popc(char *p) { int len = strlen(p); if (len == 0) - return; + return p; char *e = p + len - 1; @@ -325,8 +325,31 @@ void popc(char *p) { if (((c & 0x80) && (c & 0x40)) || !(c & 0x80)) break; } while (e >= p); + + return e; } +// remove the last word plus trailing whitespaces from the give string +void popw(char *w) { + int len = strlen(w); + if (len == 0) + return; + + bool in_word = true; + while (true) { + char *e = popc(w); + + if (e < w) + return; + + if (in_word && isspace(*e)) + in_word = false; + + if (!in_word && !isspace(*e)) + return; + } +} + // If the string is surrounded by quotes (`"`) remove them and replace // every `\"` in the string with `"` char *normalize_str(const char *str) { @@ -1477,25 +1500,7 @@ int main(int argc, char **argv) { break; case DEL_WORD: { - // `textlen` is the lenght of the allocated string, not the - // lenght of the ACTUAL string - int p = strlen(text) -1; - if (p > 0) { // delete the current char - text[p] = 0; - p--; - } - - // erase the alphanumeric char - while (p >= 0 && isalnum(text[p])) { - text[p] = 0; - p--; - } - - // erase also trailing white spaces - while (p >= 0 && isspace(text[p])) { - text[p] = 0; - p--; - } + popw(text); update_completions(cs, text, lines, first_selected); break; }