@@ -32,6 +32,7 @@ import Control.Lens
3232import qualified Control.Lens as Lens
3333import Control.Monad
3434 ( void
35+ , (<=<)
3536 )
3637import Control.Monad.Extra
3738 ( ifM
@@ -935,16 +936,19 @@ clear
935936 => Maybe ReplNode
936937 -- ^ 'Nothing' for current node, or @Just n@ for a specific node identifier
937938 -> m ()
938- clear =
939- \ case
939+ clear maybeNode = do
940+ graph <- getInnerGraph
941+ case maybeNode of
940942 Nothing -> Lens. use (field @ " node" ) >>= clear . Just
941943 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
944949 where
945- clear0 :: ReplNode -> m ()
946- clear0 rnode = do
947- graph <- getInnerGraph
950+ clear0 :: ReplNode -> InnerGraph Axiom -> m ()
951+ clear0 rnode graph = do
948952 let node = unReplNode rnode
949953 let
950954 nodesToBeRemoved = collect (next graph) node
@@ -962,6 +966,11 @@ clear =
962966 prevNode :: InnerGraph axiom -> Graph. Node -> Graph. Node
963967 prevNode graph = fromMaybe 0 . headMay . fmap fst . Graph. lpre graph
964968
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+
965974-- | Save this sessions' commands to the specified file.
966975saveSession
967976 :: forall m
0 commit comments