From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9278 invoked from network); 9 Mar 2008 16:15:37 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 9 Mar 2008 16:15:37 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 26424 invoked from network); 9 Mar 2008 16:15:30 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 9 Mar 2008 16:15:30 -0000 Received: (qmail 11809 invoked by alias); 9 Mar 2008 16:15:26 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24703 Received: (qmail 11794 invoked from network); 9 Mar 2008 16:15:25 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 9 Mar 2008 16:15:25 -0000 Received: from vms173003pub.verizon.net (vms173003pub.verizon.net [206.46.173.3]) by bifrost.dotsrc.org (Postfix) with ESMTP id A9DC98028AEE for ; Sun, 9 Mar 2008 17:15:21 +0100 (CET) Received: from torch.brasslantern.com ([71.116.89.42]) by vms173003.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JXH0064G10N3Z90@vms173003.mailsrvcs.net> for zsh-workers@sunsite.dk; Sun, 09 Mar 2008 11:12:24 -0500 (CDT) Received: from torch.brasslantern.com (localhost.localdomain [127.0.0.1]) by torch.brasslantern.com (8.13.1/8.13.1) with ESMTP id m29GFElg016658; Sun, 09 Mar 2008 09:15:14 -0700 Received: (from schaefer@localhost) by torch.brasslantern.com (8.13.1/8.13.1/Submit) id m29GFD5J016657; Sun, 09 Mar 2008 09:15:13 -0700 Date: Sun, 09 Mar 2008 09:15:13 -0700 From: Bart Schaefer Subject: Re: functions in prompts evaluated twice? In-reply-to: <20080309115652.GP30518@fsst.voodoo.lan> To: zsh-workers@sunsite.dk, Frank Terbeck Message-id: <080309091513.ZM16656@torch.brasslantern.com> MIME-version: 1.0 X-Mailer: OpenZMail Classic (0.9.2 24April2005) Content-type: text/plain; charset=us-ascii References: <20080309115652.GP30518@fsst.voodoo.lan> Comments: In reply to Frank Terbeck "functions in prompts evaluated twice?" (Mar 9, 12:56pm) X-Virus-Scanned: ClamAV 0.91.2/6184/Sun Mar 9 16:03:41 2008 on bifrost X-Virus-Status: Clean [Redirected to -workers] On Mar 9, 12:56pm, Frank Terbeck wrote: } } I was about to use the output of a function in my prompt, when I } noticed, that it was evaluated twice. That's definitely new in 4.3.x. The first time it's expanded is here: [...] #12 0x080aa9b7 in promptexpand (s=0xb7d281d8 "", ns=1, rs=0x0, Rs=0x0) at ../../zsh-4.3/Src/prompt.c:170 #13 0x0811a8ed in zleread (lp=0x8166a48, rp=0x0, flags=3, context=0) at ../../../zsh-4.3/Src/Zle/zle_main.c:1135 #14 0x0807c541 in inputline () at ../../zsh-4.3/Src/input.c:278 #15 0x0807c3f8 in ingetc () at ../../zsh-4.3/Src/input.c:214 #16 0x08072eca in ihgetc () at ../../zsh-4.3/Src/hist.c:240 #17 0x08083bbf in gettok () at ../../zsh-4.3/Src/lex.c:663 #18 0x0808349f in yylex () at ../../zsh-4.3/Src/lex.c:350 #19 0x0809daf8 in parse_event () at ../../zsh-4.3/Src/parse.c:451 #20 0x0807926e in loop (toplevel=1, justonce=0) at ../../zsh-4.3/Src/init.c:129 #21 0x0807c041 in zsh_main (argc=2, argv=0xbff9c9d4) The second time is here: [...] #12 0x080aa9b7 in promptexpand (s=0xb7d282c0 "", ns=1, rs=0x0, Rs=0x0) at ../../zsh-4.3/Src/prompt.c:170 #13 0x0811c52e in reexpandprompt () at ../../../zsh-4.3/Src/Zle/zle_main.c:1702 #14 0x081218b4 in zrefresh () at ../../../zsh-4.3/Src/Zle/zle_refresh.c:554 #15 0x0811ab26 in zleread (lp=0x8166a48, rp=0x0, flags=3, context=0) at ../../../zsh-4.3/Src/Zle/zle_main.c:1181 #16 0x0807c541 in inputline () at ../../zsh-4.3/Src/input.c:278 #17 0x0807c3f8 in ingetc () at ../../zsh-4.3/Src/input.c:214 #18 0x08072eca in ihgetc () at ../../zsh-4.3/Src/hist.c:240 #19 0x08083bbf in gettok () at ../../zsh-4.3/Src/lex.c:663 #20 0x0808349f in yylex () at ../../zsh-4.3/Src/lex.c:350 #21 0x0809daf8 in parse_event () at ../../zsh-4.3/Src/parse.c:451 #22 0x0807926e in loop (toplevel=1, justonce=0) at ../../zsh-4.3/Src/init.c:129 #23 0x0807c041 in zsh_main (argc=2, argv=0xbff9c9d4) The fix is *either* to clear trashedzle in zleread(), or to *set* trashedzle in zleread() and remove the stuff that computes the prompt there. However, I'm a unsure of which to do, because reexpandprompt() doesn't do all the same steps as zleread(). However, I tried the latter approach and got a core dump, so here's a short patch that does the former. The second hunk is cosmetic. Index: Src/Zle/zle_main.c --- zsh-forge/current/Src/Zle/zle_main.c 2008-02-16 08:22:31.000000000 -0800 +++ Src/Zle/zle_main.c 2008-03-09 09:12:20.000000000 -0700 @@ -1131,6 +1131,7 @@ eofsent = 0; resetneeded = 0; fetchttyinfo = 0; + trashedzle = 0; raw_lp = lp; lpromptbuf = promptexpand(lp ? *lp : NULL, 1, NULL, NULL); pmpt_attr = txtchange; @@ -1721,7 +1722,8 @@ /**/ mod_export void zle_resetprompt(void) -{ reexpandprompt(); +{ + reexpandprompt(); if (zleactive) redisplay(NULL); }