Implement IndentPolicyMultiple
parent
004dee73e0
commit
9ab17cc899
|
@ -436,7 +436,7 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs mWhereDocs ha
|
||||||
-- multiple clauses added in-paragraph, each in a single line
|
-- multiple clauses added in-paragraph, each in a single line
|
||||||
-- example: foo | bar = baz
|
-- example: foo | bar = baz
|
||||||
-- | lll = asd
|
-- | lll = asd
|
||||||
addAlternativeCond (indentPolicy /= IndentPolicyLeft)
|
addAlternativeCond (indentPolicy == IndentPolicyFree)
|
||||||
$ docLines
|
$ docLines
|
||||||
$ [ docSeq
|
$ [ docSeq
|
||||||
[ appSep $ docForceSingleline $ return patDoc
|
[ appSep $ docForceSingleline $ return patDoc
|
||||||
|
|
|
@ -422,7 +422,8 @@ layoutExpr lexpr@(L _ expr) = do
|
||||||
let maySpecialIndent =
|
let maySpecialIndent =
|
||||||
case indentPolicy of
|
case indentPolicy of
|
||||||
IndentPolicyLeft -> BrIndentRegular
|
IndentPolicyLeft -> BrIndentRegular
|
||||||
_ -> BrIndentSpecial 3
|
IndentPolicyMultiple -> BrIndentRegular
|
||||||
|
IndentPolicyFree -> BrIndentSpecial 3
|
||||||
-- TODO: some of the alternatives (especially last and last-but-one)
|
-- TODO: some of the alternatives (especially last and last-but-one)
|
||||||
-- overlap.
|
-- overlap.
|
||||||
runFilteredAlternative $ do
|
runFilteredAlternative $ do
|
||||||
|
@ -541,7 +542,10 @@ layoutExpr lexpr@(L _ expr) = do
|
||||||
let
|
let
|
||||||
ifIndentLeftElse :: a -> a -> a
|
ifIndentLeftElse :: a -> a -> a
|
||||||
ifIndentLeftElse x y =
|
ifIndentLeftElse x y =
|
||||||
if indentPolicy == IndentPolicyLeft then x else y
|
case indentPolicy of
|
||||||
|
IndentPolicyLeft -> x
|
||||||
|
IndentPolicyMultiple -> x
|
||||||
|
IndentPolicyFree -> y
|
||||||
-- this `docSetBaseAndIndent` might seem out of place (especially the
|
-- this `docSetBaseAndIndent` might seem out of place (especially the
|
||||||
-- Indent part; setBase is necessary due to the use of docLines below),
|
-- Indent part; setBase is necessary due to the use of docLines below),
|
||||||
-- but is here due to ghc-exactprint's DP handling of "let" in
|
-- but is here due to ghc-exactprint's DP handling of "let" in
|
||||||
|
@ -596,18 +600,21 @@ layoutExpr lexpr@(L _ expr) = do
|
||||||
-- c = d
|
-- c = d
|
||||||
-- in
|
-- in
|
||||||
-- fooooooooooooooooooo
|
-- fooooooooooooooooooo
|
||||||
|
let noHangingBinds =
|
||||||
|
[ docAddBaseY BrIndentRegular
|
||||||
|
$ docPar
|
||||||
|
(docLit $ Text.pack "let")
|
||||||
|
(docSetBaseAndIndent $ docLines bindDocs)
|
||||||
|
, docSeq
|
||||||
|
[ docLit $ Text.pack "in "
|
||||||
|
, docAddBaseY BrIndentRegular expDoc1
|
||||||
|
]
|
||||||
|
]
|
||||||
addAlternativeCond (indentPolicy == IndentPolicyLeft)
|
addAlternativeCond (indentPolicy == IndentPolicyLeft)
|
||||||
$ docLines
|
$ docLines noHangingBinds
|
||||||
[ docAddBaseY BrIndentRegular
|
addAlternativeCond (indentPolicy == IndentPolicyMultiple)
|
||||||
$ docPar
|
$ docLines noHangingBinds
|
||||||
(docLit $ Text.pack "let")
|
addAlternativeCond (indentPolicy == IndentPolicyFree)
|
||||||
(docSetBaseAndIndent $ docLines bindDocs)
|
|
||||||
, docSeq
|
|
||||||
[ docLit $ Text.pack "in "
|
|
||||||
, docAddBaseY BrIndentRegular expDoc1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
addAlternativeCond (indentPolicy /= IndentPolicyLeft)
|
|
||||||
$ docLines
|
$ docLines
|
||||||
[ docSeq
|
[ docSeq
|
||||||
[ appSep $ docLit $ Text.pack "let"
|
[ appSep $ docLit $ Text.pack "let"
|
||||||
|
@ -877,7 +884,7 @@ layoutExpr lexpr@(L _ expr) = do
|
||||||
-- container { fieldA = blub
|
-- container { fieldA = blub
|
||||||
-- , fieldB = blub
|
-- , fieldB = blub
|
||||||
-- }
|
-- }
|
||||||
addAlternativeCond (indentPolicy /= IndentPolicyLeft)
|
addAlternativeCond (indentPolicy == IndentPolicyFree)
|
||||||
$ docSeq
|
$ docSeq
|
||||||
[ docNodeAnnKW lexpr Nothing $ appSep rExprDoc
|
[ docNodeAnnKW lexpr Nothing $ appSep rExprDoc
|
||||||
, docSetBaseY $ docLines $ let
|
, docSetBaseY $ docLines $ let
|
||||||
|
@ -918,9 +925,10 @@ layoutExpr lexpr@(L _ expr) = do
|
||||||
$ docPar
|
$ docPar
|
||||||
(docNodeAnnKW lexpr Nothing rExprDoc)
|
(docNodeAnnKW lexpr Nothing rExprDoc)
|
||||||
(docNonBottomSpacing $ docLines $ let
|
(docNonBottomSpacing $ docLines $ let
|
||||||
expressionWrapper = if indentPolicy == IndentPolicyLeft
|
expressionWrapper = case indentPolicy of
|
||||||
then docForceParSpacing
|
IndentPolicyLeft -> docForceParSpacing
|
||||||
else docSetBaseY
|
IndentPolicyMultiple -> docForceParSpacing
|
||||||
|
IndentPolicyFree -> docSetBaseY
|
||||||
line1 = docCols ColRecUpdate
|
line1 = docCols ColRecUpdate
|
||||||
[ appSep $ docLit $ Text.pack "{"
|
[ appSep $ docLit $ Text.pack "{"
|
||||||
, docWrapNodePrior rF1f $ appSep $ docLit rF1n
|
, docWrapNodePrior rF1f $ appSep $ docLit rF1n
|
||||||
|
|
|
@ -48,7 +48,7 @@ layoutImport limportD@(L _ importD) = docWrapNode limportD $ case importD of
|
||||||
importAsCol <- mAsk <&> _conf_layout .> _lconfig_importAsColumn .> confUnpack
|
importAsCol <- mAsk <&> _conf_layout .> _lconfig_importAsColumn .> confUnpack
|
||||||
indentPolicy <- mAsk <&> _conf_layout .> _lconfig_indentPolicy .> confUnpack
|
indentPolicy <- mAsk <&> _conf_layout .> _lconfig_indentPolicy .> confUnpack
|
||||||
let
|
let
|
||||||
compact = indentPolicy == IndentPolicyLeft
|
compact = indentPolicy /= IndentPolicyFree
|
||||||
modNameT = Text.pack $ moduleNameString modName
|
modNameT = Text.pack $ moduleNameString modName
|
||||||
pkgNameT = Text.pack . prepPkg . sl_st <$> pkg
|
pkgNameT = Text.pack . prepPkg . sl_st <$> pkg
|
||||||
masT = Text.pack . moduleNameString . prepModName <$> mas
|
masT = Text.pack . moduleNameString . prepModName <$> mas
|
||||||
|
|
|
@ -58,11 +58,11 @@ layoutStmt lstmt@(L _ stmt) = do
|
||||||
docCols
|
docCols
|
||||||
ColDoLet
|
ColDoLet
|
||||||
[ appSep $ docLit $ Text.pack "let"
|
[ appSep $ docLit $ Text.pack "let"
|
||||||
, ( if indentPolicy == IndentPolicyLeft
|
, let f = case indentPolicy of
|
||||||
then docForceSingleline
|
IndentPolicyFree -> docSetBaseAndIndent
|
||||||
else docSetBaseAndIndent
|
IndentPolicyLeft -> docForceSingleline
|
||||||
)
|
IndentPolicyMultiple -> docForceSingleline
|
||||||
$ return bindDoc
|
in f $ return bindDoc
|
||||||
]
|
]
|
||||||
, -- let
|
, -- let
|
||||||
-- bind = expr
|
-- bind = expr
|
||||||
|
@ -74,8 +74,8 @@ layoutStmt lstmt@(L _ stmt) = do
|
||||||
-- let aaa = expra
|
-- let aaa = expra
|
||||||
-- bbb = exprb
|
-- bbb = exprb
|
||||||
-- ccc = exprc
|
-- ccc = exprc
|
||||||
addAlternativeCond (indentPolicy /= IndentPolicyLeft)
|
-- TODO: Allow this for IndentPolicyMultiple when indentAmount = 4
|
||||||
$ docSeq
|
addAlternativeCond (indentPolicy == IndentPolicyFree) $ docSeq
|
||||||
[ appSep $ docLit $ Text.pack "let"
|
[ appSep $ docLit $ Text.pack "let"
|
||||||
, docSetBaseAndIndent $ docLines $ return <$> bindDocs
|
, docSetBaseAndIndent $ docLines $ return <$> bindDocs
|
||||||
]
|
]
|
||||||
|
@ -83,16 +83,14 @@ layoutStmt lstmt@(L _ stmt) = do
|
||||||
-- aaa = expra
|
-- aaa = expra
|
||||||
-- bbb = exprb
|
-- bbb = exprb
|
||||||
-- ccc = exprc
|
-- ccc = exprc
|
||||||
addAlternative $
|
addAlternative $ docAddBaseY BrIndentRegular $ docPar
|
||||||
docAddBaseY BrIndentRegular $ docPar
|
(docLit $ Text.pack "let")
|
||||||
(docLit $ Text.pack "let")
|
(docSetBaseAndIndent $ docLines $ return <$> bindDocs)
|
||||||
(docSetBaseAndIndent $ docLines $ return <$> bindDocs)
|
|
||||||
RecStmt stmts _ _ _ _ _ _ _ _ _ -> runFilteredAlternative $ do
|
RecStmt stmts _ _ _ _ _ _ _ _ _ -> runFilteredAlternative $ do
|
||||||
-- rec stmt1
|
-- rec stmt1
|
||||||
-- stmt2
|
-- stmt2
|
||||||
-- stmt3
|
-- stmt3
|
||||||
addAlternativeCond (indentPolicy /= IndentPolicyLeft)
|
addAlternativeCond (indentPolicy == IndentPolicyFree) $ docSeq
|
||||||
$ docSeq
|
|
||||||
[ docLit (Text.pack "rec")
|
[ docLit (Text.pack "rec")
|
||||||
, docSeparator
|
, docSeparator
|
||||||
, docSetBaseAndIndent $ docLines $ layoutStmt <$> stmts
|
, docSetBaseAndIndent $ docLines $ layoutStmt <$> stmts
|
||||||
|
@ -101,9 +99,9 @@ layoutStmt lstmt@(L _ stmt) = do
|
||||||
-- stmt1
|
-- stmt1
|
||||||
-- stmt2
|
-- stmt2
|
||||||
-- stmt3
|
-- stmt3
|
||||||
addAlternative
|
addAlternative $ docAddBaseY BrIndentRegular $ docPar
|
||||||
$ docAddBaseY BrIndentRegular
|
(docLit (Text.pack "rec"))
|
||||||
$ docPar (docLit (Text.pack "rec")) (docLines $ layoutStmt <$> stmts)
|
(docLines $ layoutStmt <$> stmts)
|
||||||
BodyStmt expr _ _ _ -> do
|
BodyStmt expr _ _ _ -> do
|
||||||
expDoc <- docSharedWrapper layoutExpr expr
|
expDoc <- docSharedWrapper layoutExpr expr
|
||||||
docAddBaseY BrIndentRegular $ expDoc
|
docAddBaseY BrIndentRegular $ expDoc
|
||||||
|
|
|
@ -142,17 +142,23 @@ transformAlts =
|
||||||
BDFAddBaseY indent bd -> do
|
BDFAddBaseY indent bd -> do
|
||||||
acp <- mGet
|
acp <- mGet
|
||||||
indAmount <- mAsk <&> _conf_layout .> _lconfig_indentAmount .> confUnpack
|
indAmount <- mAsk <&> _conf_layout .> _lconfig_indentAmount .> confUnpack
|
||||||
|
indPolicy <- mAsk <&> _conf_layout .> _lconfig_indentPolicy .> confUnpack
|
||||||
let indAdd = case indent of
|
let indAdd = case indent of
|
||||||
BrIndentNone -> 0
|
BrIndentNone -> 0
|
||||||
BrIndentRegular -> indAmount
|
BrIndentRegular -> indAmount
|
||||||
BrIndentSpecial i -> i
|
BrIndentSpecial i -> i
|
||||||
mSet $ acp { _acp_indentPrep = max (_acp_indentPrep acp) indAdd }
|
let indAdd' =
|
||||||
|
if indPolicy == IndentPolicyMultiple
|
||||||
|
then
|
||||||
|
max 0 (indAdd - ((_acp_indent acp + indAdd) `mod` indAmount))
|
||||||
|
else indAdd
|
||||||
|
mSet $ acp { _acp_indentPrep = max (_acp_indentPrep acp) indAdd' }
|
||||||
r <- rec bd
|
r <- rec bd
|
||||||
acp' <- mGet
|
acp' <- mGet
|
||||||
mSet $ acp' { _acp_indent = _acp_indent acp }
|
mSet $ acp' { _acp_indent = _acp_indent acp }
|
||||||
return $ case indent of
|
return $ case indent of
|
||||||
BrIndentNone -> r
|
BrIndentNone -> r
|
||||||
BrIndentRegular -> reWrap $ BDFAddBaseY (BrIndentSpecial indAdd) r
|
BrIndentRegular -> reWrap $ BDFAddBaseY (BrIndentSpecial indAdd') r
|
||||||
BrIndentSpecial i -> reWrap $ BDFAddBaseY (BrIndentSpecial i) r
|
BrIndentSpecial i -> reWrap $ BDFAddBaseY (BrIndentSpecial i) r
|
||||||
BDFBaseYPushCur bd -> do
|
BDFBaseYPushCur bd -> do
|
||||||
acp <- mGet
|
acp <- mGet
|
||||||
|
|
Loading…
Reference in New Issue