From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: handle multibyte chars in compset -p/-s
Date: Mon, 09 Oct 2017 11:42:20 +0200 [thread overview]
Message-ID: <17691.1507542140@thecus.kiddle.eu> (raw)
In-Reply-To: <22320.1507334630@thecus.kiddle.eu>
On 7 Oct, I wrote:
> Incidentally, while pondering such a solution, I noticed that
> compset -p is removing bytes rather than characters to IPREFIX which
> would have been useful in this case but should be corrected.
Having further checked uses of compset -p, I'm satisfied that compset -p
and -s should be handling multibyte characters so this is a patch to do
that. Is mb_metacharlenconv and backwardmetafiedchar as used here the
best way to do that?
Oliver
diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c
index 68bdf2332..16f48c958 100644
--- a/Src/Zle/complete.c
+++ b/Src/Zle/complete.c
@@ -934,19 +934,45 @@ do_comp_vars(int test, int na, char *sa, int nb, char *sb, int mod)
}
case CVT_PRENUM:
case CVT_SUFNUM:
- if (!na)
- return 1;
- if (na > 0 &&
- (int)strlen(test == CVT_PRENUM ? compprefix : compsuffix) >= na) {
- if (mod) {
- if (test == CVT_PRENUM)
- ignore_prefix(na);
- else
- ignore_suffix(na);
- return 1;
- }
+ if (na < 0)
return 0;
+ if (na > 0 && mod) {
+#ifdef MULTIBYTE_SUPPORT
+ if (isset(MULTIBYTE)) {
+ if (test == CVT_PRENUM) {
+ const char *ptr = compprefix;
+ int len = 1;
+ int sum = 0;
+ while (*ptr && na && len) {
+ wint_t wc;
+ len = mb_metacharlenconv(ptr, &wc);
+ ptr += len;
+ sum += len;
+ na--;
+ }
+ if (na)
+ return 0;
+ na = sum;
+ } else {
+ char *end = compsuffix + strlen(compsuffix);
+ char *ptr = end;
+ while (na-- && ptr > compsuffix)
+ ptr = backwardmetafiedchar(compsuffix, ptr, NULL);
+ if (na >= 0)
+ return 0;
+ na = end - ptr;
+ }
+ } else
+#endif
+ if ((int)strlen(test == CVT_PRENUM ? compprefix : compsuffix) >= na)
+ return 0;
+ if (test == CVT_PRENUM)
+ ignore_prefix(na);
+ else
+ ignore_suffix(na);
+ return 1;
}
+ return 1;
case CVT_PREPAT:
case CVT_SUFPAT:
{
next prev parent reply other threads:[~2017-10-09 9:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-07 0:03 PATCH: _arguments sets mixing rest/option arguments Oliver Kiddle
2017-10-09 9:42 ` Oliver Kiddle [this message]
2017-10-09 9:50 ` PATCH: handle multibyte chars in compset -p/-s Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=17691.1507542140@thecus.kiddle.eu \
--to=okiddle@yahoo.co.uk \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).