Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,
	T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=googlemail.com; s=20120113;
        h=from:to:cc:subject:date:message-id;
        bh=M+nAe8e+b5VGSx6wOJ403E84kb2b+3RVAqGYLo0CxjU=;
        b=OSLrXx4Wsk4hKkF5x4ENx2vyBQFon9nzjD8pPR0ePuq3VAnpUZvkhcJMD0+/dZGEco
         najNS0li9kYymrIOy1C7CF91CUz0XFvB0DY2ICQ12qP5+E6Jf1IIoeA1f3eIXY0OGDLP
         gTMr48IqDlPZDiydAGPv0yO/hb6RtB60kNDtr8aKbU3tc+ojATUqaK+1x7K+5W/DZG2S
         4zgxY6RrsMskDdMPvEUHJI+pF/mkNwe73Akz/L4kx1Lv6rGpc9SLYheIHu9KZnpGKDoy
         0aHhn0MJxW8ISHuACV1G5e9hXmWssj8MwFqWoPwuTaqFis04FLJdT8ZndwvqNT2DV4jr
         TGEA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:to:cc:subject:date:message-id;
        bh=M+nAe8e+b5VGSx6wOJ403E84kb2b+3RVAqGYLo0CxjU=;
        b=Lv1aVn2pNSldoBnuRlQ5GpIRmVSyruHTw+1LZJ3/YOGHxPr6SPKU4eL1A/+FsCpf0i
         aTJjkxyy90kh0lV+Ydo1OoLkbtfKjtaa5aIbSDwWuO7rYKmslDtEqgtaIQRedMXgg4Mj
         8OwPqXoyMl/sBGTAXBDdT9mHgCtl/OrwJy8G9xRyEJlF2mpdIHYuW76Ift3sJ3Js8puZ
         eWBbxwsjUQMt7AbGfEhOLkGBgRlXy4F9snKOEK0TETZlWGjbULIItT2DraX8nFvwhvNi
         6uFH8iUzpSh4e89ftvVVXfcLAkFojhaX9pxrlDvdNvdQ/VLpGAkKhHn4MjSCMimxlkYp
         g1BQ==
X-Gm-Message-State: AD7BkJKvSl35CsZg5dRlbgKBOf1qi3nq2M5+Y+hvI/So9I6aiQlno/6CMmxu8iNGZgITig==
X-Received: by 10.28.184.148 with SMTP id i142mr14763286wmf.22.1457908579851;
        Sun, 13 Mar 2016 15:36:19 -0700 (PDT)
From: m0viefreak <m0viefreak.cm@googlemail.com>
To: zsh-workers@zsh.org
Cc: m0viefreak <m0viefreak.cm@googlemail.com>
Subject: [PATCH] completion: matcher correspondence classes: fix offset
Date: Sun, 13 Mar 2016 23:36:14 +0100
Message-Id: <1457908574-11020-1-git-send-email-m0viefreak.cm@googlemail.com>
X-Mailer: git-send-email 2.5.0.234.gefc8a62
X-Seq: zsh-workers 38150

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

