zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Three questions about a completer
Date: Tue, 13 Sep 2016 19:59:16 -0700	[thread overview]
Message-ID: <160913195916.ZM30431@torch.brasslantern.com> (raw)
In-Reply-To: <CABZhJg_4b6GiCo1J3BHzL0ACwao5Q_-HQgnhuHjQowUF+FVemQ@mail.gmail.com>

On Sep 13,  9:18pm, Jesper Nygards wrote:
} 
} So now, at least, I get the completion to trigger. However, I still have
} the same problem: hitting alt-e for menu-complete works, and hitting alt-E
} for reverse-menu-complete works as well, but switching direction doesn't:

The doc for the _menu completer that Oliver mentioned, states:

     Note that this is independent of the setting of the
     MENU_COMPLETE option and does not work with the other menu
     completion widgets such as reverse-menu-complete, or
     accept-and-menu-complete.

So that suggestion is out.

>> 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
>> alternatives.

You should not have to do this yourself; this is what the completion
internals are made to do.  You need to caculate ALL the possible files
that fit the rest of your criteria, and "compadd" will take care of
filtering that set down to the ones that match what's on the line.

If you don't want to match by simple prefix then you do have to tell
compadd how to filter.  You do this with the matching control format
that Oliver outlined.

To stop the listing, and only menu through the matches, you assign
empty string to compstate[list].

Finally you need Oliver's wrapper technique to interpret NUMERIC.
The nice thing about menu-complete / reverse-menu-complete is that
if a menu is already in progress, it won't re-invoke the completer,
so if you start from the wrapper widget in the forward direction,
you can reverse without having to use the wrapper again.

So the whole thing looks something like:

    zle -C list-comp menu-complete _generic
    zle -C reve-list-comp reverse-menu-complete _generic

    n-list-comp() {
      local -a dirs=( $HOME /etc /bin )
      local __lsdir=${dirs[${NUMERIC:-1}]
      zle list-comp -w -n 1
    }
    zle -N n-list-comp
    # Similarly for n-rev-list-comp to start in reverse with NUMERIC

    bindkey '\ee' n-list-comp
    bindkey '\eE' rev-list-comp    # or n-rev-list-comp if defined

    _list-result() {
      compadd -M 'l:|=* m:{[:lower:]}={[:upper:]}' -f ${__lsdir:-HOME}/*
      compstate[list]=''
    }
    zstyle ':completion:*list-comp::::' completer _list-result

Strictly speaking you don't even need rev-list-comp, you could just
invoke reverse-menu-complete provided that you always first enter
the menu in the forward direction.


  reply	other threads:[~2016-09-14  2:59 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
2016-09-13 16:16   ` Jesper Nygårds
2016-09-13 19:18     ` Jesper Nygårds
2016-09-14  2:59       ` Bart Schaefer [this message]
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=160913195916.ZM30431@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).