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

Re: Calling a zle widget from a function

Angel Olivera wrote:
> So I would love to be able to call zle's clear-screen widget from the
> function.
> redondos@refinery ~ % zle clear-screen
> zle: widgets can only be called when ZLE is active

If you have version 4.3.4 the sched mechanism will call functions
asynchronously within zle, if that's running.  So something like

  clear-zle-screen() {
    zle && zle clear-screen
    sched +60 clear-zle-screen
  sched +60 clear-zle-screen

does the basics.  However, it will attempt to clear the screen *every*
60 seconds, not just after 60 seconds of idleness.  One possible way
around that is to look at the modification time for the terminal and compare
it with the current time:

  clear-zle-screen() {
    zmodload -i zsh/stat
    zmodload -i zsh/datetime
    local -a mtime
    integer diff

    stat -A mtime +mtime $TTY
    (( diff = EPOCHSECONDS - ${mtime} ))
    if (( diff > 60 )); then
      zle && zle clear-screen
      sched +60 clear-zle-screen
      sched +$(( 60 - diff )) clear-zle-screen

(I needed to use $TTY, not /dev/tty, on the Fedora Core 6 system I have
here since they don't seem to be kept in sync.)

This doesn't work with 4.2 where sched is only run synchronously and
never from zle.  I think you'd have to do it in two steps: have the
timeout set a flag, and have some zle hook look at the timeout.  But
hooking into zle at that depth is quite painful.

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