zsh-workers
 help / color / mirror / code / Atom feed
* Re: functions in prompts evaluated twice?
       [not found] <20080309115652.GP30518@fsst.voodoo.lan>
@ 2008-03-09 16:15 ` Bart Schaefer
  0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 2008-03-09 16:15 UTC (permalink / raw)
  To: zsh-workers, Frank Terbeck

[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);
 }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-03-09 16:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20080309115652.GP30518@fsst.voodoo.lan>
2008-03-09 16:15 ` functions in prompts evaluated twice? 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).