zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Felix Rosencrantz <f_rosencrantz@yahoo.com>, zsh-workers@sunsite.dk
Subject: Re: Working with the historywords special parameter
Date: Fri, 24 Aug 2001 17:05:26 +0000	[thread overview]
Message-ID: <1010824170526.ZM28196@candle.brasslantern.com> (raw)
In-Reply-To: <15238.3399.455051.715190@gargle.gargle.HOWL>

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   


  reply	other threads:[~2001-08-24 17:06 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
2001-08-24 17:05   ` Bart Schaefer [this message]
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=1010824170526.ZM28196@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=f_rosencrantz@yahoo.com \
    --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).