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.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE 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 A36E9255F1 for ; Mon, 19 Feb 2024 20:15:24 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1708370124; b=RZMtaur8+nI2wxIkg11HTu3q0/xH1XbcQCtVbmxvXmP+jiEFQXDn4aQFSRiyS96tKvU8WSoRrP TVTdtA3foU2zbmtkRByL2WRR8s1dDihxJB8MvOx6Im4YOXCxXniySPE1a4PSxV88XUIEJ1Xbtz q9rJGJs+iTgroXwQaoezqmCjPgIUlIEQkAkW3KcF+RZ3d33cKJoRyNWCdoHSGUf9r9v1VrZ32I /YzoRp10+BXooVVj+oc4xaJGceUHiIA1Z4birXZGtBWif5JPDlgs+nq7A0eD9YVyiv41Dzchi0 nhjGtYDkZDYh1WGzcHbC5VG3zQcFcP15QVudGgv9nYhqsw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f49.google.com) smtp.remote-ip=209.85.218.49; 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=1708370124; bh=1D4or5Y4AJxwC3EsTgVQKXMXnvCKLW6oEddo+KjUGso=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=PhanMVYppMD3V4RYuVZt152p5rgPmtPUtvyEV0Ctcazq4eOCIqh9fHr2B/jtOvl+M4jBIaYTxc DyeR1HCJ3qmRYGdpKBNfF31Gc8JKtUJYr3qUUIbAmUXKNtZaK2A/Zq3dETTa2jjhR1+pTuXJfK VkQ/vF3hZt38m1QOTJSzWgOEB4xiYmbXYt9Q9cyrFk48bsu2f3s8Z0iIArt77XfEjoKJP1bZ7v 51ZTpaYiqJ0iBQaAvZCpXoF0ECKMkLsOuy/0bQheKxuMAy0MU25zsVbwloSHwVqZ98osiSfGb4 cDzkLtQKmTeMYtEUMNRIYjCRwiUCgjGYFShxGLu1zFicTQ==; 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:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=0UUIixA2Q69SgX7uPlOOn0rlqUcQ7mFGIPp6wmqoNaQ=; b=kw13BcEMf2V26C4q/9ZOuIUnpd 1qCDlYnlyYYa/Dvu5UkzTrQRVcMnCVHzIwT6AZKfjeXNQh0Um8myFiUAiR7eAHIusQNgqVdJY5/zy H4T8WoJa4rj5jB4eMALKaE/znKDZuhtxouBxIdcNVcN185WoUGtxkbI8One2TyQNBlnw12qCFJdxz Hd/yFtylzSXHvgWnR61jbAvThE5J2ervESk/dfp/PvrSml8BkSJKmVITt/9cnB8SJVF9zEdmWVleo 8eUbTYTriSRGdMSxgjHECAHdkBvPhnrdWfwoehs9hYNphj8TlitAlVfM/9ZI3/8viGtlx+jud0rj5 OcyojM4A==; Received: by zero.zsh.org with local id 1rc96p-000Cf6-AR; Mon, 19 Feb 2024 19:15:23 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f49.google.com) smtp.remote-ip=209.85.218.49; 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-f49.google.com ([209.85.218.49]:53343) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rc96C-000Bxm-1m; Mon, 19 Feb 2024 19:14:45 +0000 Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a3e8c1e4aa7so138842066b.2 for ; Mon, 19 Feb 2024 11:14:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1708370083; x=1708974883; darn=zsh.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=0UUIixA2Q69SgX7uPlOOn0rlqUcQ7mFGIPp6wmqoNaQ=; b=fMMPDI4qb1FQZI7RGK6AhTRv+zc+ARAJRnMVtO0D1LMtTWeR00TAjOEfGO7LJ3rcJY /QvOgECSGWT+7CTyHcfxXQ5kIjj5pTJYOidFhp6IhGe/1cVf42Fr96T4KrfKIj5gPvSS ihrvmfM/bKSKY3h5p7yi3cpx1Im/xCX/0JsFRLW8FRekA417ADQlKATHV5OZG2xWJdyS +sOPpqZiJZPdt+cCu3xePVPtwNUG6sS2BTe7GUzE8rrLmz6/aFEvcg8rYuOkqSwcS9nj c49ufR60pgx9O0G9TLgE/ftoU1pH5RBKHz7AdMnm8ct1Z12ZYU/CCjV3Bg4J6sp03OB2 k8ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708370083; x=1708974883; h=content-transfer-encoding:cc: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=0UUIixA2Q69SgX7uPlOOn0rlqUcQ7mFGIPp6wmqoNaQ=; b=B1oWhpGttQ8470ccQ9wNCd7zizGisCm/ZSHilyWuRkB5w/GQgCbYKPzxCniXOdv59N 8AFI7rZLBanKqD/xLwtxnY68MZ++HhLdMXADQ0Zt/60AwXv/mb24WJrMnAhH22BfV/JQ fZUSkjRcSlddXF+wIrMmYxz7bsbbGLC1gNiLhxNncYeDFZvdHOY3DZ8y2NBCEa6VykVI fajlz9akyD82XaMyxxkjq6GpkH6FUeNM6TsBC5qlA9OY4oUX2Lejy05lcfTWv6EctgK/ K+s5SSnCNKzDUr2sYF9jAvLPCFEc3aar6idNiHe5p0VG8bhXkiV78nMpQq+wj/DjLJUY Pedg== X-Gm-Message-State: AOJu0YyoosvHd5z5Bp8LmjTIYZxspkqIMJcuMUL6TSqTFBi79MDHd2XU dfffEzbEsuLh9VcTIdaUsdtsBsO9WxzeNCQULwzrzbmJhkqTfAi4N5OwtkHgUGuwhgGM1zSSeFM OdQPAk3iO10eH62MZQ96I50tHKbl2NtUnPvVU X-Google-Smtp-Source: AGHT+IFpgixxn4m+uwqb60od6NXbdA5iTFCqodBQXd+m8MGqIYiGnWUkQezy21IgJ70ILuNEOq4f4MWr+z7/5O2Ax/c= X-Received: by 2002:a17:906:d107:b0:a3e:50ac:c5c9 with SMTP id b7-20020a170906d10700b00a3e50acc5c9mr3373427ejz.72.1708370083177; Mon, 19 Feb 2024 11:14:43 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Mon, 19 Feb 2024 11:14:32 -0800 Message-ID: Subject: Re: external completion command To: Felix von Leitner Cc: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 29689 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Mon, Feb 19, 2024 at 4:30=E2=80=AFAM Felix von Leitner wrote: > > Hello zsh-users, Hi, Felix. I'm sure we've chatted before but I can't find anything from you in the list archives going back 25 years. Still maintaining zsh.vim ? > % s memc[TAB] > memccpy > memchr > memcpy > memcmp > > However, since the database covers potentially gigabytes of source code, > I have written an optimized tool to list all the words that start with a > certain prefix. I want zsh to run that tool with the prefix I already > typed. There's a lot of scaffolding in the "new" completion system (which has now been around for about 85% of the life of the "old" one), but it's all pretty much in support of two commands: - compdef how what Tells completion "how" (e.g., what command to run) to complete for "what" (command line context). - compadd details -- words... Tells completion to consider the listed words when invoked, with various details like whether the words are file names and what explanatory text to show. The rest is all just to assist with breaking the command line and the word adjacent to the cursor down into "what" context so that different "how" can be selected. The whole scaffold is loaded by running autoload -Uz compinit compinit which also scans the directories in $fpath for files with "#compdef" in the first line and automatically enables those. The other minimum thing you need to know is that the $words array contains the command and arguments for which completions are being generated, and that the integer $CURRENT specifies the position in $words that is adjacent to the cursor, so $words[CURRENT] is your already typed prefix. > I don't want to give zsh a list of all the words, because that > would be very inefficient. I would also like to tell zsh to abort after > reading 100 completions. The simplest formulation of this, then, using here "taglist" as the name of your custom tool and "s" from your example as the command name for which completions are being offered, would be something like (in .zshrc) compinit compdef 'compadd -- $(taglist $words[CURRENT] | head -n 100)' s Or you could create a file named "_taglist" in a directory in your $fpath and in that file have #compdef s compadd -- $(taglist $words[CURRENT] | head -n 100) I'm glossing over the possible need to do other quoting on the $(...) if taglist could produce results with embedded spaces, or what you want to do if $words[CURRENT] is the empty string. Everything beyond this is just frosting. For example there's a variable $curcontext that tells you what context the completion system has figured out from the contents of the command line, and the "zstyle" command to define and look up values based on that context, so in the above _taglist you could change the limit of 100 to different numbers based how many words are to the left of $CURRENT, etc. Hope this helps.