From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17754 invoked from network); 24 Aug 2001 17:06:24 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 24 Aug 2001 17:06:24 -0000 Received: (qmail 537 invoked by alias); 24 Aug 2001 17:06:09 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 15706 Received: (qmail 522 invoked from network); 24 Aug 2001 17:06:05 -0000 From: Bart Schaefer Message-Id: <1010824170526.ZM28196@candle.brasslantern.com> Date: Fri, 24 Aug 2001 17:05:26 +0000 References: <20010824065417.34532.qmail@web10408.mail.yahoo.com> <15238.3399.455051.715190@gargle.gargle.HOWL> X-Mailer: Z-Mail (5.0.0 30July97) To: Felix Rosencrantz , zsh-workers@sunsite.dk Subject: Re: Working with the historywords special parameter MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Aug 23, 11:54pm, Felix Rosencrantz wrote: } } I'm trying to create a completer that uses the previous word on the line } and the special parameter historywords to determine what values current } word should be. Have you tried using $history instead of $historywords? You want the word that comes immediately after $words[CURRENT-1] in every history line that contains $word[CURRENT-1], right? local w p h r w=${(q)words[CURRENT-1]} p=$'\0'$w$'\0' h=$'\0'${(pj:\0:)${(z)history[(R)*$w*]}} r=( ${${(ps:\1:)h//$~p/$'\1'}%%$'\0'*} ) compadd -a r This assumes there are no literal NUL or ctrl-A characters in the history, but that seems a pretty safe assumption. } It looks to me like there is no single expression that can be used to } get just the list of all the elements that match an expression from an } array. That's a different question. You want a list of the indices of all the elements that match $words[CURRENT-1]? integer n=0 local ixs p="(#b)((#s)(${(q)words[CURRENT-1]})(#e)|*)" ixs=( ${${(M)${historywords//$~p/$((++n))=$match[2]}:#<->\=?##}%\=*} ) This takes advantage of the fact that alternate matches with `|' are tried left to right; it wouldn't work with (*|...). To get the nth element after the element that matches the word, just start n at a larger number, e.g. n=1 for your specific example. } Would anyone object to a new special parameter (maybe historywordsnums) } that has corresponding elements to historywords saying with which } history line the word is associated? I won't object, but it's not really necessary, is it? You can get it from ${(k)history[(R)word]}. On Aug 24, 10:16am, Sven Wischnowsky wrote: } } Maybe ${(Mk)historywords:#$the_word} should expand to the list of } the indices of the words equal to $the_word. That's an interesting thought. It's equivalent to what I invented above but not quite as flexible. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net