zsh-users
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: "Jesper Nygårds" <jesper.nygards@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Three questions about a completer
Date: Mon, 12 Sep 2016 22:53:03 +0200	[thread overview]
Message-ID: <75335.1473713583@hydra.kiddle.eu> (raw)
In-Reply-To: <CABZhJg-VR4ss0KpxLvUnrUS7JnTVGGdSWePH7NzCzQvdimMubg@mail.gmail.com>

Jesper Nygårds wrote:
> I have a completer function that I have bound with menu-complete to alt-e

> 1) I want to have the alternatives offered by consecutive presses of alt-e,
> and I don't want the alternatives to be listed below the command line. To

The hidden style should suppress listing the matches:
  zstyle ':completion:*list-comp:*' hidden all
But hidden is looked up from _description which you don't call.
You could add _wanted around the compadd but all the hidden style
actually does is cause the -n option to be passed to compadd which you
could do directly.

> 2) The line starting with "[[ -n $words[CURRENT] ]] ..." is meant to make
> sure that only files that match whats given on the command line (case
> insensitively and anywhere within the file name) is offered as

I would try using the completion matching control:

  compadd -n -p /etc/ -M 'l:|=* m:{[:lower:]}={[:upper:]}' /etc/*(:t)

> alternatives. I does work, but it also means that reversing the order -
> either by starting with alt-e and then hitting alt-E, or the opposite -
> does not work. I assume that when I reverse the order, the widget is called
> again, and since there is already a file on the command line (from pressing
> alt-e once), there is only one file matching. Is there a better way to get
> this behaviour? Again, I want to put a string on the command line, hit
> alt-e, and only those files having a part matching what i wrote should be
> offered. If I then reverse the order, I want the same list, i.e. those
> files matching what I originally wrote.

Using _menu generally does what I think you're describing. To use that,
you may want to use _generic instead of _list-result directly. I'd
recommend using _generic regardless of whether you want _menu, actually.
Other completers such as _match could also be useful.

  zle -C list-comp menu-complete _generic
  zstyle ':completion:*list-comp::::' completer _menu _list-result

The same thing can probably be done directly: _menu is not long but I
wonder whether it is right with the reverse widget.

> 3) I like the idea of using $NUMERIC to trigger alternative behaviour, in
> this example getting the file names from another directory. That means I

The menu completion widgets interpret the numeric argument. You can
always use a wrapper zle widget:

  zle-list-comp() {
    local dir
    (( NUMERIC == 1 )) && dir=/etc || dir=~
    zle list-comp -n 1
  }
  zle -N zle-list-comp

The -n 1 there passes 1 as the numeric argument on to list-comp. Needing
two widgets is a big ugly but I don't know of any alternative.

Oliver


  reply	other threads:[~2016-09-12 21:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-12 11:38 Jesper Nygårds
2016-09-12 20:53 ` Oliver Kiddle [this message]
2016-09-13 16:16   ` Jesper Nygårds
2016-09-13 19:18     ` Jesper Nygårds
2016-09-14  2:59       ` Bart Schaefer
2016-09-14  7:22         ` Jesper Nygårds
2016-09-14 16:39           ` Bart Schaefer
2016-09-14 20:32             ` Jesper Nygårds
2016-09-15  4:49               ` Bart Schaefer
2016-09-15  6:01               ` Jesper Nygårds

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=75335.1473713583@hydra.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=jesper.nygards@gmail.com \
    --cc=zsh-users@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).