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

File ticket-8051-multi-line-number-fix.patch, 2.2 KB (added by hvr, 9 months ago)
  • ghc/InteractiveUI.hs

    commit af8a8f08f6caecf1b6044b2e1e9fe64364ee3d1c
    Author: Herbert Valerio Riedel <hvr@gnu.org>
    Date:   Thu Jul 11 18:21:29 2013 +0200
    
        Fix multi-line input line-numbers & interaction between `:{` and `:set +m`
        
        This fixes #8051
    
    diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
    index 36335cd..4bac5ad 100644
    a b runOneCommand eh gCmd = do 
    732732    collectCommand q c = q >>= 
    733733      maybe (liftIO (ioError collectError)) 
    734734            (\l->if removeSpaces l == ":}" 
    735                  then return (Just $ removeSpaces c) 
     735                 then return (Just c) 
    736736                 else collectCommand q (c ++ "\n" ++ map normSpace l)) 
    737737      where normSpace '\r' = ' ' 
    738738            normSpace   x  = x 
    runOneCommand eh gCmd = do 
    751751 
    752752    -- haskell 
    753753    doCommand stmt = do 
     754      -- if 'stmt' was entered via ':{' it will contain '\n's 
     755      let stmt_nl_cnt = length [ () | '\n' <- stmt ] 
    754756      ml <- lift $ isOptionSet Multiline 
    755       if ml 
     757      if ml && stmt_nl_cnt == 0 -- don't trigger automatic multi-line mode for ':{'-multiline input 
    756758        then do 
    757759          mb_stmt <- checkInputForLayout stmt gCmd 
    758760          case mb_stmt of 
    759761            Nothing      -> return $ Just True 
    760762            Just ml_stmt -> do 
     763              let line_ofs = length [ () | '\n' <- ml_stmt ] 
     764              -- temporarily compensate line-number for multi-line input 
     765              lift $ getGHCiState >>= \st' -> setGHCiState st'{ line_number = line_number st' - line_ofs } 
    761766              result <- timeIt $ lift $ runStmt ml_stmt GHC.RunToCompletion 
     767              lift $ getGHCiState >>= \st' -> setGHCiState st'{ line_number = line_number st' + line_ofs } 
    762768              return $ Just result 
    763769        else do 
     770          let line_ofs = if stmt_nl_cnt > 0 then stmt_nl_cnt + 1 else 0 
     771          -- temporarily compensate line-number for multi-line input 
     772          lift $ getGHCiState >>= \st' -> setGHCiState st'{ line_number = line_number st' - line_ofs } 
    764773          result <- timeIt $ lift $ runStmt stmt GHC.RunToCompletion 
     774          lift $ getGHCiState >>= \st' -> setGHCiState st'{ line_number = line_number st' + line_ofs } 
    765775          return $ Just result 
    766776 
    767777-- #4316