From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12461 invoked by alias); 3 Dec 2015 23:39:34 -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: 21038 Received: (qmail 15547 invoked from network); 3 Dec 2015 23:39:32 -0000 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-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=zxrVug8Fj2mmFZ7p/bHRFYUzQxI=; b=zTfUr3 TuZ77h8c2wsxFBEtWuxeOkpI/7gBrFN4sGPQXdd0+EKIfa3fGAEVY8gyq9BFgpEm NysSy9u1vupKrMVUInDXtbT4JMWHfuejdufHloxFQONGTiKBg6MFO6SAqQLnhBEF uf17Y5ho7JsE2uLiNf3wiC7OGJsjeFjoQb7EA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=smtpout; bh=zxrVug8Fj2mmFZ7p/bHRFYUzQxI=; b=TXtyu ANTuwuYciU62pTRuR4popBiU210+uFYO2FVlcpTHLVMS2nK81FK6G1W+zU0KEL1H sckzyp0rZlcLvGaMXMlIEJZItBA8ItQhrf/lAzjAKrtZ/BbsTYiCGzDCSVtBkwXj XKcINoX7txiGct8018nnXxYxz5f8dkdPxUUiHE= X-Sasl-enc: SBhHd8XexRm5bXtDwhdvBd627sQo+IOevIOUYXpB8nIF 1449185968 Date: Thu, 3 Dec 2015 23:39:26 +0000 From: Daniel Shahaf To: Scott Frazer Cc: zsh-users@zsh.org Subject: Re: Interactive search on the command line? Message-ID: <20151203233926.GF1955@tarsus.local2> References: <20151126080400.GA20074@linux.vnet.ibm.com> <565B723B.70900@gmail.com> <20151130031915.GD2504@tarsus.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Scott Frazer wrote on Wed, Dec 02, 2015 at 08:15:57 -0500: > On Sun, Nov 29, 2015 at 10:19 PM, Daniel Shahaf > wrote: > > > I wouldn't know you were new to zsh if you didn't say so; the code looks > > as good as anyone's. The one thing I would suggest is to use the > > ${BUFFER[(i)$char]} syntax in the 'for' loop, which should translate to > > a strchr() or strstr() call at the C level. (There's also the > > ${(ps:$char:)BUFFER} syntax, but I'm not sure it gains you anything.) > > > > > I tried the (i) thing but the function stopped working. I couldn't > find what it was supposed to do in the zsh manual, only something > about use as a flag for case-insensitive search which doesn't seem > relevant. A parenthesized "i" after an opening brace of parameter substitution means "sort case-insensitively": % a=(Foo bar) ; print ${(oi)a} bar Foo A parenthesized "i" after a subscript's bracket is a strstr() flag: % s=foobar x=b % print ${s[(i)$x]} 4 The latter is documented in "Subscript Flags" in zshparam(1). (It took me a little while to find that; I checked zshexpn(1) first.) So, you could do something like this (using the (b::) subscript flag as well): % () { local haystack="$1" local needle="a" integer idx while (( idx = ${haystack[(ib:idx+1:)${needle}]} )) (( idx <= $#haystack )) do print -r - $haystack[idx,idx+$#needle-1] done } foobar a % > How do people debug these types of things? You mean, how people look up flags? Just type ": ${(" and then press . > > > Also, three minor points: > > > > - With recent zsh, WARN_CREATE_GLOBAL complains: > > (anon):1: scalar parameter ZSH_JUMP_TARGET_CHOICES created globally in > > function (anon) > > (anon):2: scalar parameter ZSH_JUMP_TARGET_STYLE created globally in > > function (anon) > > The fix is to declare these parameters either global ('typeset -g') or > > 'local'. > > > > - You could use 'region_highlight+=("foo bar baz")' to append to the array. > > > > - You might use an 'always' block to restore $orig_region_highlight. > > > > P.S. Perhaps you could throw a LICENSE file into that repository? > > > > > Thanks for the feedback, I fixed all these things. Thanks, LGTM. Daniel