@@ -22,7 +22,7 @@ import System.IO
2222import Control.Monad.Trans.State.Strict
2323import Control.Monad.Trans.Error
2424
25−import Data.List
25+import Data.List hiding (group)
2626import Data.Char
2727import qualified Data.Map as M
2828import qualified Data.Text as T
@@ -696,7 +696,6 @@ data PTactic' t = Intro [Name] | Intros | Focus Name
696696deriving instance Binary PTactic'
697697deriving instance NFData PTactic'
698698!-}
699−
700699instance Sized a => Sized (PTactic' a) where
701700 size (Intro nms) = 1 + size nms
702701 size Intros = 1
@@ -1015,17 +1014,20 @@ piBindp p ((n, ty):ns) t = PPi p n ty (piBindp p ns t)
10151014
10161015-- Pretty-printing declarations and terms
10171016
1017+-- These "show" instances render to an absurdly wide screen because inserted line breaks
1018+-- could interfere with interactive editing, which calls "show".
1019+
10181020instance Show PTerm where
1019− showsPrec _ tm = (displayS . renderCompact . prettyImp False) tm
1021+ showsPrec _ tm = (displayS . renderPretty 1.0 10000000 . prettyImp False) tm
10201022
10211023instance Show PDecl where
1022− showsPrec _ d = (displayS . renderCompact . showDeclImp False) d
1024+ showsPrec _ d = (displayS . renderPretty 1.0 10000000 . showDeclImp False) d
10231025
10241026instance Show PClause where
1025− showsPrec _ c = (displayS . renderCompact . showCImp True) c
1027+ showsPrec _ c = (displayS . renderPretty 1.0 10000000 . showCImp True) c
10261028
10271029instance Show PData where
1028− showsPrec _ d = (displayS . renderCompact . showDImp False) d
1030+ showsPrec _ d = (displayS . renderPretty 1.0 10000000 . showDImp False) d
10291031
10301032instance Pretty PTerm OutputAnnotation where
10311033 pretty = prettyImp False
@@ -1065,9 +1067,6 @@ pprintPTerm impl bnd = prettySe 10 bnd
10651067 where
10661068 prettySe :: Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
10671069 prettySe p bnd (PQuote r) =
1068− if size r > breakingSize then
1069− text "![" <> line <> pretty r <> text "]"
1070− else
10711070 text "![" <> pretty r <> text "]"
10721071 prettySe p bnd (PPatvar fc n) = pretty n
10731072 prettySe p bnd e
@@ -1075,35 +1074,23 @@ pprintPTerm impl bnd = prettySe 10 bnd
10751074 | Just n <- snat p e = annotate AnnConstData (text (show n))
10761075 prettySe p bnd (PRef fc n) = prettyName impl bnd n
10771076 prettySe p bnd (PLam n ty sc) =
1078− bracket p 2 $
1079− if size sc > breakingSize then
1080− text "\\" <> bindingOf n False <+> text "=>" <> line <> prettySe 10 ((n, False):bnd) sc
1081− else
1082− text "\\" <> bindingOf n False <+> text "=>" <+> prettySe 10 ((n, False):bnd) sc
1077+ bracket p 2 . group . hang 2 $
1078+ text "\\" <> bindingOf n False <+> text "=>" <$>
1079+ prettySe 10 ((n, False):bnd) sc
10831080 prettySe p bnd (PLet n ty v sc) =
10841081 bracket p 2 $
1085− if size sc > breakingSize then
1086− text "let" <+> bindingOf n False <+> text "=" <+> prettySe 10 bnd v <+> text "in" <>
1087− nest nestingSize (prettySe 10 ((n, False):bnd) sc)
1088− else
1089− text "let" <+> bindingOf n False <+> text "=" <+> prettySe 10 bnd v <+> text "in" <+>
1090− prettySe 10 ((n, False):bnd) sc
1082+ text "let" <+> bindingOf n False <+> text "=" </>
1083+ prettySe 10 bnd v <+> text "in" </>
1084+ prettySe 10 ((n, False):bnd) sc
10911085 prettySe p bnd (PPi (Exp l s _ _) n ty sc)
10921086 | n `elem` allNamesIn sc || impl =
10931087 let open = if Lazy `elem` l then text "|" <> lparen else lparen in
1094− bracket p 2 $
1095− if size sc > breakingSize then
1096− enclose open rparen (bindingOf n False <+> colon <+> prettySe 10 bnd ty) <+>
1097− st <> text "->" <> line <> prettySe 10 ((n, False):bnd) sc
1098− else
1099− enclose open rparen (bindingOf n False <+> colon <+> prettySe 10 bnd ty) <+>
1100− st <> text "->" <+> prettySe 10 ((n, False):bnd) sc
1088+ bracket p 2 . group $
1089+ enclose open rparen (group . align $ bindingOf n False <+> colon <+> prettySe 10 bnd ty) <+>
1090+ st <> text "->" <$> prettySe 10 ((n, False):bnd) sc
11011091 | otherwise =
1102− bracket p 2 $
1103− if size sc > breakingSize then
1104− prettySe 0 bnd ty <+> st <> text "->" <> line <> prettySe 10 ((n, False):bnd) sc
1105− else
1106− prettySe 0 bnd ty <+> st <> text "->" <+> prettySe 10 ((n, False):bnd) sc
1092+ bracket p 2 . group $
1093+ group (prettySe 0 bnd ty <+> st) <> text "->" <$> group (prettySe 10 ((n, False):bnd) sc)
11071094 where
11081095 st =
11091096 case s of
@@ -1113,12 +1100,8 @@ pprintPTerm impl bnd = prettySe 10 bnd
11131100 | impl =
11141101 let open = if Lazy `elem` l then text "|" <> lbrace else lbrace in
11151102 bracket p 2 $
1116− if size sc > breakingSize then
1117− open <> bindingOf n True <+> colon <+> prettySe 10 bnd ty <> rbrace <+>
1118− st <> text "->" <+> prettySe 10 ((n, True):bnd) sc
1119− else
1120− open <> bindingOf n True <+> colon <+> prettySe 10 bnd ty <> rbrace <+>
1121− st <> text "->" <+> prettySe 10 ((n, True):bnd) sc
1103+ open <> bindingOf n True <+> colon <+> prettySe 10 bnd ty <> rbrace <+>
1104+ st <> text "->" </> prettySe 10 ((n, True):bnd) sc
11221105 | otherwise = prettySe 10 ((n, True):bnd) sc
11231106 where
11241107 st =
@@ -1127,18 +1110,11 @@ pprintPTerm impl bnd = prettySe 10 bnd
11271110 _ -> empty
11281111 prettySe p bnd (PPi (Constraint _ _ _) n ty sc) =
11291112 bracket p 2 $
1130− if size sc > breakingSize then
1131− prettySe 10 bnd ty <+> text "=>" <+> prettySe 10 ((n, True):bnd) sc
1132− else
1133− prettySe 10 bnd ty <+> text "=>" <> line <> prettySe 10 ((n, True):bnd) sc
1113+ prettySe 10 bnd ty <+> text "=>" </> prettySe 10 ((n, True):bnd) sc
11341114 prettySe p bnd (PPi (TacImp _ _ s _) n ty sc) =
11351115 bracket p 2 $
1136− if size sc > breakingSize then
1137− lbrace <> text "tacimp" <+> bindingOf n True <+> colon <+> prettySe 10 bnd ty <>
1138− rbrace <+> text "->" <> line <> prettySe 10 ((n, True):bnd) sc
1139− else
1140− lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 bnd ty <>
1141− rbrace <+> text "->" <+> prettySe 10 ((n, True):bnd) sc
1116+ lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 bnd ty <>
1117+ rbrace <+> text "->" </> prettySe 10 ((n, True):bnd) sc
11421118 prettySe p bnd (PApp _ (PRef _ f) [])
11431119 | not impl = prettyName impl bnd f
11441120 prettySe p bnd (PAppBind _ (PRef _ f) [])
@@ -1148,11 +1124,8 @@ pprintPTerm impl bnd = prettySe 10 bnd
11481124 , not (tnull nm) &&
11491125 length (getExps args) == 2 && (not impl) && (not $ isAlpha (thead nm)) =
11501126 let [l, r] = getExps args in
1151− bracket p 1 $
1152− if size r > breakingSize then
1153− prettySe 1 bnd l <+> prettyName impl bnd op <> line <> prettySe 0 bnd r
1154− else
1155− prettySe 1 bnd l <+> prettyName impl bnd op <+> prettySe 0 bnd r
1127+ bracket p 1 . align . group $
1128+ (prettySe 1 bnd l <+> prettyName impl bnd op) <$> group (prettySe 0 bnd r)
11561129 prettySe p bnd (PApp _ hd@(PRef fc f) [tm])
11571130 | PConstant (Idris.Core.TT.Str str) <- getTm tm,
11581131 f == sUN "Symbol_" = char '\'' <> prettySe 10 bnd (PRef fc (sUN str))
@@ -1160,10 +1133,14 @@ pprintPTerm impl bnd = prettySe 10 bnd
11601133 let args = getExps as
11611134 fp = prettySe 1 bnd f
11621135 in
1163− bracket p 1 $
1164− hsep (if impl
1165− then fp : map (prettyArgS bnd) as
1166− else fp : map (prettyArgSe bnd) args)
1136+ bracket p 1 . group $
1137+ if impl
1138+ then if null as
1139+ then fp
1140+ else fp <+> align (vsep (map (prettyArgS bnd) as))
1141+ else if null args
1142+ then fp
1143+ else fp <+> align (vsep (map (prettyArgSe bnd) args))
11671144 prettySe p bnd (PCase _ scr opts) =
11681145 text "case" <+> prettySe 10 bnd scr <+> text "of" <> prettyBody
11691146 where
@@ -1176,32 +1153,18 @@ pprintPTerm impl bnd = prettySe 10 bnd
11761153 prettySe p bnd (PTrue _) = annotate (AnnName unitTy Nothing Nothing) $ text "()"
11771154 prettySe p bnd (PFalse _) = annotate (AnnName falseTy Nothing Nothing) $ text "_|_"
11781155 prettySe p bnd (PEq _ l r) =
1179− bracket p 2 $
1180− if size r > breakingSize then
1181− prettySe 10 bnd l <+> eq <$> nest nestingSize (prettySe 10 bnd r)
1182− else
1183− prettySe 10 bnd l <+> eq <+> prettySe 10 bnd r
1156+ bracket p 2 . align . group $
1157+ prettySe 10 bnd l <+> eq <$> group (prettySe 10 bnd r)
11841158 where eq = annotate (AnnName eqTy Nothing Nothing) (text "=")
11851159 prettySe p bnd (PRewrite _ l r _) =
11861160 bracket p 2 $
1187− if size r > breakingSize then
1188− text "rewrite" <+> prettySe 10 bnd l <+> text "in" <> nest nestingSize (prettySe 10 bnd r)
1189− else
1190− text "rewrite" <+> prettySe 10 bnd l <+> text "in" <+> prettySe 10 bnd r
1161+ text "rewrite" <+> prettySe 10 bnd l <+> text "in" <+> prettySe 10 bnd r
11911162 prettySe p bnd (PTyped l r) =
11921163 lparen <> prettySe 10 bnd l <+> colon <+> prettySe 10 bnd r <> rparen
11931164 prettySe p bnd (PPair _ l r) =
1194− if size r > breakingSize then
1195− lparen <> prettySe 10 bnd l <> text "," <>
1196− line <> prettySe 10 bnd r <> rparen
1197− else
1198− lparen <> prettySe 10 bnd l <> text "," <+> prettySe 10 bnd r <> rparen
1165+ lparen <> prettySe 10 bnd l <> text "," <+> prettySe 10 bnd r <> rparen
11991166 prettySe p bnd (PDPair _ l t r) =
1200− if size r > breakingSize then
1201− lparen <> prettySe 10 bnd l <+> text "**" <>
1202− line <> prettySe 10 bnd r <> rparen
1203− else
1204− lparen <> prettySe 10 bnd l <+> text "**" <+> prettySe 10 bnd r <> rparen
1167+ lparen <> prettySe 10 bnd l <+> text "**" <+> prettySe 10 bnd r <> rparen
12051168 prettySe p bnd (PAlternative a as) =
12061169 lparen <> text "|" <> prettyAs <> text "|" <> rparen
12071170 where