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 all 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-internal/*.elc
*~
/.cabal-sandbox/
add-source-timestamps
Expand Down
31 changes: 31 additions & 0 deletions elisp-internal/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
SRCS = ghc.el ghc-func.el ghc-doc.el ghc-comp.el ghc-check.el ghc-process.el \
ghc-command.el ghc-info.el ghc-ins-mod.el ghc-indent.el ghc-rewrite.el
EMACS = emacs
DETECT = xemacs

TEMPFILE = temp.el

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

detect: $(TEMPFILE) ghc.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.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)/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions elisp-internal/ghc-mod-internal-pkg.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(define-package
"ghc-mod-internal"
2.0.0
"Sub mode for Haskell mode"
'((haskell-mode "13.0")))
36 changes: 17 additions & 19 deletions elisp/ghc.el → elisp-internal/ghc-mod-internal.el
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
;;; ghc.el --- ghc-mod front-end for haskell-mode
;;; ghc-mod-internal.el --- ghc-mod front-end for haskell-mode

;; Author: Kazu Yamamoto <[email protected]>
;; Created: Sep 25, 2009
;; Revised:

;; Put the following code to your "~/.emacs".
;;
;; (autoload 'ghc-init "ghc" nil t)
;; (autoload 'ghc-debug "ghc" nil t)
;; (add-hook 'haskell-mode-hook (lambda () (ghc-init)))
;; (autoload 'ghc-mod-internal-init "ghc" nil t)
;; (autoload 'ghc-mod-internal-debug "ghc" nil t)
;; (add-hook 'haskell-mode-hook (lambda () (ghc-mod-internal-init)))
;;
;; Or if you wish to display error each goto next/prev error,
;; set ghc-display-error valiable.
Expand All @@ -28,7 +28,7 @@
(< emacs-minor-version minor)))
(error "ghc-mod requires at least Emacs %d.%d" major minor)))

(defconst ghc-version "0")
(defconst ghc-mod-version "0")

;; (eval-when-compile
;; (require 'haskell-mode))
Expand Down Expand Up @@ -86,7 +86,7 @@
(defvar ghc-initialized nil)

;;;###autoload
(defun ghc-init ()
(defun ghc-mod-internal-init ()
(ghc-abbrev-init)
(ghc-type-init)
(unless ghc-initialized
Expand Down Expand Up @@ -125,28 +125,26 @@
(set (make-local-variable 'dabbrev-case-fold-search) nil))

;;;###autoload
(defun ghc-debug ()
(defun ghc-mod-internal-debug ()
(interactive)
(let ((el-path (locate-file "ghc.el" load-path))
(let ((el-path (locate-file "ghc-mod-internal.el" load-path))
(bootstrap-el-path (locate-file "ghc-mod.el" load-path))
(ghc-path (executable-find "ghc")) ;; FIXME
(ghc-mod-path (executable-find ghc-module-command))
(ghc-modi-path (executable-find ghc-interactive-command))
(el-ver ghc-version)
(el-ver ghc-mod-version)
(ghc-ver (ghc-run-ghc-mod '("--version") "ghc"))
(ghc-mod-ver (ghc-run-ghc-mod '("version")))
(ghc-modi-ver (ghc-run-ghc-mod '("version") ghc-interactive-command))
(path (getenv "PATH")))
(switch-to-buffer (get-buffer-create "**GHC Debug**"))
(erase-buffer)
(insert "Path: check if you are using intended programs.\n")
(insert (format "\t ghc.el path: %s\n" el-path))
(insert (format "\t ghc-mod path: %s\n" ghc-mod-path))
(insert (format "\tghc-modi path: %s\n" ghc-modi-path))
(insert (format "\t ghc path: %s\n" ghc-path))
(insert (format "\t ghc-mod.el path: %s\n" bootstrap-el-path))
(insert (format "\t ghc-mod-internal.el path: %s\n" el-path))
(insert (format "\t ghc-mod path: %s\n" ghc-mod-path))
(insert (format "\t ghc path: %s\n" ghc-path))
(insert "\nVersion: all versions must be the same.\n")
(insert (format "\t ghc.el version %s\n" el-ver))
(insert (format "\t %s\n" ghc-mod-ver))
(insert (format "\t%s\n" ghc-modi-ver))
(insert (format "\tghc-mod-internal.el version %s\n" el-ver))
(insert (format "\t %s\n" ghc-mod-ver))
(insert (format "\t%s\n" ghc-ver))
(insert "\nEnvironment variables:\n")
(insert (format "\tPATH=%s\n" path))))
Expand All @@ -157,4 +155,4 @@
(ghc-initial-code-from-signature)
(ghc-insert-template)))

(provide 'ghc)
(provide 'ghc-mod-internal)
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions elisp/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
SRCS = ghc.el ghc-func.el ghc-doc.el ghc-comp.el ghc-check.el ghc-process.el \
ghc-command.el ghc-info.el ghc-ins-mod.el ghc-indent.el ghc-rewrite.el
SRCS = ghc-mod.el
EMACS = emacs
DETECT = xemacs

TEMPFILE = temp.el

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

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

Expand All @@ -22,7 +21,7 @@ $(TEMPFILE):
clean:
rm -f *.elc $(TEMPFILE)

VERSION = `grep version ghc.el | sed -e 's/[^0-9\.]//g'`
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
Expand Down
42 changes: 42 additions & 0 deletions elisp/ghc-mod.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(defconst ghc-mod-version "0")
(defvar ghc-module-command "ghc-mod"
"*The command name of \"ghc-mod\"")
(defvar ghc-bootstrapped nil)

;;;###autoload
(defun ghc-mod-bootstrap ()
(unless ghc-bootstrapped
(dolist (path (process-lines ghc-module-command "elispPath"))
(add-to-list 'load-path path)
(require 'ghc-mod-internal)
(setq ghc-bootstrapped t))))

;;;###autoload
(defun ghc-mod-init ()
(ghc-mod-bootstrap)
(when (fboundp 'ghc-mod-internal-init)
(ghc-mod-internal-init)))

;;;###autoload
(defun ghc-mod-debug ()
(condition-case err
(ghc-mod-bootstrap)
('error
(interactive)
(switch-to-buffer (get-buffer-create "**GHC Debug**"))
(erase-buffer)
(insert "Error loading ghc-mod-internal. Check that ghc-mod is available on the PATH.\n")
(insert (format "Exception: %s\n" err))
(insert (format "PATH: %s" (getenv "PATH")))))
(when (fboundp 'ghc-mod-internal-debug)
(ghc-mod-internal-debug)))

;;;###autoload
(defun ghc-init ()
"Backwards compatible shim for ghc-mod-init"
(ghc-mod-init))

;;;###autoload
(defun ghc-debug ()
"Backwards compatible shim for ghc-mod-debug"
(ghc-mod-debug))
6 changes: 4 additions & 2 deletions ghc-mod.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ Description:
Category: GHC, Development
Cabal-Version: >= 1.14
Build-Type: Custom
Data-Files: elisp/Makefile
elisp/*.el
Data-Files: elisp-internal/Makefile
elisp-internal/*.el
Data-Files: LICENSE COPYING.BSD3 COPYING.AGPL3
Extra-Source-Files: ChangeLog
SetupCompat.hs
elisp/Makefile
elisp/*.el
NotCPP/*.hs
test/data/annotations/*.hs
test/data/broken-cabal/*.cabal
Expand Down
9 changes: 6 additions & 3 deletions scripts/bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ fi

cd $(dirname $0)/..

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

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

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

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-internal/ghc.el elisp/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-internal"

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