From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 5A69021EB4 for ; Tue, 9 Apr 2024 11:16:07 +0200 (CEST) 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:Message-ID:Date: Content-Transfer-Encoding:Content-ID:Content-Type:MIME-Version:Subject:To: References:From:In-reply-to:cc:Reply-To:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=wPmO4cwGZm/0sfsr9b173VbGjKs39obOvji6s6CFcLY=; b=WDRGrjSgxjiwr5w/WPjYHgRrsb 551qTmjCBQ05a6xike9YAocM5eOM9ZqVGqd96VgnFF/GKysciEp2+mboMyKPoVHTJsZFes31bNuC4 ZCZ+wK68Vm3fPO3JJF3EZvTDVXRsKRVvIHO08gMKFzGBHNTxjETQMVW2w/mz29P0yEheLr8MvXuXA oOq1vvd8MTFkQPR/8cx5H14RWjbggrOtxIxxar5qtJo5hidstlR7cHl5XvTUTIGumXkxpHtnl6GC9 goubgdkfp+rwyGMOl91yBiM2h2ol6+vMv+egpmid8cWXHzzjhzbaHIRyHXujWQy2bXCkAeEyggts6 yQcy1AAQ==; Received: by zero.zsh.org with local id 1ru7aI-000KUY-W7; Tue, 09 Apr 2024 09:16:07 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1ru7ZA-000K9S-N6; Tue, 09 Apr 2024 09:14:57 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.97.1) (envelope-from ) id 1ru7Z9-00000000DcG-0M06; Tue, 09 Apr 2024 11:14:55 +0200 cc: Zsh hackers list In-reply-to: From: Oliver Kiddle References: To: Marlon Richert Subject: Re: [BUG] Incorrect usage of $PREFIX and $SUFFIX in completion functions MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <52342.1712654095.1@hydra> Content-Transfer-Encoding: 8bit Date: Tue, 09 Apr 2024 11:14:55 +0200 Message-ID: <52343-1712654095.077817@pvBu.uHUo._xjG> X-Seq: 52883 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: Marlon Richert wrote: > Many completion functions in the Zsh code base use $PREFIX$SUFFIX to get the > word to complete on the command line. However, this seems incorrect to me, > because it prevents the _prefix completer from functioning correctly for those > completion functions. If it is being used to get the word to complete then it is wrong. In some complex cases, it may be a necessary compromise. There are also cases where $words[CURRENT] is used (wrongly) instead of $PREFIX. However, most cases of $PREFIX$SUFFIX found in a search of the functions look valid at a brief glance. Note that, e.g. [[ $PREFIX$SUFFIX = */* ]] is equivalent to doing [[ $PREFIX = */* || $SUFFIX = */* ]] > Shouldn't all completion functions simply use $PREFIX to get the word to > complete, since it is the responsibility of the completer function (_complete, > _prefix, etc.) to decide whether the character to the right should be > considered part of the word to be completed? Depends on what exactly you mean by "word to complete". It is best to leave matching up to the completion system so that it can handle matching control etc correctly. There are cases where generating matches is faster if you let the external tools filter by prefix. This is also not uncommon in completions that have been converted from bash (which isn't really the case for any included with zsh). > Shouldn't _complete do `PREFIX+=$SUFFIX; SUFFIX=` before calling completion > functions, since, otherwise, there is no meaningful difference between it and > _prefix? Definitely not. Given ac and candidate matches abc and acd, _complete should complete to abc with complete_in_word set, offer both with _prefix and complete to acd if complete_in_word is unset. Oliver