Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID
	autolearn=ham autolearn_force=no version=3.4.0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=brasslantern-com.20150623.gappssmtp.com; s=20150623;
        h=from:message-id:date:in-reply-to:comments:references:to:subject
         :mime-version:content-type;
        bh=KNSmWQ3iRFA3PDgeIlVxwRmq1UGWlQLP+EbxGvvxQZk=;
        b=ErRSKH5NW6CS4NYRCb8lcwSvUxETvRzQiWv6ncKLP2JZNMX8zrMVvgvwnGsRYsfLXY
         HmHlepKALi1/czFY3Oud8iEcxmZ29XKigDLxZShi7W6UmDP4hEPJNTP3a3M91Pfcnxhf
         d7t0HXweQlUmeqA/rZ2KNcqleFkWfDHlD+R8aBwbmU0C1rWAq8SvKXQas4K5zbN0EHKj
         M/ZsHiwDzpxroMsvpG4GnZGLxMLiV0DjnqnzPU++Xrzx4AFrRYHMHAEyC29YXWWcfpXC
         9ePIddisHNpKR9EIy98zneQ0pe6aXeCTCdNqTeKu8ios66YZWTrZ5fTApy3E6hiq+lWP
         SlLw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:date:in-reply-to:comments
         :references:to:subject:mime-version:content-type;
        bh=KNSmWQ3iRFA3PDgeIlVxwRmq1UGWlQLP+EbxGvvxQZk=;
        b=V9QlRlhGPkwFk2TYlVJKSxmgdHPiwsu8Ny4hbUS/4SdW9evHmGVn9+3j74yYw756KP
         3otutrNvMZmqLP+bUHTEVt8im+LCY6bGtnAewcBkY+J995SStOzPl+vD8QN6hYseJ0vk
         1xapzGok2Dcl3L109KJV66n3cFSEkcR62PRbu57I7QCnGLCwFqdh8mYIYUB53glVGOwd
         qOZmKq9+LInX+NZvCBN+b9t8p1fVci77r8liX7/Q/dqZcAVNkhHX99ZEPrlM4K4R/kkP
         FTz0JtwePqhl9SYIhpV1ed7JPKo1iJbVRp8mhJ5bCSEcEOabFVR7XPZZowmjpzUJE90O
         qPNw==
X-Gm-Message-State: ALoCoQl7wAiP6m0TGf9nnrONXrKZj0DEWpvBgxrfF4xmo6o53BtExe1qQ1SOu1DOzIbVQ20YxZPK0SyV/+1K7I5iv4wI8s1grw==
X-Received: by 10.66.141.165 with SMTP id rp5mr125663230pab.56.1452557688060;
        Mon, 11 Jan 2016 16:14:48 -0800 (PST)
From: Bart Schaefer <schaefer@brasslantern.com>
Message-Id: <160111161501.ZM5305@torch.brasslantern.com>
Date: Mon, 11 Jan 2016 16:15:01 -0800
In-Reply-To: <CAKc7PVDVR=B8SWX+gSiNvtODWZ-25LtDz7jXVDH8BtrcxMnjXQ@mail.gmail.com>
Comments: In reply to Sebastian Gniazdowski <sgniazdowski@gmail.com>
        "Re: _history-complete-older problems with $(" (Jan 11,  5:21pm)
References: <CAKc7PVCnEX1rEhNqhtx7spyUVKCWukz4Tzkqr27-OV9+4hVciQ@mail.gmail.com> 
	<CAKc7PVDVR=B8SWX+gSiNvtODWZ-25LtDz7jXVDH8BtrcxMnjXQ@mail.gmail.com>
X-Mailer: OpenZMail Classic (0.9.2 24April2005)
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: _history-complete-older problems with $(
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Seq: zsh-workers 37565

On Jan 11,  5:21pm, Sebastian Gniazdowski wrote:
} Subject: Re: _history-complete-older problems with $(
}
} on IRC it came up that $( is a start of a subshell and that it makes
} completion start over at this place. Seems that $(( works in the same
} way. Is there any possibility to change that? Even at level of C code?

The following produces the correct set of completion matches (pardon the
unimaginative name) but is a bit of a hack (it breaks _complete_debug
and _complete_help):

  _widen_for_history () {
    local -a left=( "${(z)LBUFFER}" )
    local right="${words[CURRENT]#${left[-1]}}"
    words=( "${(z)BUFFER}" )
    CURRENT=${#left}
    PREFIX="${left[-1]}"
    IPREFIX=''
    SUFFIX="${right}"
    ISUFFIX=''
    {
      compadd () {
	local -a found
	builtin compadd -O found "$@"
	builtin compadd -Q -U "${(@)${(@)found#$PREFIX}%$SUFFIX}"
      }
      _history
    } always {
      unfunction compadd
    }
  }
  zstyle ':completion:*' completer _widen_for_history _complete

This needs some work around the issue of empty words, i.e., when
completing in empty parens such as $(<TAB>) then $words[CURRENT] is
empty and the trailing paren must be copied from $RBUFFER to SUFFIX.
I haven't dived into that detail.

It could be further refined (with a lot of work) to widen only to the
next "outward" command, e.g., in

  foo $(bar $(<TAB>

to extend back only as far as "bar" rather than to "foo", which might
turn out to be important for some multi-line buffers, I'm not sure.

Another approach would be to create a custom key binding for a widget
which

- inserts an open quote before the current word
- invokes completion with completer style set to _history
- removes quoting again

but that has its own complications if the word on the line is already
quoted, etc.

