zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Cannot use LBUFFER+= nor print -zr from zsh/sched call
Date: Sun, 11 Sep 2016 17:58:10 -0700	[thread overview]
Message-ID: <160911175810.ZM21350@torch.brasslantern.com> (raw)
In-Reply-To: <CAKc7PVCiy_phpQb=DTR-Td5ktDL2cDK=y_tUE3bTXVXVTm2AXA@mail.gmail.com>

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


  parent reply	other threads:[~2016-09-12  0:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-11  9:28 Sebastian Gniazdowski
2016-09-11 10:35 ` Sebastian Gniazdowski
2016-09-12  1:13   ` Bart Schaefer
2016-09-12 15:06     ` Bart Schaefer
2016-09-12 15:24       ` Sebastian Gniazdowski
2016-09-12 17:34         ` Bart Schaefer
2016-09-13 15:44           ` Sebastian Gniazdowski
2016-09-13 16:55             ` Bart Schaefer
2016-09-13 17:29               ` Sebastian Gniazdowski
2016-09-14  1:47                 ` Bart Schaefer
2016-09-14  5:13                   ` Sebastian Gniazdowski
2016-09-12  0:58 ` Bart Schaefer [this message]
2016-09-12  8:49   ` Peter Stephenson

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=160911175810.ZM21350@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /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).