@@ -271,6 +271,21 @@ undoElab prf env st [] = ifail "Nothing to undo"
271271undoElab prf env st (h:hs) = do (prf', env', st') <- undoStep prf env st h
272272 return (prf', env', st', hs)
273273
274+runWithInterrupt
275+ :: ElabState EState
276+ -> Idris a -- ^ run with SIGINT handler
277+ -> Idris b -- ^ run if mTry finished
278+ -> Idris b -- ^ run if mTry was interrupted
279+ -> Idris b
280+runWithInterrupt elabState mTry mSuccess mFailure = do
281+ ist <- getIState
282+ case idris_outputmode ist of
283+ RawOutput _ -> do
284+ success <- runInputT (proverSettings elabState) $
285+ handleInterrupt (return False) $
286+ withInterrupt (lift mTry >> return True)
287+ if success then mSuccess else mFailure
288+ IdeMode _ _ -> mTry >> mSuccess
274289
275290elabloop :: Name -> Bool -> String -> [String] -> ElabState EState -> [ElabShellHistory] -> Maybe History -> [(Name, Type, Term)] -> Idris (Term, [String])
276291elabloop fn d prompt prf e prev h env
@@ -283,7 +298,7 @@ elabloop fn d prompt prf e prev h env
283298 do case h of
284299 Just history -> putHistory history
285300 Nothing -> return ()
286− l <- getInputLine (prompt ++ "> ")
301+ l <- handleInterrupt (return $ Just "") $ withInterrupt $ getInputLine (prompt ++ "> ")
287302 h' <- getHistory
288303 return (l, Just h')
289304 IdeMode _ handle ->
@@ -375,8 +390,9 @@ elabloop fn d prompt prf e prev h env
375390 Right ok ->
376391 if done then do (tm, _) <- elabStep st get_term
377392 return (tm, prf')
378− else do ok
379− elabloop fn d prompt prf' st prev' h' env'
393+ else runWithInterrupt e ok
394+ (elabloop fn d prompt prf' st prev' h' env')
395+ (elabloop fn d prompt prf e prev h' env)
380396
381397 where
382398 -- A bit of a hack: wrap the value up in a let binding, which will
@@ -401,7 +417,7 @@ ploop fn d prompt prf e h
401417 do case h of
402418 Just history -> putHistory history
403419 Nothing -> return ()
404− l <- getInputLine (prompt ++ "> ")
420+ l <- handleInterrupt (return $ Just "") $ withInterrupt $ getInputLine (prompt ++ "> ")
405421 h' <- getHistory
406422 return (l, Just h')
407423 IdeMode _ handle ->
@@ -445,8 +461,9 @@ ploop fn d prompt prf e h
445461 Right ok ->
446462 if done then do (tm, _) <- elabStep st get_term
447463 return (tm, prf')
448− else do ok
449− ploop fn d prompt prf' st h'
464+ else runWithInterrupt e ok
465+ (ploop fn d prompt prf' st h')
466+ (ploop fn d prompt prf e h')
450467
451468
452469envCtxt env ctxt = foldl (\c (n, b) -> addTyDecl n Bound (binderTy b) c) ctxt env