From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: (qmail 30453 invoked from network); 2 May 2020 21:26:09 -0000 Received-SPF: pass (primenet.com.au: domain of zsh.org designates 203.24.36.2 as permitted sender) receiver=inbox.vuxu.org; client-ip=203.24.36.2 envelope-from= Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 2 May 2020 21:26:09 -0000 Received: (qmail 29452 invoked by alias); 2 May 2020 21:26:03 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45762 Received: (qmail 472 invoked by uid 1010); 2 May 2020 21:26:03 -0000 X-Qmail-Scanner-Diagnostics: from relay6-d.mail.gandi.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.2/25793. spamassassin: 3.4.4. Clear:RC:0(217.70.183.198):SA:0(-2.6/5.0):. Processed in 1.631267 secs); 02 May 2020 21:26:03 -0000 X-Envelope-From: stephane@chazelas.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _nblcust.gandi.net designates 217.70.183.198 as permitted sender) X-Originating-IP: 94.3.152.49 Date: Sat, 2 May 2020 22:25:17 +0100 From: Stephane Chazelas To: Zsh hackers list Subject: Effect of "print -s" when called in zle widget not seen until zle is restarted Message-ID: <20200502212517.v36yw3jv7x3zxzho@chazelas.org> Mail-Followup-To: Zsh hackers list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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