zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: gi1242+zsh@gmail.com, "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: Use external tool if there are a large number of completions
Date: Mon, 14 Sep 2020 13:32:35 -0700	[thread overview]
Message-ID: <CAH+w=7Zz-yX49tW1nowE9oBiaiDXKC_xmTcHz=T0eDq4Y+zjxw@mail.gmail.com> (raw)
In-Reply-To: <20200913222122.GA4031@andrew.cmu.edu>

On Sun, Sep 13, 2020 at 3:21 PM <gi1242+zsh@gmail.com> wrote:
>
> I was wondering if it's possible to use an external tool if there are
> more than a certain number of completions.

This is not directly possible for a few reasons.  For one, the strings
passed to the compadd builtin are allowed to be (and usually are)
potential rather than actual matches, which the completion internals
then filter down to the actual completions based on comparison to the
command line.   For another, once potential matches are collected via
compadd there is (at least at present) no way other than by that
comparison to remove non-matches from the set.

That said ... I can think of a possible way to do it.

Adopt a scheme similar to the one used by the _approximate completer,
which creates a function wrapper around the compadd builtin to
intercept the potential matches and apply corrections.  I'm not going
to attempt to write this, but the idea would be:  1) Build a wrapper
around compadd that interposes the "-A array" option (via "builtin
compadd") to collect the results in an array instead of adding them to
the internal data structures.  2) In a comppostfuncs function, remove
the wrapper and invoke your external command on the contents of that
array.  3) When you have the result of the external command, compadd
that as the single possible completion.

It will require some considerable care for this to interact correctly
with _approximate and _complete_help, if not some other completers.
It will also mess up things like groups and explanations.  You're
likely to be better off with Oliver's suggestion of the complist
module, or create a separate keybinding to delegate the entire process
to rofi and when you encounter the "do you wish to see all 3069
possibilities?" prompt, say no and type your rofi binding.


  parent reply	other threads:[~2020-09-14 20:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-13 22:21 gi1242+zsh
2020-09-14  0:14 ` Daniel Shahaf
2020-09-14 12:29 ` Oliver Kiddle
2020-09-14 20:32 ` Bart Schaefer [this message]
2020-09-15  1:16   ` gi1242+zsh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7Zz-yX49tW1nowE9oBiaiDXKC_xmTcHz=T0eDq4Y+zjxw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=gi1242+zsh@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).