zsh-workers
 help / color / mirror / code / Atom feed
* The mystery of deferred prompt evaluation
@ 1999-05-27 21:45 Nik Gervae
  1999-05-31  9:20 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Nik Gervae @ 1999-05-27 21:45 UTC (permalink / raw)
  To: zsh-workers

Folks--

If I do this in 3.0.5:

  PROMPT_LEN=3
  PROMPT_DYN='%${PROMPT_LEN}C'
  PROMPT='%0(#..)${PROMPT_DYN}% '

I get the really cool feature of being able to change PROMPT_LEN at
any point and having my prompt adjust how much of my path it shows.
Oddly enough, this only works if I put the %(...) construct before
the parameter reference in the prompt, if that isn't there then my
prompt ends up being the literal text of the definition, with the
parameter not getting expanded. I might add that in 3.1.5 the latter
behavior is always the case (which I when I first noticed this).

Does anyone know:

 a) Why I shouldn't be able to defer parameter expansion in my
    prompts in general?
 b) Why in 3.0.5 it works with %(...) before the parameter
    but not without?
 c) Why it doesn't work at all, ever, in 3.1.5?
 d) How I can get this behavior back? :-)

In case you're wondering why I would want something so convoluted,
I was trying to make life easier for the non-power users, so that
they could set a single variable and get as much of the prompt as
they wanted without having to learn all the details of prompt
syntax. I happened to have the $(...) there for another such
feature, which is why this happened to work for me for so long.

-- 
Nik Gervae < nik at linna dot com >
Techwriter, vegan, dilettante


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: The mystery of deferred prompt evaluation
  1999-05-27 21:45 The mystery of deferred prompt evaluation Nik Gervae
@ 1999-05-31  9:20 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 1999-05-31  9:20 UTC (permalink / raw)
  To: nik, zsh-workers

On May 27,  2:45pm, Nik Gervae wrote:
} Subject: The mystery of deferred prompt evaluation
}
}   PROMPT_LEN=3
}   PROMPT_DYN='%${PROMPT_LEN}C'
}   PROMPT='%0(#..)${PROMPT_DYN}% '
} 
} I get the really cool feature of being able to change PROMPT_LEN at
} any point and having my prompt adjust how much of my path it shows.
} Oddly enough, this only works if I put the %(...) construct before
} the parameter reference in the prompt, if that isn't there then my
} prompt ends up being the literal text of the definition, with the
} parameter not getting expanded. I might add that in 3.1.5 the latter
} behavior is always the case (which I when I first noticed this).

You're making use of an undocumented (mis)feature.  You've relied on
two levels of parameter expansion, which you're getting in 3.0.x only
by accident.

} Does anyone know:
} 
}  a) Why I shouldn't be able to defer parameter expansion in my
}     prompts in general?

You should, by use of the PROMPT_SUBST option, which you must have set
for any of this to happen even in 3.0.x.  What you can't expect is that
the expansion of a parameter is re-expanded when it happens to have a
$ in it, unless you tell zsh to do so.

}  b) Why in 3.0.5 it works with %(...) before the parameter
}     but not without?
}  c) Why it doesn't work at all, ever, in 3.1.5?

The 3.0.x prompt code calls itself recursively when it encounters a %( )
construct, which causes the PROMPT_SUBST option to be applied twice (or
more, if the nesting is deeper).  This was not supposed to happen, and
in fact is a bug if you're trying to get a prompt that contains a $ or
other special character.  Prompt display has been completely rewritten
for 3.1.5, so this no longer occurs.

}  d) How I can get this behavior back? :-)

Use the (e) parameter flag, like so:

  PROMPT_LEN=3
  PROMPT_DYN='%${PROMPT_LEN}C'
  PROMPT='${(e)PROMPT_DYN}% '

Or simply eliminate one level of indirection:

  PROMPT_LEN=3
  PROMPT='%${PROMPT_LEN}C% '


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-05-31  9:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-27 21:45 The mystery of deferred prompt evaluation Nik Gervae
1999-05-31  9:20 ` 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).