Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: pushing a string in the cut&paste stack



"Giulio Bottazzi" wrote:
> I would like to know how can I push a string in the cut&paste stack of
> zle. In practice, I would like to have a shell function, name it
> "copythis", such that
> 
> > copythis "blabla"
> 
> will insert the string "blabla" in the stack, so that can later
> recover it using the ctrl-y/alt-y mechanism (emacs key map).

If you have a recent version of the shell, you can do this:

zle-line-init () {
  if [[ -n $copy_this ]]
  then
    CUTBUFFER=$copy_this
    copy_this=
  fi
}
zle -N zle-line-init
copythis() { copy_this="$*"; }

It's that complicated because CUTBUFFER only exists as a special
parameter once the line editor has started.

If you want to manipulate the editing stack (save the old value of the
the cut buffer onto the kill ring in the way the kill commands do) you
will need to use the array kill_ring.  See the function kill-word-match
distributed with the shell for an example.  (One day I should make it so
that copy-region-as-kill can take a string argument when called from an
editor widget.)

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview



Messages sorted by: Reverse Date, Date, Thread, Author