[commit: ghc] master: GHCi: Implement `%l` prompt substitution for line-number (11814a8)

git at git.haskell.org git at git.haskell.org
Sat Aug 10 22:31:03 CEST 2013


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/11814a8e2f1a5b1163cb1b00bfdc699436b40317/ghc

>---------------------------------------------------------------

commit 11814a8e2f1a5b1163cb1b00bfdc699436b40317
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Wed Jul 10 10:01:31 2013 +0200

    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 <hvr at gnu.org>


>---------------------------------------------------------------

11814a8e2f1a5b1163cb1b00bfdc699436b40317
 docs/users_guide/ghci.xml |    6 ++++--
 ghc/InteractiveUI.hs      |    3 ++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/docs/users_guide/ghci.xml b/docs/users_guide/ghci.xml
index 9d7fa6c..df483e8 100644
--- a/docs/users_guide/ghci.xml
+++ b/docs/users_guide/ghci.xml
@@ -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>
         </listitem>
diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
index dbc0c05..fd034ea 100644
--- a/ghc/InteractiveUI.hs
+++ b/ghc/InteractiveUI.hs
@@ -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)))
 





More information about the ghc-commits mailing list