zsh-workers
 help / color / mirror / code / Atom feed
From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.dk
Subject: Working with the historywords special parameter
Date: Fri, 24 Aug 2001 10:16:07 +0200	[thread overview]
Message-ID: <15238.3399.455051.715190@gargle.gargle.HOWL> (raw)
In-Reply-To: <20010824065417.34532.qmail@web10408.mail.yahoo.com>


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.
> 
> 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.  It seems like you need to iterate over the elements of an array
> via an expression like:
> 
>     #the_word is $words[CURRENT-1]
>     cnt=2
>     words=()
>     while [[ $historywords[(in:cnt:)the_word] -lt  $#historywords  ]] ; do
>        words=($words $historywords[$historywords[(in:cnt:)the_word]-1]
>        let "cnt = cnt + 1" 
>     done
> 
> Is there a faster way to do this?

I don't see anything faster than:

  local i length cnt=2 words hist
  words=()
  hist=($historywords)
  length=$#hist
  while (( ( i=$hist[(in:cnt++:)$the_word] ) <= length )); do
    words=($words $hist[i-1])
  done

Maybe ${(Mk)historywords:#$the_word} should expand to the list of
the indices of the words equal to $the_word.

> ...
> 
> 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 ask since one of the problems
> with this completer is that it picks up false "matches" when the
> previous word is the last word of a previous command, it gets the next command.
> 
> It would be nice to be able to determine if a word is the last word of
> the line, or what the first word of the line is.

Or maybe give that new array another name and let it report not only
the line but also other information, e.g. the position on the line
(word number and character positions so that that could be used to
index into the values of the history assoc).


Bye
  Sven

-- 
Sven Wischnowsky                    wischnow@informatik.hu-berlin.de


  reply	other threads:[~2001-08-24  8:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-24  6:54 Felix Rosencrantz
2001-08-24  8:16 ` Sven Wischnowsky [this message]
2001-08-24 17:05   ` Bart Schaefer
2001-08-28  6:19     ` Felix Rosencrantz
2001-08-28 15:16       ` Bart Schaefer
2001-08-28  6:24     ` Seg Fault in paramsubst() Felix Rosencrantz
2001-08-28  8:35       ` PATCH: " Sven Wischnowsky

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=15238.3399.455051.715190@gargle.gargle.HOWL \
    --to=wischnow@informatik.hu-berlin.de \
    --cc=zsh-workers@sunsite.dk \
    /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).