Skip to content
This repository has been archived by the owner on Apr 25, 2020. It is now read-only.

add elispPath command to bootstrap elisp code from ghc-mod installation #492

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dist/
elisp/*.elc
elisp-bootstrap/*.elc
*~
/.cabal-sandbox/
add-source-timestamps
Expand Down
30 changes: 30 additions & 0 deletions elisp-bootstrap/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
SRCS = ghc-mod.el
EMACS = emacs
DETECT = xemacs

TEMPFILE = temp.el

all: $(TEMPFILE) ghc-mod.el
$(EMACS) -batch -q -no-site-file -l ./$(TEMPFILE) -f ghc-compile
rm -f $(TEMPFILE)

detect: $(TEMPFILE) ghc-mod.el
$(EMACS) -batch -q -no-site-file -l ./$(TEMPFILE) -f ghc-compile
rm -f $(DETECT)

$(TEMPFILE):
@echo '(setq load-path (cons "." load-path))' >> $(TEMPFILE)
@echo '(defun ghc-compile () (mapcar (lambda (x) (byte-compile-file x)) (list ' >> $(TEMPFILE)
@echo $(SRCS)| sed -e 's/\(ghc[^ ]*\.el\)/"\1"/g' >> $(TEMPFILE)
@echo ')))' >> $(TEMPFILE)

clean:
rm -f *.elc $(TEMPFILE)

VERSION = `grep version ghc-mod.el | sed -e 's/[^0-9\.]//g'`

bump:
echo "(define-package\n \"ghc-mod\"\n $(VERSION)\n \"Sub mode for Haskell mode\"\n nil)" > ghc-pkg.el

archive:
git archive master -o ~/ghc-$(VERSION).tar --prefix=ghc-$(VERSION)/
12 changes: 12 additions & 0 deletions elisp-bootstrap/ghc-mod.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(defconst ghc-version "0")
(defvar ghc-module-command "ghc-mod"
"*The command name of \"ghc-mod\"")
(defvar ghc-bootstrapped nil)

(defun ghc-bootstrap ()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just prefix all symbols with ghc-mod instead of ghc I'd like to move away from the elisp package being called ghc, might as well start now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good plan, I'll do that when I get back from lunch.

(unless ghc-bootstrapped
(dolist (path (process-lines ghc-module-command "elispPath"))
(add-to-list 'load-path path)
(setq ghc-bootstrapped t)))
(when (fboundp 'ghc-init)
(ghc-init)))
2 changes: 2 additions & 0 deletions ghc-mod.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Data-Files: elisp/Makefile
Data-Files: LICENSE COPYING.BSD3 COPYING.AGPL3
Extra-Source-Files: ChangeLog
SetupCompat.hs
elisp-bootstrap/Makefile
elisp-bootstrap/*.el
NotCPP/*.hs
test/data/annotations/*.hs
test/data/broken-cabal/*.cabal
Expand Down
5 changes: 4 additions & 1 deletion scripts/bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ cd $(dirname $0)/..
sed -i 's/(defconst ghc-version ".*")/(defconst ghc-version "'"$VERSION"'")/' \
elisp/ghc.el

sed -i 's/(defconst ghc-version ".*")/(defconst ghc-version "'"$VERSION"'")/' \
elisp-bootstrap/ghc-mod.el

sed -r -i 's/^(Version:[[:space:]]*)[0-9.]+/\1'"$VERSION"'/' ghc-mod.cabal

( tac ChangeLog; echo "\n$(date '+%Y-%m-%d') v$VERSION" ) | tac \
Expand All @@ -26,6 +29,6 @@ mv ChangeLog.tmp ChangeLog

emacs -q -nw ChangeLog

git add ChangeLog elisp/ghc.el ghc-mod.cabal
git add ChangeLog elisp/ghc.el elisp-bootstrap/ghc-mod.el ghc-mod.cabal
git commit -m "Bump version to $VERSION"
git tag "v$VERSION"
13 changes: 11 additions & 2 deletions src/GHCMod.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Data.Char (isSpace)
import Exception
import Language.Haskell.GhcMod
import Language.Haskell.GhcMod.Internal
import Paths_ghc_mod
import Paths_ghc_mod (version, getDataFileName)
import System.Console.GetOpt (OptDescr(..), ArgDescr(..), ArgOrder(..))
import qualified System.Console.GetOpt as O
import System.Directory (setCurrentDirectory)
Expand Down Expand Up @@ -187,6 +187,9 @@ usage =
\ - boot\n\
\ Internal command used by the emacs frontend.\n\
\\n\
\ - elispPath\n\
\ Internal command used by the emacs frontend.\n\
\\n\
\ - legacy-interactive\n\
\ ghc-modi compatibility mode.\n"
where
Expand Down Expand Up @@ -401,6 +404,7 @@ legacyInteractiveLoop symdbreq ref world = do
"refine" -> refineCmd args

"boot" -> bootCmd []
"elispPath" -> elispPathCmd []
"browse" -> browseCmd args

"quit" -> liftIO $ exitSuccess
Expand All @@ -410,6 +414,9 @@ legacyInteractiveLoop symdbreq ref world = do
liftIO $ putStr res >> putStrLn "OK" >> hFlush stdout
legacyInteractiveLoop symdbreq ref world

elispPath :: IOish m => GhcModT m String
elispPath = liftIO $ getDataFileName "elisp"

globalCommands :: [String] -> Maybe String
globalCommands [] = Nothing
globalCommands (cmd:_) = case cmd of
Expand Down Expand Up @@ -443,6 +450,7 @@ ghcCommands (cmd:args) = do
"doc" -> pkgDocCmd
"dumpsym" -> dumpSymbolCmd
"boot" -> bootCmd
"elispPath" -> elispPathCmd
"legacy-interactive" -> legacyInteractiveCmd
_ -> fatalError $ "unknown command: `" ++ cmd ++ "'"

Expand Down Expand Up @@ -487,7 +495,7 @@ catchArgs cmd action =
modulesCmd, languagesCmd, flagsCmd, browseCmd, checkSyntaxCmd, expandTemplateCmd,
debugInfoCmd, componentInfoCmd, infoCmd, typesCmd, splitsCmd, sigCmd,
refineCmd, autoCmd, findSymbolCmd, lintCmd, rootInfoCmd, pkgDocCmd,
dumpSymbolCmd, bootCmd, legacyInteractiveCmd
dumpSymbolCmd, bootCmd, legacyInteractiveCmd, elispPathCmd
:: IOish m => [String] -> GhcModT m String

modulesCmd = withParseCmd' "modules" s $ \[] -> modules
Expand All @@ -499,6 +507,7 @@ rootInfoCmd = withParseCmd' "root" [] $ \[] -> rootInfo
componentInfoCmd = withParseCmd' "debugComponent" [] $ \ts -> componentInfo ts
-- internal
bootCmd = withParseCmd' "boot" [] $ \[] -> boot
elispPathCmd = withParseCmd' "elispPath" [] $ \[] -> elispPath

dumpSymbolCmd = withParseCmd' "dump" [] $ \[tmpdir] -> dumpSymbol tmpdir
findSymbolCmd = withParseCmd' "find" [] $ \[sym] -> findSymbol sym
Expand Down