module Agda.Interaction.EmacsCommand
( Lisp(..)
, response
, putResponse
, display_info'
, clearRunningInfo
, clearWarning
, displayRunningInfo
) where
import qualified Data.List as List
import Agda.Utils.Pretty
import Agda.Utils.String
data Lisp a
= A a
| Cons (Lisp a) (Lisp a)
| L [Lisp a]
| Q (Lisp a)
deriving Lisp a -> Lisp a -> Bool
forall a. Eq a => Lisp a -> Lisp a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Lisp a -> Lisp a -> Bool
$c/= :: forall a. Eq a => Lisp a -> Lisp a -> Bool
== :: Lisp a -> Lisp a -> Bool
$c== :: forall a. Eq a => Lisp a -> Lisp a -> Bool
Eq
instance Pretty a => Pretty (Lisp a) where
pretty :: Lisp a -> Doc
pretty (A a
a ) = forall a. Pretty a => a -> Doc
pretty a
a
pretty (Cons Lisp a
a Lisp a
b) = Doc -> Doc
parens (forall a. Pretty a => a -> Doc
pretty Lisp a
a Doc -> Doc -> Doc
<+> Doc
"." Doc -> Doc -> Doc
<+> forall a. Pretty a => a -> Doc
pretty Lisp a
b)
pretty (L [Lisp a]
xs) = Doc -> Doc
parens (forall (t :: * -> *). Foldable t => t Doc -> Doc
hsep (forall a b. (a -> b) -> [a] -> [b]
map forall a. Pretty a => a -> Doc
pretty [Lisp a]
xs))
pretty (Q Lisp a
x) = Doc
"'" forall a. Semigroup a => a -> a -> a
<> forall a. Pretty a => a -> Doc
pretty Lisp a
x
response :: Lisp String -> String
response :: Lisp String -> String
response = (forall a. [a] -> [a] -> [a]
++ String
"\n") forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
replaceNewLines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Pretty a => a -> Doc
pretty
where
replaceNewLines :: Char -> Char
replaceNewLines Char
'\n' = Char
' '
replaceNewLines Char
c = Char
c
putResponse :: Lisp String -> IO ()
putResponse :: Lisp String -> IO ()
putResponse = String -> IO ()
putStr forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lisp String -> String
response
displayInBuffer :: String -> Bool -> String -> String -> Lisp String
displayInBuffer :: String -> Bool -> String -> String -> Lisp String
displayInBuffer String
buffername Bool
append String
header String
content =
forall a. [Lisp a] -> Lisp a
L [ forall a. a -> Lisp a
A String
buffername
, forall a. a -> Lisp a
A (String -> String
quote String
header)
, forall a. a -> Lisp a
A (String -> String
quote String
content)
, forall a. a -> Lisp a
A (if Bool
append then String
"t" else String
"nil")
]
display_info' :: Bool -> String -> String -> Lisp String
display_info' :: Bool -> String -> String -> Lisp String
display_info' = String -> Bool -> String -> String -> Lisp String
displayInBuffer String
"agda2-info-action"
runningInfoBufferName :: String
runningInfoBufferName :: String
runningInfoBufferName = String
"*Type-checking*"
clearRunningInfo :: Lisp String
clearRunningInfo :: Lisp String
clearRunningInfo =
Bool -> String -> String -> Lisp String
display_info' Bool
False String
runningInfoBufferName String
""
clearWarning :: Lisp String
clearWarning :: Lisp String
clearWarning = forall a. [Lisp a] -> Lisp a
L [ forall a. a -> Lisp a
A String
"agda2-close-warning" ]
displayRunningInfo :: String -> Lisp String
displayRunningInfo :: String -> Lisp String
displayRunningInfo String
s =
Bool -> String -> String -> Lisp String
display_info' Bool
True String
runningInfoBufferName String
s