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

Re: Cannot use LBUFFER+= nor print -zr from zsh/sched call



On Sep 11, 11:28am, Sebastian Gniazdowski wrote:
}
}     zle .redisplay
}     zle .kill-buffer
}     LBUFFER+="${(j:; :)commands[@]}"
}     print -zr "${(j:; :)commands[@]}"
}     print -rl -- "${commands[@]}"
} 
} And command line isn't feed with the $commands.

Commands added with "sched" are handled in two different ways:  There
is one check just before the prompt is printed -- effectively at the
same time as the precmd function/hooks -- and then there is a check
each time the keyboard input loop finds that it has been sitting idle.
So a sched will never fire while you're rapidly typing something.

The reason LBUFFER seems not to work is because sched functions are not
ZLE widgets, and the ZLE buffer variables are only active during the
execution of a widget.

"print -zr ..." DOES work, but unless it happens during the pre-prompt
check the commands pushed onto the buffer stack will not be popped onto
the command line until the next time zle restarts (after some subsequent
prompt).

So what you need to do is make a widget for your sched command to run,
and then modify LBUFFER inside that widget (and call "zle redisplay"
to make the change be visible, or pass the -o option to sched, but not
both or you'll get extra blank lines printed).

Here's a completely useless example:

fiddle() { if zle; then zle fiddlewid; else print -zr "echo fiddled"; fi }
fiddlewid() { LBUFFER+="echo fiddled"; zle redisplay }
zle -N fiddlewid
sched +3 fiddle



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