zsh-users
 help / color / mirror / code / Atom feed
* how to execute zle widget during zsh-init?
@ 2004-08-16 21:46 Andy Spiegl
  2004-08-17  3:14 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Spiegl @ 2004-08-16 21:46 UTC (permalink / raw)
  To: ZSH User List

Back in 2003 Peter Stephenson kindly added the possibility to increase the
size of the zle kill-ring.  As suggested I wrote a ZLE widget that makes
use of this feature and sets the size to 30:

-------------
# increase the size of zle kill ring to 30

emulate -L zsh

: ${NUMERIC:=30}
while (( NUMERIC-- )); do killring+=(''); done
-------------

But now I can't find a practial way to "execute" it every time I start y
new shell because it has to be done from inside zle. :-(

Does anyone have an idea how this can be done?
Thanks!
 Andy.

-- 
                              o      _     _         _
  ------- __o       __o      /\_   _ \\o  (_)\__/o  (_)          -o)
  ----- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/       /\\
  ---- (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_    _\_v
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 If people from Poland are called Poles,
 why aren't people from Holland called Holes?  (George Carlin, US comedian)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to execute zle widget during zsh-init?
  2004-08-16 21:46 how to execute zle widget during zsh-init? Andy Spiegl
@ 2004-08-17  3:14 ` Bart Schaefer
  2004-08-17 16:22   ` Andy Spiegl
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2004-08-17  3:14 UTC (permalink / raw)
  To: ZSH User List

On Mon, 16 Aug 2004, Andy Spiegl wrote:

> -------------
> # increase the size of zle kill ring to 30
> 
> emulate -L zsh
> 
> : ${NUMERIC:=30}
> while (( NUMERIC-- )); do killring+=(''); done
> -------------

That could be more compactly written as

    grow-killring() {
	setopt localoptions noksharrays
	: ${killring[${NUMERIC:-30}]:=''}
    }

Arrays automatically grow to accomodate the largest element into which you 
store a value, even if you don't use the intervening elements.

> But now I can't find a practial way to "execute" it every time I start a
> new shell because it has to be done from inside zle. :-(

    zle-line-init() {
	zle grow-killring
	zle -D zle-line-init
    }
    zle -N zle-line-init


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to execute zle widget during zsh-init?
  2004-08-17  3:14 ` Bart Schaefer
@ 2004-08-17 16:22   ` Andy Spiegl
  2004-08-17 21:27     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Spiegl @ 2004-08-17 16:22 UTC (permalink / raw)
  To: ZSH User List

Hi Bart,

but zle-line-init() is called every time zle starts, i.e. before a prompt
is shown.  Isn't that overkill? :-)

> zle-line-init
>  Executed every time the line editor is started to read a new line of input

Besides that doubt I can't get it to work.  I put the function
zle-line-init into my .zshrc, but where do I put the definition of the
function grow-killring?  zsh complains:
 "No such widget `grow-killring'"

Thanks again,
 Andy.

-- 
                              o      _     _         _
  ------- __o       __o      /\_   _ \\o  (_)\__/o  (_)          -o)
  ----- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/       /\\
  ---- (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_    _\_v
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 "In a cat's eye, all things belong to cats."  --English proverb


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to execute zle widget during zsh-init?
  2004-08-17 16:22   ` Andy Spiegl
@ 2004-08-17 21:27     ` Bart Schaefer
  2004-08-18  1:19       ` Andy Spiegl
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2004-08-17 21:27 UTC (permalink / raw)
  To: ZSH User List

On Tue, 17 Aug 2004, Andy Spiegl wrote:

> but zle-line-init() is called every time zle starts, i.e. before a prompt
> is shown.  Isn't that overkill? :-)

That's why I put "zle -D zle-line-init" in there.  The widget executes 
once (the first time zle initializes) and then ceases to be a widget, so
it never executes again.

> Besides that doubt I can't get it to work.  I put the function 
> zle-line-init into my .zshrc, but where do I put the definition of the 
> function grow-killring?

I presumed you had that somewhere already, because of the implementation
you had included.  I didn't know what you called it so I made up a name.
I supposed e.g. that you had pasted in the content of an autoload file.

The full solution (with apologies to others that this repeats most of my 
previous post) could all be in .zshrc and would then look something like

    grow-killring() {
        setopt localoptions noksharrays
        : ${killring[${NUMERIC:-30}]:=''}
    }
    zle -N grow-killring
                                                                                
    zle-line-init() {
        zle grow-killring
        zle -D zle-line-init
    }
    zle -N zle-line-init


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to execute zle widget during zsh-init?
  2004-08-17 21:27     ` Bart Schaefer
@ 2004-08-18  1:19       ` Andy Spiegl
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Spiegl @ 2004-08-18  1:19 UTC (permalink / raw)
  To: zsh-users

> The full solution (with apologies to others that this repeats most of my 
> previous post) could all be in .zshrc and would then look something like
Thanks again, now it works like a charm.
 Andy.

-- 
                              o      _     _         _
  ------- __o       __o      /\_   _ \\o  (_)\__/o  (_)          -o)
  ----- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/       /\\
  ---- (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_    _\_v
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 43rd Law of Computing:
         Anything that can go wr
 fortune: Segmentation violation -- Core dumped


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-08-18  1:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-16 21:46 how to execute zle widget during zsh-init? Andy Spiegl
2004-08-17  3:14 ` Bart Schaefer
2004-08-17 16:22   ` Andy Spiegl
2004-08-17 21:27     ` Bart Schaefer
2004-08-18  1:19       ` Andy Spiegl

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).