From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Scott Frazer <frazer.scott@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: Interactive search on the command line?
Date: Thu, 3 Dec 2015 23:39:26 +0000 [thread overview]
Message-ID: <20151203233926.GF1955@tarsus.local2> (raw)
In-Reply-To: <CAGjUN-TEPKNr3fKfUvL1JBtZN9y2jrw9m1kjstggEeR+12gjcA@mail.gmail.com>
Scott Frazer wrote on Wed, Dec 02, 2015 at 08:15:57 -0500:
> On Sun, Nov 29, 2015 at 10:19 PM, Daniel Shahaf <d.s@daniel.shahaf.name>
> 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
<TAB>.
>
> > 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
next prev parent reply other threads:[~2015-12-03 23:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-26 8:04 Dominik Vogt
2015-11-26 8:20 ` Mikael Magnusson
2015-11-27 7:03 ` lilydjwg
2015-11-27 7:34 ` Daniel Shahaf
2015-11-29 21:46 ` Scott Frazer
2015-11-30 3:19 ` Daniel Shahaf
2015-12-02 13:15 ` Scott Frazer
2015-12-03 23:39 ` Daniel Shahaf [this message]
2015-12-04 0:40 ` Ray Andrews
2015-12-04 0:50 ` Ray Andrews
2015-12-04 0:59 ` Bart Schaefer
2015-12-04 20:56 ` Scott Frazer
2015-12-05 10:00 ` Daniel Shahaf
2015-12-05 16:38 ` Mikael Magnusson
2015-12-05 21:07 ` Bart Schaefer
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=20151203233926.GF1955@tarsus.local2 \
--to=d.s@daniel.shahaf.name \
--cc=frazer.scott@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).