@@ -18,6 +18,7 @@ import Control.Monad.Trans.Except (ExceptT (ExceptT), runExceptT)
1818import System.Console.Haskeline.MonadException
1919 (MonadException (controlIO), RunIO (RunIO))
2020import System.IO (stdout, Handle, hPutStrLn)
21+import System.FilePath (replaceExtension)
2122
2223import Prelude hiding ((<$>))
2324
@@ -198,7 +199,9 @@ sendHighlighting :: [(FC, OutputAnnotation)] -> Idris ()
198199sendHighlighting highlights =
199200 do ist <- getIState
200201 case idris_outputmode ist of
201− RawOutput _ -> return ()
202+ RawOutput _ -> updateIState $
203+ \ist -> ist { idris_highlightedRegions =
204+ highlights ++ idris_highlightedRegions ist }
202205 IdeMode n h ->
203206 let fancier = [ toSExp (fc, fancifyAnnots ist False annot)
204207 | (fc, annot) <- highlights, fullFC fc
@@ -213,6 +216,20 @@ sendHighlighting highlights =
213216 where fullFC (FC _ _ _) = True
214217 fullFC _ = False
215218
219+-- | Write the highlighting information to a file, for use in external tools
220+-- or in editors that don't support the IDE protocol
221+writeHighlights :: FilePath -> Idris ()
222+writeHighlights f =
223+ do ist <- getIState
224+ let hs = reverse $ idris_highlightedRegions ist
225+ let hfile = replaceExtension f "idh"
226+ let annots = toSExp [ (fc, fancifyAnnots ist False annot)
227+ | (fc@(FC _ _ _), annot) <- hs
228+ ]
229+ runIO $ writeFile hfile $ sExpToString annots
230+
231+clearHighlights :: Idris ()
232+clearHighlights = updateIState $ \ist -> ist { idris_highlightedRegions = [] }
216233
217234renderExternal :: OutputFmt -> Int -> Doc OutputAnnotation -> Idris String
218235renderExternal fmt width doc