* Effect of "print -s" when called in zle widget not seen until zle is restarted
@ 2020-05-02 21:25 Stephane Chazelas
2020-05-10 10:07 ` [PATCH] [ping] " Stephane Chazelas
0 siblings, 1 reply; 3+ messages in thread
From: Stephane Chazelas @ 2020-05-02 21:25 UTC (permalink / raw)
To: Zsh hackers list
From
https://unix.stackexchange.com/questions/583443/adding-a-string-to-the-zsh-history
User https://unix.stackexchange.com/users/368116/noibe:
> The following function
>
> function test_hist() {
> print -s "This is a test"
> }
> zle -N test_hist
> bindkey '^X^T' test_hist
>
> adds the string This is a test to the zsh-history.
>
> If I call the function explicitly by typing test_hist, the
> string is immediately added to the history, but if I call it
> through the bindkey by pressing ctrl-x ctrl-t, the string is not
> added to the history straight away. I need to issue another
> command before I can see it in the history.
>
> Why is that, and how can I fix it?
My answer there:
I find that using fc -R =(print text) in place of print -s text
works consistently in and out of a zle widgets though, so it
could be a work around for you.
Looking at the code of zsh 5.8, I find that fc -R seems to let
zle know that a new history entry has been added when it detects
zle is active, while print -s doesn't.
This patch (on the current git head as of
2020-05-02T22:20+01:00) seems to fix it:
diff --git a/Src/builtin.c b/Src/builtin.c
index 3dab3f9b4..551653508 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -4918,6 +4918,8 @@ bin_print(char *name, char **args, Options ops, int func)
ent->stim = ent->ftim = time(NULL);
ent->node.flags = 0;
addhistnode(histtab, ent->node.nam, ent);
+ if (zleactive)
+ zleentry(ZLE_CMD_SET_HIST_LINE, curhist);
unqueue_signals();
return 0;
}
Not sure if that's the right fix though. I'll submit it to
zsh-workers@zsh.org.
Hence this email.
--
Stephane
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] [ping] Effect of "print -s" when called in zle widget not seen until zle is restarted
2020-05-02 21:25 Effect of "print -s" when called in zle widget not seen until zle is restarted Stephane Chazelas
@ 2020-05-10 10:07 ` Stephane Chazelas
2020-05-21 5:09 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Stephane Chazelas @ 2020-05-10 10:07 UTC (permalink / raw)
To: Zsh hackers list
[Repost as it looks like it was missed the first time round.]
From
https://unix.stackexchange.com/questions/583443/adding-a-string-to-the-zsh-history
User https://unix.stackexchange.com/users/368116/noibe:
> The following function
>
> function test_hist() {
> print -s "This is a test"
> }
> zle -N test_hist
> bindkey '^X^T' test_hist
>
> adds the string This is a test to the zsh-history.
>
> If I call the function explicitly by typing test_hist, the
> string is immediately added to the history, but if I call it
> through the bindkey by pressing ctrl-x ctrl-t, the string is not
> added to the history straight away. I need to issue another
> command before I can see it in the history.
>
> Why is that, and how can I fix it?
My answer there:
I find that using fc -R =(print text) in place of print -s text
works consistently in and out of a zle widgets though, so it
could be a work around for you.
Looking at the code of zsh 5.8, I find that fc -R seems to let
zle know that a new history entry has been added when it detects
zle is active, while print -s doesn't.
This patch (on the current git head as of
2020-05-02T22:20+01:00) seems to fix it:
diff --git a/Src/builtin.c b/Src/builtin.c
index 3dab3f9b4..551653508 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -4918,6 +4918,8 @@ bin_print(char *name, char **args, Options ops, int func)
ent->stim = ent->ftim = time(NULL);
ent->node.flags = 0;
addhistnode(histtab, ent->node.nam, ent);
+ if (zleactive)
+ zleentry(ZLE_CMD_SET_HIST_LINE, curhist);
unqueue_signals();
return 0;
}
Not sure if that's the right fix though. I'll submit it to
zsh-workers@zsh.org.
Hence this email.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] [ping] Effect of "print -s" when called in zle widget not seen until zle is restarted
2020-05-10 10:07 ` [PATCH] [ping] " Stephane Chazelas
@ 2020-05-21 5:09 ` Bart Schaefer
0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2020-05-21 5:09 UTC (permalink / raw)
To: Zsh hackers list
On Sun, May 10, 2020 at 3:08 AM Stephane Chazelas <stephane@chazelas.org> wrote:
>
> [Repost as it looks like it was missed the first time round.]
I got it both times, FWIW.
> > function test_hist() {
> > print -s "This is a test"
> > }
> >
> > If I call the function explicitly by typing test_hist, the
> > string is immediately added to the history, but if I call it
> > through the bindkey by pressing ctrl-x ctrl-t, the string is not
> > added to the history straight away. I need to issue another
> > command before I can see it in the history.
> >
> > Why is that, and how can I fix it?
I think that's actually intentional, and changing it might break
contributed functions such as zcalc, sticky-note, and nslookup.
There appears to be some interaction with "vared -h" that changes when
the ZLE_CMD_SET_HIST_LINE entry point is used.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-05-21 5:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-02 21:25 Effect of "print -s" when called in zle widget not seen until zle is restarted Stephane Chazelas
2020-05-10 10:07 ` [PATCH] [ping] " Stephane Chazelas
2020-05-21 5:09 ` Bart Schaefer
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).