Commit 11814a8e authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺

GHCi: Implement `%l` prompt substitution for line-number

This commit also updates the GHC user guide section
regarding the `set prompt` command and closes #8047.
Signed-off-by: Herbert Valerio Riedel's avatarHerbert Valerio Riedel <>
parent c08bf882
......@@ -2787,8 +2787,10 @@ bar
<para>Sets the string to be used as the prompt in GHCi.
Inside <replaceable>prompt</replaceable>, the sequence
<literal>%s</literal> is replaced by the names of the
modules currently in scope, and <literal>%%</literal> is
replaced by <literal>%</literal>. If <replaceable>prompt</replaceable>
modules currently in scope, <literal>%l</literal> is replaced
by the line number (as referenced in compiler messages) of the
current prompt, and <literal>%%</literal> is replaced by
<literal>%</literal>. If <replaceable>prompt</replaceable>
starts with &quot; then it is parsed as a Haskell String;
otherwise it is treated as a literal string.</para>
......@@ -609,6 +609,7 @@ fileLoop hdl = do
mkPrompt :: GHCi String
mkPrompt = do
st <- getGHCiState
imports <- GHC.getContext
resumes <- GHC.getResumeContext
......@@ -639,12 +640,12 @@ mkPrompt = do
deflt_prompt = dots <> context_bit <> modules_bit
f ('%':'l':xs) = ppr (1 + line_number st) <> f xs
f ('%':'s':xs) = deflt_prompt <> f xs
f ('%':'%':xs) = char '%' <> f xs
f (x:xs) = char x <> f xs
f [] = empty
st <- getGHCiState
dflags <- getDynFlags
return (showSDoc dflags (f (prompt st)))
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment