From: Mikael Magnusson <mikachu@gmail.com>
To: zsh-workers@zsh.org
Subject: PATCH 1/2: Fix comments for UNIQCON/ALL
Date: Sat, 26 Mar 2022 02:40:30 +0100 [thread overview]
Message-ID: <20220326014030.2802-1-mikachu@gmail.com> (raw)
In-Reply-To: <CAHYJk3QcMJ+cyoKBAbZqT1xE-LFmyT9yBaE==zmkiKymE-5MFw@mail.gmail.com>
Hopefully this can save future generations some confusion.
---
Src/Zle/comp.h | 6 +++---
Src/Zle/compcore.c | 8 +++++++-
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/Src/Zle/comp.h b/Src/Zle/comp.h
index 0c5fbd4f00..a8480c2bac 100644
--- a/Src/Zle/comp.h
+++ b/Src/Zle/comp.h
@@ -85,8 +85,8 @@ struct cmgroup {
#define CGF_NOSORT 1 /* don't sort this group */
#define CGF_LINES 2 /* these are to be printed on different lines */
#define CGF_HASDL 4 /* has display strings printed on separate lines */
-#define CGF_UNIQALL 8 /* remove all duplicates */
-#define CGF_UNIQCON 16 /* remove consecutive duplicates */
+#define CGF_UNIQALL 8 /* remove consecutive duplicates (if neither are set, */
+#define CGF_UNIQCON 16 /* don't deduplicate */ /* remove all dupes) */
#define CGF_PACKED 32 /* LIST_PACKED for this group */
#define CGF_ROWS 64 /* LIST_ROWS_FIRST for this group */
#define CGF_FILES 128 /* contains file names */
@@ -299,7 +299,7 @@ struct menuinfo {
#define CAF_NOSORT 2 /* compadd -V: don't sort */
#define CAF_MATCH 4 /* compadd without -U: do matching */
#define CAF_UNIQCON 8 /* compadd -2: don't deduplicate */
-#define CAF_UNIQALL 16 /* compadd -1: deduplicate */
+#define CAF_UNIQALL 16 /* compadd -1: deduplicate consecutive only */
#define CAF_ARRAYS 32 /* compadd -a or -k: array/assoc parameter names */
#define CAF_KEYS 64 /* compadd -k: assoc parameter names */
#define CAF_ALL 128 /* compadd -C: _all_matches */
diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index c6deff7568..a9ace5587b 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -3254,10 +3254,13 @@ makearray(LinkList l, int type, int flags, int *np, int *nlp, int *llp)
qsort((void *) rp, n, sizeof(Cmatch),
(int (*) _((const void *, const void *)))matchcmp);
+ /* since the matches are sorted and the default is to remove
+ * all duplicates, -1 (remove only consecutive dupes) is a no-op,
+ * so this condition only checks for -2 */
if (!(flags & CGF_UNIQCON)) {
int dup;
- /* And delete the ones that occur more than once. */
+ /* we did not pass -2 so go ahead and remove those dupes */
for (ap = cp = rp; *ap; ap++) {
*cp++ = *ap;
for (bp = ap; bp[1] && matcheq(*ap, bp[1]); bp++, n--);
@@ -3279,7 +3282,9 @@ makearray(LinkList l, int type, int flags, int *np, int *nlp, int *llp)
if ((*ap)->flags & (CMF_NOLIST | CMF_MULT))
nl++;
}
+ /* used -O nosort or -V, don't sort */
} else {
+ /* didn't use -1 or -2, so remove all duplicates (inefficient) */
if (!(flags & CGF_UNIQALL) && !(flags & CGF_UNIQCON)) {
int dup;
@@ -3303,6 +3308,7 @@ makearray(LinkList l, int type, int flags, int *np, int *nlp, int *llp)
(*ap)->flags |= CMF_FMULT;
}
}
+ /* passed -1 but not -2, so remove consecutive duplicates (efficient) */
} else if (!(flags & CGF_UNIQCON)) {
int dup;
--
2.15.1
next prev parent reply other threads:[~2022-03-26 1:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-15 11:56 PATCH: Fix inverted condition for unique completions Mikael Magnusson
2022-03-17 17:08 ` Mikael Magnusson
2022-03-17 19:17 ` Bart Schaefer
2022-03-17 19:32 ` Mikael Magnusson
2022-03-26 1:40 ` Mikael Magnusson [this message]
2022-03-26 1:43 ` PATCH 2/2: [WIP] Efficient dedup for unsorted completions Mikael Magnusson
2022-03-29 16:07 ` PATCHv2 2/2: " Mikael Magnusson
2022-03-30 16:41 ` PATCH 2/2: [WIP] " Bart Schaefer
2022-03-30 18:33 ` Mikael Magnusson
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=20220326014030.2802-1-mikachu@gmail.com \
--to=mikachu@gmail.com \
--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).