Skip to content
Merged
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
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ language: bash

sudo: required

matrix:
include:
- env: NIXCHAN=15.09
- env: NIXCHAN=16.03
- env: NIXCHAN=unstable
env:
- NIXCHAN=15.09
- NIXCHAN=16.03
- NIXCHAN=unstable

install:
- curl https://nixos.org/nix/install | sh
- source /home/travis/.nix-profile/etc/profile.d/nix.sh
- nix-channel --add https://nixos.org/channels/nixos-$NIXCHAN nixpkgs
- nix-channel --update
- export NIX_PATH=https://nixos.org/channels/nixos-$NIXCHAN/nixexprs.tar.xz

script:
- nix-shell -Q --pure -p haskellPackages.hlint --command "hlint HaskellEmacs.hs"
Expand Down
79 changes: 42 additions & 37 deletions haskell-emacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,9 @@ Call `haskell-emacs-help' to read the documentation."
(code (with-temp-buffer
(insert-file-contents
(concat haskell-emacs--load-dir "HaskellEmacs.hs"))
(buffer-string)))
(stop-proc
'(when haskell-emacs--proc
(set-process-sentinel haskell-emacs--proc nil)
(delete-process haskell-emacs--proc)))
(start-proc
'(progn
(setq haskell-emacs--proc
(start-process "hask" nil haskell-emacs--bin))
(set-process-filter haskell-emacs--proc
'haskell-emacs--filter)
(set-process-query-on-exit-flag haskell-emacs--proc nil)
(set-process-sentinel haskell-emacs--proc
(lambda (proc sign)
(let ((debug-on-error t))
(error "Haskell-emacs crashed")))))))
(eval stop-proc)
(buffer-string))))
(haskell-emacs--set-bin)
(haskell-emacs--stop-proc)
(setq haskell-emacs--response nil)
(setq haskell-emacs--function-hash
(with-temp-buffer (mapc 'insert-file-contents funs)
Expand All @@ -147,15 +133,15 @@ Call `haskell-emacs-help' to read the documentation."
(re-search-forward haskell-emacs--function-hash
nil t))))))
(when has-changed (haskell-emacs--compile code))
(eval start-proc)
(haskell-emacs--start-proc)
(setq funs (mapcar (lambda (f) (with-temp-buffer
(insert-file-contents f)
(buffer-string)))
funs)
docs (apply 'concat funs)
funs (haskell-emacs--fun-body 'allExports (apply 'list "" "" funs)))
(when (stringp funs)
(eval stop-proc)
(haskell-emacs--stop-proc)
(error funs))
(setq docs (haskell-emacs--fun-body
'getDocumentation
Expand Down Expand Up @@ -318,11 +304,26 @@ dyadic xs ys = map (\\x -> map (x*) ys) xs")
(eval res)
res)))

(defun haskell-emacs--compile (code)
"Use CODE to compile a new haskell Emacs programm."
(defun haskell-emacs--start-proc ()
"Start an haskell-emacs process."
(setq haskell-emacs--proc (start-process "hask" nil haskell-emacs--bin))
(set-process-filter haskell-emacs--proc 'haskell-emacs--filter)
(set-process-query-on-exit-flag haskell-emacs--proc nil)
(set-process-sentinel
haskell-emacs--proc
(lambda (proc sign)
(let ((debug-on-error t))
(error "Haskell-emacs crashed")))))

(defun haskell-emacs--stop-proc ()
"Stop haskell-emacs process."
(when haskell-emacs--proc
(set-process-sentinel haskell-emacs--proc nil)
(delete-process haskell-emacs--proc))
(kill-process haskell-emacs--proc)
(setq haskell-emacs--proc nil)))

(defun haskell-emacs--compile (code)
"Use CODE to compile a new haskell Emacs programm."
(with-temp-buffer
(let* ((heB "*HASKELL-BUFFER*")
(heF "HaskellEmacs.hs")
Expand Down Expand Up @@ -371,15 +372,9 @@ executable HaskellEmacs
(insert-file-contents (concat (file-name-directory haskell-emacs--load-dir)
"Foreign/Emacs/Internal.hs"))
(write-file "Foreign/Emacs/Internal.hs")))
(haskell-emacs--compile-command heB)))
(setq haskell-emacs--proc
(start-process "hask" nil haskell-emacs--bin))
(set-process-filter haskell-emacs--proc 'haskell-emacs--filter)
(set-process-query-on-exit-flag haskell-emacs--proc nil)
(set-process-sentinel haskell-emacs--proc
(lambda (proc sign)
(let ((debug-on-error t))
(error "Haskell-emacs crashed")))))
(haskell-emacs--stop-proc)
(haskell-emacs--compile-command heB)
(haskell-emacs--start-proc))))

(defun haskell-emacs--get-build-tool ()
"Guess the build tool."
Expand All @@ -396,14 +391,12 @@ executable HaskellEmacs
(if (eql 0
(let ((tool (haskell-emacs--get-build-tool)))
(if (eq tool 'cabal)
(progn (setq haskell-emacs--bin (concat haskell-emacs-dir ".cabal-sandbox/bin/HaskellEmacs" (when (eq system-type 'windows-nt) ".exe")))
(message "Compiling ...")
(progn (message "Compiling ...")
(+ (call-process "cabal" nil heB nil "sandbox" "init")
(call-process "cabal" nil heB nil "install" "happy")
(call-process "cabal" nil heB nil "install")))
(if (eq tool 'stack)
(progn (setq haskell-emacs--bin (concat "~/.local/bin/HaskellEmacs" (when (eq system-type 'windows-nt) ".exe")))
(unless (file-exists-p (concat haskell-emacs-dir "stack.yaml"))
(progn (unless (file-exists-p (concat haskell-emacs-dir "stack.yaml"))
(with-temp-buffer
(insert "
resolver: lts-6.6
Expand All @@ -415,8 +408,7 @@ extra-deps: [ atto-lisp-0.2.2.2 ]")
(+ (call-process "stack" nil heB nil "setup")
(call-process "stack" nil heB nil "install")))
(if (eq tool 'nix)
(progn (setq haskell-emacs--bin (concat haskell-emacs-dir "result/bin/HaskellEmacs"))
(unless (file-exists-p (concat haskell-emacs-dir "default.nix"))
(progn (unless (file-exists-p (concat haskell-emacs-dir "default.nix"))
(with-temp-buffer (insert "
{ nixpkgs ? import <nixpkgs> {} }:
nixpkgs.pkgs.haskellPackages.callPackage ./HaskellEmacs.nix { }")
Expand All @@ -429,6 +421,19 @@ nixpkgs.pkgs.haskellPackages.callPackage ./HaskellEmacs.nix { }")
(kill-buffer heB)
(error bug))))

(defun haskell-emacs--set-bin ()
"Set the path of the executable."
(setq haskell-emacs--bin
(let ((tool (haskell-emacs--get-build-tool)))
(if (eq tool 'nix)
(concat haskell-emacs-dir "result/bin/HaskellEmacs")
(if (eq tool 'stack)
(concat "~/.local/bin/HaskellEmacs" (when (eq system-type 'windows-nt) ".exe"))
(when (eq tool 'cabal)
(concat haskell-emacs-dir
".cabal-sandbox/bin/HaskellEmacs"
(when (eq system-type 'windows-nt) ".exe"))))))))

(provide 'haskell-emacs)

;;; haskell-emacs.el ends here