3
1
-- | A program which either tries to add setup code for Agda's Emacs
4
2
-- mode to the users .emacs file, or provides information to Emacs
5
3
-- about where the Emacs mode is installed.
7
5
module Main (main) where
7
import Control.Applicative
9
8
import Control.Exception
10
9
import Control.Monad
18
17
import System.FilePath
20
#if !(MIN_VERSION_base(4,2,0))
21
import qualified System.IO.UTF8 as UTF8
23
19
import System.Process
25
21
import Paths_Agda (getDataDir, version)
37
33
setupDotEmacs (Files { thisProgram = prog
38
34
, dotEmacs = dotEmacs
36
| arg == compileFlag ->
40
38
_ -> do inform usage
43
41
-- Command line options.
45
compileFlag = "compile"
48
47
-- | Usage information.
52
51
[ "This program, which is part of Agda version " ++ ver ++ ", can be run"
53
, "in two modes, depending on which option it is invoked with:"
52
, "in three modes, depending on which option it is invoked with:"
57
56
, " The program tries to add setup code for Agda's Emacs mode to the"
58
57
, " current user's .emacs file. It is assumed that the .emacs file"
59
#if MIN_VERSION_base(4,2,0)
60
58
, " uses the character encoding specified by the locale."
62
, " uses ASCII or some other character encoding which ASCII is"
63
, " compatible with (like Latin-1 or UTF-8)."
68
62
, " The path to the Emacs mode's main file is printed on standard"
69
63
, " output (using the UTF-8 character encoding and no trailing"
68
, " The program tries to compile Agda's Emacs mode's source files."
70
, " WARNING: If you reinstall the Agda mode without recompiling the Emacs"
71
, " Lisp files, then Emacs may continue using the old, compiled files."
73
74
-- | The current version of Agda.
86
87
printEmacsModeFile = do
87
88
dataDir <- getDataDir
88
89
let path = dataDir </> "emacs-mode" </> "agda2.el"
89
#if MIN_VERSION_base(4,2,0)
90
90
hSetEncoding stdout utf8
96
93
------------------------------------------------------------------------
97
94
-- Setting up the .emacs file
193
190
| otherwise = "\\x" ++ showHex (fromEnum c) "\\ "
195
192
------------------------------------------------------------------------
193
-- Compiling Emacs Lisp files
195
-- | The Agda mode's Emacs Lisp files, given in the order in which
196
-- they should be compiled.
198
emacsLispFiles :: [FilePath]
206
, "agda2-highlight.el"
210
-- | Tries to compile the Agda mode's Emacs Lisp files.
212
compileElispFiles :: IO ()
213
compileElispFiles = do
214
dataDir <- (</> "emacs-mode") <$> getDataDir
215
let elFiles = map (dataDir </>) emacsLispFiles
216
elFiles <- filterM doesFileExist elFiles
217
exit <- rawSystem "emacs" $
218
[ "--no-init-file", "--no-site-file"
219
, "--directory", dataDir
221
, "--funcall", "batch-byte-compile"
223
unless (exit == ExitSuccess) $ do
224
informLn "Unable to compile Emacs Lisp files."
227
------------------------------------------------------------------------
196
228
-- Helper functions
198
230
-- These functions inform the user about something by printing on