* [PATCH] completion: matcher correspondence classes: fix offset
@ 2016-03-13 22:36 m0viefreak
2021-12-23 20:24 ` Mikael Magnusson
0 siblings, 1 reply; 4+ messages in thread
From: m0viefreak @ 2016-03-13 22:36 UTC (permalink / raw)
To: zsh-workers; +Cc: m0viefreak
The "compfiles" function passes the matcher through the
"cfp_matcher_range" function to turn a prefix into
character classes. Example:
matcher: m:{a-z}={A-Z}
prefix: fo<tab>
file list: foo1.txt FOO2.txt
the cfp_matcher_range function is supposed to turn the
prefix into:
[fF][oO]
However there is bug which causes the offset to shift
by 1. Without this patch it returns:
[fE][oN]
The bug was unnoticed before, because in the usual
case -- that is when matcher-list is set -- _path_files
calls compfiles -p ... "m:{a-z}={A-Z} m:{a-z}={A-Z}"
with the matcher added twice. This causes
"cfp_matcher_range" to do nothing at all, and instead
the whole list of files in the directory is returned.
Then it is filtered using compadd -D.
A case where this bug surfaces is the following:
Make sure no global matcher-list is set and set a single
matcher instead:
zstyle -d ':completion:*' matcher-list
zstyle ':completion:*' matcher 'm:{a-z}={A-Z}'
Now the completion
cat fo<tab>
only offers "foo1.txt" but not "FOO2.txt".
Questions I couldn't anwswer, yet:
a) Why does "cfp_matcher_range" do nothing if more than
one matcher spec is given?
b) Do we even need the "cfp_matcher_range" function
at all? Seems like the later compadd -D works just
fine and we could remove a whole bunch of unneeded
functions that are only called from cfp_matcher_range.
c) Why does _path_files duplicate all matcher-list
entries when calling "compfiles -p"?
---
Src/Zle/compmatch.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Src/Zle/compmatch.c b/Src/Zle/compmatch.c
index 0e41ac3..667d71d 100644
--- a/Src/Zle/compmatch.c
+++ b/Src/Zle/compmatch.c
@@ -1218,7 +1218,7 @@ pattern_match_equivalence(Cpattern lp, convchar_t wind, int wmtp,
convchar_t lchr;
int lmtp;
- if (!PATMATCHINDEX(lp->u.str, wind-1, &lchr, &lmtp)) {
+ if (!PATMATCHINDEX(lp->u.str, wind, &lchr, &lmtp)) {
/*
* No equivalent. No possible match; give up.
*/
--
2.5.0.234.gefc8a62
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] completion: matcher correspondence classes: fix offset
2016-03-13 22:36 [PATCH] completion: matcher correspondence classes: fix offset m0viefreak
@ 2021-12-23 20:24 ` Mikael Magnusson
2021-12-24 19:58 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2021-12-23 20:24 UTC (permalink / raw)
To: m0viefreak; +Cc: zsh-workers
Were there ever any follwoups to this? I don't see any in the archive,
and the code still has the -1.
On 3/13/16, m0viefreak <m0viefreak.cm@googlemail.com> wrote:
> The "compfiles" function passes the matcher through the
> "cfp_matcher_range" function to turn a prefix into
> character classes. Example:
>
> matcher: m:{a-z}={A-Z}
> prefix: fo<tab>
> file list: foo1.txt FOO2.txt
>
> the cfp_matcher_range function is supposed to turn the
> prefix into:
>
> [fF][oO]
>
> However there is bug which causes the offset to shift
> by 1. Without this patch it returns:
>
> [fE][oN]
>
> The bug was unnoticed before, because in the usual
> case -- that is when matcher-list is set -- _path_files
> calls compfiles -p ... "m:{a-z}={A-Z} m:{a-z}={A-Z}"
> with the matcher added twice. This causes
> "cfp_matcher_range" to do nothing at all, and instead
> the whole list of files in the directory is returned.
> Then it is filtered using compadd -D.
>
> A case where this bug surfaces is the following:
>
> Make sure no global matcher-list is set and set a single
> matcher instead:
>
> zstyle -d ':completion:*' matcher-list
> zstyle ':completion:*' matcher 'm:{a-z}={A-Z}'
>
> Now the completion
>
> cat fo<tab>
>
> only offers "foo1.txt" but not "FOO2.txt".
>
> Questions I couldn't anwswer, yet:
> a) Why does "cfp_matcher_range" do nothing if more than
> one matcher spec is given?
> b) Do we even need the "cfp_matcher_range" function
> at all? Seems like the later compadd -D works just
> fine and we could remove a whole bunch of unneeded
> functions that are only called from cfp_matcher_range.
> c) Why does _path_files duplicate all matcher-list
> entries when calling "compfiles -p"?
> ---
> Src/Zle/compmatch.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Src/Zle/compmatch.c b/Src/Zle/compmatch.c
> index 0e41ac3..667d71d 100644
> --- a/Src/Zle/compmatch.c
> +++ b/Src/Zle/compmatch.c
> @@ -1218,7 +1218,7 @@ pattern_match_equivalence(Cpattern lp, convchar_t
> wind, int wmtp,
> convchar_t lchr;
> int lmtp;
>
> - if (!PATMATCHINDEX(lp->u.str, wind-1, &lchr, &lmtp)) {
> + if (!PATMATCHINDEX(lp->u.str, wind, &lchr, &lmtp)) {
> /*
> * No equivalent. No possible match; give up.
> */
> --
> 2.5.0.234.gefc8a62
>
>
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] completion: matcher correspondence classes: fix offset
2021-12-23 20:24 ` Mikael Magnusson
@ 2021-12-24 19:58 ` Bart Schaefer
2021-12-24 21:17 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2021-12-24 19:58 UTC (permalink / raw)
To: Mikael Magnusson; +Cc: m0viefreak, Zsh hackers list
On Thu, Dec 23, 2021 at 12:25 PM Mikael Magnusson <mikachu@gmail.com> wrote:
>
> Were there ever any follwoups to this?
I don't recall seeing any. Probably the only thing desirable beyond
that patch would be a regression test.
In the original message:
> > a) Why does "cfp_matcher_range" do nothing if more than
> > one matcher spec is given?
It's not that it does nothing, it's that it never gets called by
cfp_matcher_pats() when there is a matcher-list style but not a
matcher style. I haven't worked through exactly why THAT happens, but
it has to do with whether there's anything left over after the loop in
cfp_matcher_pats(). I have noticed that the "compadd -D" pass behaves
the same way regardless of the styles: cfp_matcher_pats() loops
through the matcher spec and ends up with nothing left at the end, so
cfp_matcher_range() is not called.
> > b) Do we even need the "cfp_matcher_range" function
> > at all? Seems like the later compadd -D works
Although _path_files is the only function that currently calls
compfiles -p, that doesn't mean no other function ever might ... so
what would happen if the compadd -D were never done?
> > c) Why does _path_files duplicate all matcher-list
> > entries when calling "compfiles -p"?
It doesn't appear to duplicate matcher-list entries ... what it does
is build its own list of matchers from its -M option, the "expl" value
returned by _description, and the setting of nocaseglob, and then
appends that to the matcher-list passed down from _main_complete.
That may or may not duplicate parts of the matcher-list. I suppose
_path_files could scan the $_matcher global to be sure it doesn't
append something that is already there ...?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-12-24 21:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-13 22:36 [PATCH] completion: matcher correspondence classes: fix offset m0viefreak
2021-12-23 20:24 ` Mikael Magnusson
2021-12-24 19:58 ` Bart Schaefer
2021-12-24 21:17 ` Bart Schaefer
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).