From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3541 invoked by alias); 22 Jul 2018 00:27:20 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 43198 Received: (qmail 15217 invoked by uid 1010); 22 Jul 2018 00:27:20 -0000 X-Qmail-Scanner-Diagnostics: from mail-lj1-f175.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.208.175):SA:0(-1.9/5.0):. Processed in 1.96357 secs); 22 Jul 2018 00:27:20 -0000 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,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIMWL_WL_MED,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=8qZWrBciBG6+iFIxZCuHISvp1uT9WFmFJZy1m/oQiI0=; b=I0Fzg80nNXEMJdAruQQlh8OvxuHEz5ajY66W8gJpKBjHDXjgrFTxJMGisPC5GDSx0c nTvmkDNisvuGD937hzBV80DhSpeU6/fplytR+E7PS4C8Cvb9tJJjjljgxYia4MA/k8yF Ez6/MOI2V0V6vnBCmsCorESxcdgk42/Q01a8dLKMBXm+fdNW7SxRasd1fU1diCsS4tSx SbjarI+dhZBR8+uCU1EyCgWwa6PWU8T3n8iix844fQeT1U7+M/PS6iZ4JRy/7OJEHtzG 9Te8zTxj0ElotTngdrBvDRmWs0+weQfID9wuYtxJzK8T4hbkfjsibK1tlN5d4bxGIjic kZ0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=8qZWrBciBG6+iFIxZCuHISvp1uT9WFmFJZy1m/oQiI0=; b=brCYGRnmyrqJanyJRsK6lfYUatp8Qs9uiTLNR6137lFLrWH6hihOk4kRo6JaIz87cu ywK70eLDrGiJ3yY+680oLn6vFOVb7ywChnEmZ/xMMHg+zNs91L+JwlIy/i/YYzQSQiQJ ORK6lTk0tt26ZjrihxrQZjy0SPr3C8SmR5UJ8q5SOY1MDXcvfC0InE0Wb4JjQZva1teA BmMKzfxvZMmw/j4D71muIn7A5uDkkbXN/Sj+eaJY133tMcLbhY9EA5vtNtl8z3dwa7Mk /KHDS055EPegzjYUvhh6z40nvlVPUFKmvX7i8BZpUxUNmUtn2gG7D4/QixgePBtnPZr7 Au6g== X-Gm-Message-State: AOUpUlFxtcm/1vd4tUdzmjY97Cckfwv+zoiSEJ5ehZv8uugnOgIV7q3E lJaxjZNWs8M/Lf1q5qlatWcXlDON3SCVMX1jL1526GMNzWaUTA== X-Google-Smtp-Source: AAOMgpf9Gncc7ewfdL5Frv70JF/uKUdPoYHpS3sUqOuCdt0YpP/IxRaVw61r296MYE5uBWXK87gRKlnX8xP82jW2Xrg= X-Received: by 2002:a2e:1517:: with SMTP id s23-v6mr5312811ljd.73.1532219234032; Sat, 21 Jul 2018 17:27:14 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20180721111514.GA6123@primenet.com.au> References: <20180721111514.GA6123@primenet.com.au> From: Bart Schaefer Date: Sat, 21 Jul 2018 17:27:13 -0700 Message-ID: Subject: Re: Perplexing `COMP_POINT` value on bashcompinit tab completion To: "zsh-workers@zsh.org" Cc: "Saverio M." Content-Type: text/plain; charset="UTF-8" On Sat, Jul 21, 2018 at 4:15 AM, Geoff Wing wrote: Hmm, did this get trapped as spam or something? Why did Geoff need to forward it? > ---------- Forwarded message ---------- > From: "Saverio M." > To: zsh-workers@zsh.org > Cc: > Bcc: > Date: Sat, 21 Jul 2018 11:31:02 +0200 > Subject: Perplexing `COMP_POINT` value on bashcompinit tab completion > Hello! > > I use the OMZ/`bashcompinit` combination in order to write my tab completion scripts. I'll note that as soon as you introduce OMZ, things get a little murky, because it sets a bunch of options and key mappings that may change some expected behavior. > When typing: > > ```sh > $ scr > ``` > > Bash sends to the completion script the env vars `COMP_LINE=scr ` and `COMP_POINT=4`. The number `4` is, intuitively, the position of the cursor (and the size of the `COMP_LINE` string). > > Zsh sends `COMP_LINE=/home/oooh_my_tab/scr `, which is different while correct nonetheless, but sends `COMP_POINT=23`, which is perplexing, since the position of the cursor is `22`. I'm not sure why zsh is expanding the full path to "scr" here (see above about OMZ), but: I'm fairly certain this happens because arrays in bash are zero-base-indexed, whereas arrays in zsh are one-base-indexed. So the position of the cursor is after the 22 characters in the line, at $BUFFER[23]. Even if you have the KSH_ARRAYS option set in the interactive context to revert to zero-based arrays, completion uses zsh default context with one-based arrays. COMP_POINT is computed like this: (( COMP_POINT = 1 + ${#${(j. .)words[1,CURRENT-1]}} + $#QIPREFIX + $#IPREFIX + $#PREFIX )) However, "1 +" is probably wrong here because the stand-in for compgen re-asserts KSH_ARRAYS. There was an attempt to fix this in zsh-workers articles 31031 to 30137 but the wrong fix was done, it changed the number of words examined (causing a different bug) rather than remove the "1 +" offset calculation in the assignment to COMP_POINT. The new bug was noticed and reverted to the previous behavior, which restored the original bug. > When typing: > > ```sh > $ scr a > ``` > > Zsh sends `COMP_LINE=/home/oooh_my_tab/scr a`, and the now more perplexing `COMP_POINT=25`, which adds an unexpected extra unit to what was, in the previous example, an already apparently off-by-one value. I don't see any obvious reason for this in the current sources, but what version of zsh do you have? The "different bug" I mention above was present from November 2013 to January 2017 and fixed in zsh version 5.4.2, and that bug might explain the additional offset.