~ubuntu-branches/ubuntu/trusty/agda/trusty

« back to all changes in this revision

Viewing changes to src/agda-mode/Main.hs

  • Committer: Package Import Robot
  • Author(s): Iain Lane, Kiwamu Okabe, Iain Lane
  • Date: 2013-04-10 11:46:43 UTC
  • mfrom: (4.1.5 experimental)
  • Revision ID: package-import@ubuntu.com-20130410114643-prunhsz59f0fhrdn
Tags: 2.3.2-1
[ Kiwamu Okabe ]
* New patch: Extend haskell-src-exts dependency and fix type miss.

[ Iain Lane ]
* [dfbca48] Imported Upstream version 2.3.2
* [7746bcc] Remove all patches — all upstream.
* [2cdb691] Update build-deps to match control file
* [868ebf4] agda-mode no longer depends on haskell-mode or GHCi.
  Remove dependency and update .el file accordingly
* [9e0ba22] Add agda-bin package here, as the separate package has been
  removed
* [75a240f] agda-mode needs to depend on agda-bin
* [d290f95] Allow Quickcheck up to 2.7. Fix haskeline build-dep.
* [79190e6] Add missing geniplate and parallel BDs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
{-# LANGUAGE CPP #-}
2
 
 
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.
6
4
 
7
5
module Main (main) where
8
6
 
 
7
import Control.Applicative
9
8
import Control.Exception
10
9
import Control.Monad
11
10
import Data.Char
17
16
import System.Exit
18
17
import System.FilePath
19
18
import System.IO
20
 
#if !(MIN_VERSION_base(4,2,0))
21
 
import qualified System.IO.UTF8 as UTF8
22
 
#endif
23
19
import System.Process
24
20
 
25
21
import Paths_Agda (getDataDir, version)
37
33
             setupDotEmacs (Files { thisProgram = prog
38
34
                                  , dotEmacs    = dotEmacs
39
35
                                  })
 
36
          | arg == compileFlag ->
 
37
             compileElispFiles
40
38
    _  -> do inform usage
41
39
             exitFailure
42
40
 
43
41
-- Command line options.
44
42
 
45
 
setupFlag  = "setup"
46
 
locateFlag = "locate"
 
43
setupFlag   = "setup"
 
44
locateFlag  = "locate"
 
45
compileFlag = "compile"
47
46
 
48
47
-- | Usage information.
49
48
 
50
49
usage :: String
51
50
usage = unlines
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:"
54
53
  , ""
55
54
  , setupFlag
56
55
  , ""
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."
61
 
#else
62
 
  , "  uses ASCII or some other character encoding which ASCII is"
63
 
  , "  compatible with (like Latin-1 or UTF-8)."
64
 
#endif
65
59
  , ""
66
60
  , locateFlag
67
61
  , ""
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"
70
64
  , "  newline)."
 
65
  , ""
 
66
  , compileFlag
 
67
  , ""
 
68
  , "  The program tries to compile Agda's Emacs mode's source files."
 
69
  , ""
 
70
  , "  WARNING: If you reinstall the Agda mode without recompiling the Emacs"
 
71
  , "  Lisp files, then Emacs may continue using the old, compiled files."
71
72
  ]
72
73
 
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
91
91
  putStr path
92
 
#else
93
 
  UTF8.putStr path
94
 
#endif
95
92
 
96
93
------------------------------------------------------------------------
97
94
-- Setting up the .emacs file
193
190
        | otherwise              = "\\x" ++ showHex (fromEnum c) "\\ "
194
191
 
195
192
------------------------------------------------------------------------
 
193
-- Compiling Emacs Lisp files
 
194
 
 
195
-- | The Agda mode's Emacs Lisp files, given in the order in which
 
196
-- they should be compiled.
 
197
 
 
198
emacsLispFiles :: [FilePath]
 
199
emacsLispFiles =
 
200
  [ "agda2-abbrevs.el"
 
201
  , "annotation.el"
 
202
  , "agda2-queue.el"
 
203
  , "eri.el"
 
204
  , "agda2.el"
 
205
  , "agda-input.el"
 
206
  , "agda2-highlight.el"
 
207
  , "agda2-mode.el"
 
208
  ]
 
209
 
 
210
-- | Tries to compile the Agda mode's Emacs Lisp files.
 
211
 
 
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
 
220
                    , "--batch"
 
221
                    , "--funcall", "batch-byte-compile"
 
222
                    ] ++ elFiles
 
223
  unless (exit == ExitSuccess) $ do
 
224
    informLn "Unable to compile Emacs Lisp files."
 
225
    exitFailure
 
226
 
 
227
------------------------------------------------------------------------
196
228
-- Helper functions
197
229
 
198
230
-- These functions inform the user about something by printing on