When an output line is too long in GHCI, it is broken:
> :i bar
bar :: Lens' (Foo a0) Int -- Defined at NewType_makeLenses.hs:7:1
> :i baz
baz :: Lens (Foo a0) (Foo a1) a0 a1
-- Defined at NewType_makeLenses.hs:7:1
Is there a way to set the maximal length of the lines?
There are three options that control pretty printing:
-dppr-debug Turn on debug printing (more verbose)
-dppr-user-length Set the depth for printing expressions in error msgs
-dppr-cols⟨N⟩ Set the width of debugging output. For example -dppr-cols200
You're looking for -dppr-cols
. Its default value is 100
. You can set it to any other value, either when you call GHCi or with :set
.
-dppr-cols
$ ghci NewType_makeLenses.hs
[1 of 1] Compiling Main ( NewType_makeLenses.hs, interpreted )
Ok, modules loaded: Main.
> :i bar
bar :: Lens' (Foo a0) Int -- Defined at NewType_makeLenses.hs:9:1
> :i baz
baz :: Lens (Foo a0) (Foo a1) a0 a1
-- Defined at NewType_makeLenses.hs:10:1
-dppr-cols140
$ ghci -dppr-cols140 NewType_makeLenses.hs
[1 of 1] Compiling Main ( NewType_makeLenses.hs, interpreted )
Ok, modules loaded: Main.
> :i bar
bar :: Lens' (Foo a0) Int -- Defined at NewType_makeLenses.hs:9:1
> :i baz
baz :: Lens (Foo a0) (Foo a1) a0 a1 -- Defined at NewType_makeLenses.hs:10:1
:set -dppr-cols140
$ ghci NewType_makeLenses.hs
[1 of 1] Compiling Main ( NewType_makeLenses.hs, interpreted )
Ok, modules loaded: Main.
> :set -dppr-cols140
> :i bar
bar :: Lens' (Foo a0) Int -- Defined at NewType_makeLenses.hs:9:1
> :i baz
baz :: Lens (Foo a0) (Foo a1) a0 a1 -- Defined at NewType_makeLenses.hs:10:1
I didn't look into the flags, instead, I looked into GHC's source code:
$ git clone --depth=1 https://github.com/ghc/ghc.git && cd ghc
Next, I look for a string that starts with "Defined
:
$ grep -C2 "\"Defined" -r . --exclude-dir=testsuite
./compiler/basicTypes/Name.hs-ppr_z_occ_name occ = ztext (zEncodeFS (occNameFS occ))
./compiler/basicTypes/Name.hs-
./compiler/basicTypes/Name.hs:-- Prints (if mod information is available) "Defined at <loc>" or
./compiler/basicTypes/Name.hs:-- "Defined in <mod>" information for a Name.
./compiler/basicTypes/Name.hs-pprDefinedAt :: Name -> SDoc
./compiler/basicTypes/Name.hs:pprDefinedAt name = text "Defined" <+> pprNameDefnLoc name
./compiler/basicTypes/Name.hs-
./compiler/basicTypes/Name.hs-pprNameDefnLoc :: Name -> SDoc
SDoc
seems interesting.
$ grep "data SDoc" -r . --exclude-dir=testsuite
./compiler/utils/Outputable.hs:data SDocContext = SDC
./compiler/utils/Outputable.hs-boot:data SDoc
Outputable.hs
includes printForUser
, which uses pprCol dflags
together with printDoc
from Pretty
. printDoc
is defined as
printDoc :: Mode -> Int -> Handle -> Doc -> IO ()
-- printDoc adds a newline to the end
printDoc mode cols hdl doc = printDoc_ mode cols hdl (doc $$ text "")
and pprCol
is defined in compiler/main/DynFlags.hs
, where it corresponds to -dppr-cols
. You can just grep
your way through GHC :).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With