@@ -32,6 +32,7 @@ import Control.Lens
32
32
import qualified Control.Lens as Lens
33
33
import Control.Monad
34
34
( void
35
+ , (<=<)
35
36
)
36
37
import Control.Monad.Extra
37
38
( ifM
@@ -935,16 +936,19 @@ clear
935
936
=> Maybe ReplNode
936
937
-- ^ 'Nothing' for current node, or @Just n@ for a specific node identifier
937
938
-> m ()
938
- clear =
939
- \ case
939
+ clear maybeNode = do
940
+ graph <- getInnerGraph
941
+ case maybeNode of
940
942
Nothing -> Lens. use (field @ " node" ) >>= clear . Just
941
943
Just node
942
- | unReplNode node == 0 -> putStrLn' " Cannot clear initial node (0)."
943
- | otherwise -> clear0 node
944
+ | unReplNode node == 0 ->
945
+ putStrLn' " Cannot clear initial node (0)."
946
+ | isDirectDescendentOfBranching node graph ->
947
+ putStrLn' " Cannot clear a direct descendant of a branching node."
948
+ | otherwise -> clear0 node graph
944
949
where
945
- clear0 :: ReplNode -> m ()
946
- clear0 rnode = do
947
- graph <- getInnerGraph
950
+ clear0 :: ReplNode -> InnerGraph Axiom -> m ()
951
+ clear0 rnode graph = do
948
952
let node = unReplNode rnode
949
953
let
950
954
nodesToBeRemoved = collect (next graph) node
@@ -962,6 +966,11 @@ clear =
962
966
prevNode :: InnerGraph axiom -> Graph. Node -> Graph. Node
963
967
prevNode graph = fromMaybe 0 . headMay . fmap fst . Graph. lpre graph
964
968
969
+ isDirectDescendentOfBranching :: ReplNode -> InnerGraph axiom -> Bool
970
+ isDirectDescendentOfBranching (ReplNode node) graph =
971
+ let childrenOfParent = (Graph. suc graph <=< Graph. pre graph) node
972
+ in length childrenOfParent /= 1
973
+
965
974
-- | Save this sessions' commands to the specified file.
966
975
saveSession
967
976
:: forall m
0 commit comments