{-# OPTIONS_GHC -Wunused-imports #-}

-- | Common syntax highlighting functions for Emacs and JSON

module Agda.Utils.IO.TempFile
  ( writeToTempFile
  ) where

import qualified Control.Exception as E
import qualified System.Directory as D
import qualified System.IO as IO

-- | Creates a temporary file, writes some stuff, and returns the filepath
writeToTempFile :: String -> IO FilePath
writeToTempFile :: String -> IO String
writeToTempFile String
content = do
  dir      <- IO String
D.getTemporaryDirectory
  E.bracket (IO.openTempFile dir "agda2-mode") (IO.hClose . snd) $ \ (String
filepath, Handle
handle) -> do
    Handle -> TextEncoding -> IO ()
IO.hSetEncoding Handle
handle TextEncoding
IO.utf8
    Handle -> String -> IO ()
IO.hPutStr Handle
handle String
content
    String -> IO String
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return String
filepath