Ticket #8051: ticket-8051-multi-line-number-fix.v2.patch

File ticket-8051-multi-line-number-fix.v2.patch, 2.4 KB (added by hvr, 21 months ago)

improved patch for better handling :set +m-style continuations

  • ghc/InteractiveUI.hs

    From b7a74bae689ca7ccaf43da4b09bebbe883d1d0c4 Mon Sep 17 00:00:00 2001
    From: Herbert Valerio Riedel <[email protected]>
    Date: Thu, 11 Jul 2013 18:21:29 +0200
    Subject: Fix multi-line input line-numbers & interaction between `:{` and `:set +m`
    
    This fixes #8051
    ---
     ghc/InteractiveUI.hs | 15 +++++++++++++--
     1 file changed, 13 insertions(+), 2 deletions(-)
    
    diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
    index fd034ea..5b86f36 100644
    a b runOneCommand eh gCmd = do 
    733733    collectCommand q c = q >>= 
    734734      maybe (liftIO (ioError collectError)) 
    735735            (\l->if removeSpaces l == ":}" 
    736                  then return (Just $ removeSpaces c) 
     736                 then return (Just c) 
    737737                 else collectCommand q (c ++ "\n" ++ map normSpace l)) 
    738738      where normSpace '\r' = ' ' 
    739739            normSpace   x  = x 
    runOneCommand eh gCmd = do 
    752752 
    753753    -- haskell 
    754754    doCommand stmt = do 
     755      -- if 'stmt' was entered via ':{' it will contain '\n's 
     756      let stmt_nl_cnt = length [ () | '\n' <- stmt ] 
    755757      ml <- lift $ isOptionSet Multiline 
    756       if ml 
     758      if ml && stmt_nl_cnt == 0 -- don't trigger automatic multi-line mode for ':{'-multiline input 
    757759        then do 
     760          fst_line_num <- lift (line_number <$> getGHCiState) 
    758761          mb_stmt <- checkInputForLayout stmt gCmd 
    759762          case mb_stmt of 
    760763            Nothing      -> return $ Just True 
    761764            Just ml_stmt -> do 
     765              -- temporarily compensate line-number for multi-line input 
     766              saved_line_num <- lift (line_number <$> getGHCiState) 
     767              lift $ getGHCiState >>= \st' -> setGHCiState st'{ line_number = fst_line_num } 
    762768              result <- timeIt $ lift $ runStmt ml_stmt GHC.RunToCompletion 
     769              lift $ getGHCiState >>= \st' -> setGHCiState st'{ line_number = saved_line_num } 
    763770              return $ Just result 
    764771        else do 
     772          let line_ofs = if stmt_nl_cnt > 0 then stmt_nl_cnt + 1 else 0 
     773          -- temporarily compensate line-number for multi-line input 
     774          lift $ getGHCiState >>= \st' -> setGHCiState st'{ line_number = line_number st' - line_ofs } 
    765775          result <- timeIt $ lift $ runStmt stmt GHC.RunToCompletion 
     776          lift $ getGHCiState >>= \st' -> setGHCiState st'{ line_number = line_number st' + line_ofs } 
    766777          return $ Just result 
    767778 
    768779-- #4316