From 681d165b101cad5f3bb93156fadba515e582acab Mon Sep 17 00:00:00 2001 From: knupfer Date: Mon, 18 Jul 2016 22:42:25 +0200 Subject: [PATCH 1/3] Refactor processes --- haskell-emacs.el | 56 +++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/haskell-emacs.el b/haskell-emacs.el index 1d18d8a..fb96514 100644 --- a/haskell-emacs.el +++ b/haskell-emacs.el @@ -114,23 +114,8 @@ 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--stop-proc) (setq haskell-emacs--response nil) (setq haskell-emacs--function-hash (with-temp-buffer (mapc 'insert-file-contents funs) @@ -147,7 +132,7 @@ 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))) @@ -155,7 +140,7 @@ Call `haskell-emacs-help' to read the documentation." 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 @@ -318,11 +303,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") @@ -371,15 +371,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." From 68a3e6c6aa6f53a877f2508d0ee2089e555eacd2 Mon Sep 17 00:00:00 2001 From: knupfer Date: Mon, 18 Jul 2016 23:12:22 +0200 Subject: [PATCH 2/3] factor out getting the binary path --- haskell-emacs.el | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/haskell-emacs.el b/haskell-emacs.el index fb96514..7498aac 100644 --- a/haskell-emacs.el +++ b/haskell-emacs.el @@ -115,6 +115,7 @@ Call `haskell-emacs-help' to read the documentation." (insert-file-contents (concat haskell-emacs--load-dir "HaskellEmacs.hs")) (buffer-string)))) + (haskell-emacs--set-bin) (haskell-emacs--stop-proc) (setq haskell-emacs--response nil) (setq haskell-emacs--function-hash @@ -390,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 @@ -409,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.pkgs.haskellPackages.callPackage ./HaskellEmacs.nix { }") @@ -423,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 From dbacd544080c90e99cf1e87dc41524f24159c32e Mon Sep 17 00:00:00 2001 From: knupfer Date: Tue, 19 Jul 2016 01:15:58 +0200 Subject: [PATCH 3/3] clean up .travis --- .travis.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 53d61d5..ae935c8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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"