From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2857 invoked by alias); 12 Sep 2016 11:39:01 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 21871 Received: (qmail 21731 invoked from network); 12 Sep 2016 11:39:00 -0000 X-Qmail-Scanner-Diagnostics: from mail-lf0-f44.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.215.44):SA:0(0.0/5.0):. Processed in 0.501827 secs); 12 Sep 2016 11:39:00 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE, SPF_PASS,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: jesper.nygards@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.215.44 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to; bh=6ZykZWsTjVL+7Gp9cZnpNBTnBbjuxAnJbJuw1il+aB8=; b=KRXlgQqx+5iBHxgp8PcK00bv6KvLs2+FiXXQwfg28hww5HkhygxBXqSWB1HSJG+J4I TWsxDOAeGzqcxpbYtU/fh8bBZplqIH7gok01JqgyCSO2z72U1kufLRnF52Mh0DaoIbvu sdz/c+nEFHIZt9mMZcObUnfDGz19Tz63f5//x1I8jwY55GJQSNdbAaTxkrZumN4jQKGC WV6kEmYzIldbUQuorpiiuC6axcbSTtDtIoGDfUhap4F3fWg/Z5T3kAFYo5XWgezFW2ET WSzbKmtN7m9ou3aIRIUclZeVf5ZFWZdYkuO509w8i3IE3nPhVw7PM943k/sOqmyc22qk udrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=6ZykZWsTjVL+7Gp9cZnpNBTnBbjuxAnJbJuw1il+aB8=; b=DF2/TByDDHlKWaW5ZdjjafTyTyNqra/nfb4v+jz4v2XioI++Vw3pNMJUWAdTWaDLDf x0A1LMbAOsA7yEuHfp795zr1y/7L3EDiOUzc/MjFB69BISMciW56n4G36r8VHn746QVw SZ4OSrIIGhjw/pI8vt6+HUeoxBNVW2Ecufwqi2KMP8/3Tk/oTkAhXGvo483DgTNVOlrV BLiNT2FX0BjR5hQvr5Ro0erDcuuulrOWLFdhOk/8/qQs6/xqZ/pY5RIAcMA0tCgjFDFV 2DGjIQ9kokspq2B/+kpYp7C131IX1YZVXYhBou4ig+KRrsgpq5BVg9Oz3Qy/KCcn+ah4 u6xA== X-Gm-Message-State: AE9vXwMCI4ktCaRMBE2YX3THgyDemJApbzF6fElk+NS46BPdRnf2SNd1JpaNv61pUVB2SN5YZFXn7KTxdlbP5Q== X-Received: by 10.25.190.145 with SMTP id o139mr3968875lff.164.1473680330582; Mon, 12 Sep 2016 04:38:50 -0700 (PDT) MIME-Version: 1.0 From: =?UTF-8?Q?Jesper_Nyg=C3=A5rds?= Date: Mon, 12 Sep 2016 13:38:50 +0200 Message-ID: Subject: Three questions about a completer To: Zsh Users Content-Type: multipart/alternative; boundary=94eb2c19c6429dfaeb053c4df019 --94eb2c19c6429dfaeb053c4df019 Content-Type: text/plain; charset=UTF-8 I have a completer function that I have bound with menu-complete to alt-e (or alt-E for reverse-menu-complete). The relevant code is below. I have simplified what it does to generate the alternatives to not obscure what I cannot get to work. setopt BASH_AUTO_LIST _list-result() { setopt LOCAL_OPTIONS EXTENDED_GLOB local -a hlist if [[ -n $NUMERIC ]]; then hlist=($HOME/*); else hlist=(/etc/*); fi [[ -n $words[CURRENT] ]] && hlist=(${(M)hlist:#(#i)*$words[CURRENT]*}) compadd -V list_result -U -- $hlist } zle -C list-comp menu-complete _list-result bindkey '\ee' list-comp zstyle ':completion:list-comp:*:*' menu no zle -C rev-list-comp reverse-menu-complete _list-result bindkey '\eE' rev-list-comp zstyle ':completion:rev-list-comp:*:*' menu no This works reasonably well, but I have three questions: 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 achieve this, I have had to set the option BASH_AUTO_LIST. If this option is not set, a list of alternatives is displayed as soon as I hit alt-e (and at the same time the first alternative is put on the command line, which is good). But I don't want this option to be set globally. I have not been able to figure out how to make this menu NOT appear for this particular completion, but without setting the global option. Is there a way to achieve this? 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. 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. 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 can hit alt-1 and then alt-e and it gives me the matches from the alternative directory. However, only alt-1 works. If I hit alt-2, the NUMERIC variable is of course set to 2, and this makes the menu-completion skip 2 places in the list every time I repeat alt-e. In other, non-completion widgets, I have used this: "[[ -n $NUMERIC ]] && NUMERIC=1", but it seems I cannot do this in a completion widget. I get: "read-only variable: NUMERIC". Is there a better alternative to just have one keybinding for a widget, but sometimes triggering an alternative behaviour with a prefix? (I realise if I restrict myself to only hitting alt-1 it works, but it's a bit limited). --94eb2c19c6429dfaeb053c4df019--