From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 15886 invoked from network); 17 Nov 2023 03:36:09 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 17 Nov 2023 03:36:09 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1700192169; b=PN4TzyrG9eYT/Qf7qrAx37AUCaKAUtlxKrO6zeF4UXF2zRzAWKp2PKmXKN+h6MOnjZMO4k3N/Q XqKmcUj8IZm5oRDZhnuXaoYYglwwG2dGjxQfAen9JnMTbNbCV1z+MkSJLeP9DRNwF+nTHLyOyk h3niBQZOf/duskjnsH9Nf1yX+fc0nS86vyEjaiAuYImCElqEoCkN60Hp1Dvp4X4f5gNuL6CbJT P+gSnYoXohYoMZAK7mvr2LY4/efSzHXJsXspz44/22apeq9OXcOtYNyDCEJ6N+O2505HBHXd7C 1T/iLNyAgXnSCGsV6Ps6hv1M2YHQqN1/SHw0FV+nes2aKw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f41.google.com) smtp.remote-ip=209.85.218.41; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1700192169; bh=OOYNGjOQEisNk8YqnbPQ5vGaQs1E0RzfNtQf222+suE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature:DKIM-Signature; b=ZXhDVM3eHEn1oyi7quJlPzC5IEnL3Q2jPopmw+0h4B8lEvifsdJrYCc2fk6QmEPhR7vi1lVgz2 5Go9MVXhlzNDgWIus0lw4igw6v+2BUUkn1NSWmnkn8K2DJODSPK1nYlS/NgibE0u77OFcqDszw D/a5xcCfsiFRqF0DFy2lJamQkLciS/ndsEJUGd0j+S3A6hZ+bUCC7Z6N/niA5t2mM46zLKlJMd whwRJrCIj+WNmAbEzsRjR2DqwynJpBXLxMsGTU7VesWqJOQhs/VYZg3eI2Im6tFjrqmuGBDTjb imndtq+V2vuO9CdMApK6SWPJZznzwJ0LgN09nL7kGlDa8A==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=PE2EbMgx22DN8TWWu6oxpGuDcKoeGbyJ6H/5EAy+7L8=; b=KPlq7cg7Krb49mQeUwdYmhm6Il Wf1vw+1Hh3Au9sxmJgvpqb8zgeOuAYuKiz2vdG/yW1mnUxOP0exoH72lHfPfN2JgrD6aP9J9Z7reb dRC/p3hnFN5Y2f5hrV1lCr1+gIgbYVncYDa3CFdNbpdJE13t4HXnffAC6Cld4ochEg4LZRCBLb5gF jM2FFgitt+ucZqzdwO/0IG1Z4bm5gy/Z2ys2FvXYN6m+BARvxV/ZH0gtXOn80N46qR+1siRWr7Kfy J99eMKfzXHwnRmVJcODj6N6zD22rusUpiwhS9fbyMQkNubazysfUr3EsvpPh2t0Kb9xpiOlHMsHPY qXeotilg==; Received: by zero.zsh.org with local id 1r3peL-000MHv-0V; Fri, 17 Nov 2023 03:36:09 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f41.google.com) smtp.remote-ip=209.85.218.41; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f41.google.com ([209.85.218.41]:49211) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1r3pe4-000Lzd-5x; Fri, 17 Nov 2023 03:35:53 +0000 Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-9e28724ac88so207082866b.2 for ; Thu, 16 Nov 2023 19:35:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1700192151; x=1700796951; darn=zsh.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=PE2EbMgx22DN8TWWu6oxpGuDcKoeGbyJ6H/5EAy+7L8=; b=qmR+WipcFMhKaMO3wyoiCVNZXwbyRGs/D40lq5JU0wQ+3QiV6mPSVTjy+JszZJeEu9 2c6sIT9qCc9N0N2tPONVwZi6yl4mti4pN6tw5JgHlZWMFajV/3El0uMJHQWeKvz86rYf K96fQkRVhg8HxwYyd9z2ZtJdRBzoTTJNDUkywZgO2rO/HwOUGyWxHqOAk+hpPJcR/XM8 3iTRvojxwF8HEZ2n8SgP03aYOA92Fxk7MZGR1oh6vvbxdF3mR08amOzEJ/NeesY84Mk/ Ok1nMNV4v2wOb2liwHyKpm1WwAgkZDwWVHJ2xqj1V5qra1rMkXo5xale9WR45UM2aypb 64uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700192151; x=1700796951; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PE2EbMgx22DN8TWWu6oxpGuDcKoeGbyJ6H/5EAy+7L8=; b=WqsenoF7EHzRl5bZH6xI/+dHrdSfyu39u+51ZVBapplVJlB92LhFdcLVPj088mURjB A0xwLLGPJ8rVUk/5n+IOMvOehACyc1PYXww7Hkt08qY5Qy7EzU4HhGV0far9+fhrQCJ+ PavtgNSKvNinu+e8Tfkb8yPaxXZ0BBaY4dmSr1sb1plEph90byAMlfQ66iML2vLYFzMq Iu2dOxB/LyRxZ2FF6HhGdiYh8FUHJQAuCf/Qz+JBtVRrkQgAq8wXQX86CUrIivdXAEFB YbZDLVJSBYC9SPXqNoA8VMv5xRsALWfzKQQIwIq81MWfAsHcWXYB9rIvptTAif0vp1LO CFCg== X-Gm-Message-State: AOJu0Yxu6xj3yikyHcM2PCijMg9BGyEFOg8rpmEoExUb0YEjxydSdPU6 yXiahFMCAKeA1Qf0duzdfZyGa0uGbti8p4kL2g/IGd6K2IyEJ8moOqU= X-Google-Smtp-Source: AGHT+IH2eXyBbmdBd/ztJ3nHxaGlixi35HN6oC8cXfHgoKjrSTPnbU5wa6L2oxbf+r96nDn3aPzBF/lDx6PPBxjPDd0= X-Received: by 2002:a17:906:1919:b0:9cf:797b:6adc with SMTP id a25-20020a170906191900b009cf797b6adcmr11077943eje.33.1700192151413; Thu, 16 Nov 2023 19:35:51 -0800 (PST) MIME-Version: 1.0 References: <8964126.CDJkKcVGEf.ref@phy-nordri> <8964126.CDJkKcVGEf@phy-nordri> In-Reply-To: From: Bart Schaefer Date: Thu, 16 Nov 2023 19:35:40 -0800 Message-ID: Subject: Re: [BUG] complist interactive mode overwrites command line To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 52312 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: Another thread rising from the grave: On Sat, Jul 16, 2022 at 11:11=E2=80=AFAM Bart Schaefer wrote: > > > On Wed, 4 Aug 2021 19:30:10 +0300 Marlon Richert wrote: > > > % zmodload zsh/complist > > > % bindkey '^I' menu-select > > > % MENUMODE=3Dinteractive > > > % touch test{1,2} > > > % : ; foobar > > > > > ^ 1. Type the above line in its entirety. > > > 2. Place the cursor before the ; > > > 3. Press Tab. > > > 4. Press Enter. > > > % : test1 bar > > > ^ Completion is written over existing buffer contents. > > The issue seems to be that interactive mode assumes you're going to > use it interactively -- as in, type a single character at a time until > you've reduced the set to only one match -- so it only adjusts the > buffer spacing on single keystrokes. When you accept with TAB (or > ENTER) domenuselect() is relying on do_single() to fix everything up, > but the state required by do_single() is not fully populated. This entirely seems to come down to minfo.len causing the wrong thing to happen in compresult.c:do_single(), specifically here: /* If we are already in a menu-completion or if we have done a * * glob completion, we have to delete some of the stuff on the * * command line. */ if (minfo.cur) l =3D minfo.len + minfo.insc; else l =3D we - wb; minfo.insc =3D 0; zlemetacs =3D minfo.pos; foredel(l, CUT_RAW); In normal menu completion, when entering the menu, the first match is already inserted on the command line. This code is used in common by interactive completion, so when accept-line is invoked, minfo.len is the length of that first completion. However, what minfo.len is supposed to represent is how many characters have already been inserted on the line, which in this case is zero because interactively nothing gets inserted until you type a matching character. Thus the foredel() call there deletes what it thinks is the completion already on the command line, but instead deletes other stuff after the cursor. This can trivially be fixed for Marlon's specific example by setting minfo.len =3D 0 in the "if (first)" block in domenuselect(), but that's only correct for this specific case. Anything that resets the appearance of the line -- such as hitting TAB again after accept-line, because (as in the "user defined widget doesn't execute suffix removal" thread), we are actually still in menu completion at that point even though we've left interactive completion -- also loses track of the fact that the original line is back the way it was, and so minfo.len becomes wrong again and things like navigating the menu with the arrow keys start foredel()-ing too much. Interactive completion gets in its own way here a bit, because there are several cases where it attempts to restore the original state and gets it subtly wrong. If anyone thinks they have a better grasp of all the special cases and widget handling in complist.c, please chime in. Of course 2/3 of the lines of complist.c are Sven W's and a good chunk of the rest is comments from other people trying to explain what Sven did, so I'm not very hopeful.