Skip to content

Commit a2c6a07

Browse files
authored
Merge pull request #64 from knupfer/refactor
Refactor
2 parents 78af3b4 + dbacd54 commit a2c6a07

File tree

2 files changed

+47
-44
lines changed

2 files changed

+47
-44
lines changed

.travis.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ language: bash
22

33
sudo: required
44

5-
matrix:
6-
include:
7-
- env: NIXCHAN=15.09
8-
- env: NIXCHAN=16.03
9-
- env: NIXCHAN=unstable
5+
env:
6+
- NIXCHAN=15.09
7+
- NIXCHAN=16.03
8+
- NIXCHAN=unstable
109

1110
install:
1211
- curl https://nixos.org/nix/install | sh
1312
- source /home/travis/.nix-profile/etc/profile.d/nix.sh
14-
- nix-channel --add https://nixos.org/channels/nixos-$NIXCHAN nixpkgs
15-
- nix-channel --update
13+
- export NIX_PATH=https://nixos.org/channels/nixos-$NIXCHAN/nixexprs.tar.xz
1614

1715
script:
1816
- nix-shell -Q --pure -p haskellPackages.hlint --command "hlint HaskellEmacs.hs"

haskell-emacs.el

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,9 @@ Call `haskell-emacs-help' to read the documentation."
114114
(code (with-temp-buffer
115115
(insert-file-contents
116116
(concat haskell-emacs--load-dir "HaskellEmacs.hs"))
117-
(buffer-string)))
118-
(stop-proc
119-
'(when haskell-emacs--proc
120-
(set-process-sentinel haskell-emacs--proc nil)
121-
(delete-process haskell-emacs--proc)))
122-
(start-proc
123-
'(progn
124-
(setq haskell-emacs--proc
125-
(start-process "hask" nil haskell-emacs--bin))
126-
(set-process-filter haskell-emacs--proc
127-
'haskell-emacs--filter)
128-
(set-process-query-on-exit-flag haskell-emacs--proc nil)
129-
(set-process-sentinel haskell-emacs--proc
130-
(lambda (proc sign)
131-
(let ((debug-on-error t))
132-
(error "Haskell-emacs crashed")))))))
133-
(eval stop-proc)
117+
(buffer-string))))
118+
(haskell-emacs--set-bin)
119+
(haskell-emacs--stop-proc)
134120
(setq haskell-emacs--response nil)
135121
(setq haskell-emacs--function-hash
136122
(with-temp-buffer (mapc 'insert-file-contents funs)
@@ -147,15 +133,15 @@ Call `haskell-emacs-help' to read the documentation."
147133
(re-search-forward haskell-emacs--function-hash
148134
nil t))))))
149135
(when has-changed (haskell-emacs--compile code))
150-
(eval start-proc)
136+
(haskell-emacs--start-proc)
151137
(setq funs (mapcar (lambda (f) (with-temp-buffer
152138
(insert-file-contents f)
153139
(buffer-string)))
154140
funs)
155141
docs (apply 'concat funs)
156142
funs (haskell-emacs--fun-body 'allExports (apply 'list "" "" funs)))
157143
(when (stringp funs)
158-
(eval stop-proc)
144+
(haskell-emacs--stop-proc)
159145
(error funs))
160146
(setq docs (haskell-emacs--fun-body
161147
'getDocumentation
@@ -318,11 +304,26 @@ dyadic xs ys = map (\\x -> map (x*) ys) xs")
318304
(eval res)
319305
res)))
320306

321-
(defun haskell-emacs--compile (code)
322-
"Use CODE to compile a new haskell Emacs programm."
307+
(defun haskell-emacs--start-proc ()
308+
"Start an haskell-emacs process."
309+
(setq haskell-emacs--proc (start-process "hask" nil haskell-emacs--bin))
310+
(set-process-filter haskell-emacs--proc 'haskell-emacs--filter)
311+
(set-process-query-on-exit-flag haskell-emacs--proc nil)
312+
(set-process-sentinel
313+
haskell-emacs--proc
314+
(lambda (proc sign)
315+
(let ((debug-on-error t))
316+
(error "Haskell-emacs crashed")))))
317+
318+
(defun haskell-emacs--stop-proc ()
319+
"Stop haskell-emacs process."
323320
(when haskell-emacs--proc
324321
(set-process-sentinel haskell-emacs--proc nil)
325-
(delete-process haskell-emacs--proc))
322+
(kill-process haskell-emacs--proc)
323+
(setq haskell-emacs--proc nil)))
324+
325+
(defun haskell-emacs--compile (code)
326+
"Use CODE to compile a new haskell Emacs programm."
326327
(with-temp-buffer
327328
(let* ((heB "*HASKELL-BUFFER*")
328329
(heF "HaskellEmacs.hs")
@@ -371,15 +372,9 @@ executable HaskellEmacs
371372
(insert-file-contents (concat (file-name-directory haskell-emacs--load-dir)
372373
"Foreign/Emacs/Internal.hs"))
373374
(write-file "Foreign/Emacs/Internal.hs")))
374-
(haskell-emacs--compile-command heB)))
375-
(setq haskell-emacs--proc
376-
(start-process "hask" nil haskell-emacs--bin))
377-
(set-process-filter haskell-emacs--proc 'haskell-emacs--filter)
378-
(set-process-query-on-exit-flag haskell-emacs--proc nil)
379-
(set-process-sentinel haskell-emacs--proc
380-
(lambda (proc sign)
381-
(let ((debug-on-error t))
382-
(error "Haskell-emacs crashed")))))
375+
(haskell-emacs--stop-proc)
376+
(haskell-emacs--compile-command heB)
377+
(haskell-emacs--start-proc))))
383378

384379
(defun haskell-emacs--get-build-tool ()
385380
"Guess the build tool."
@@ -396,14 +391,12 @@ executable HaskellEmacs
396391
(if (eql 0
397392
(let ((tool (haskell-emacs--get-build-tool)))
398393
(if (eq tool 'cabal)
399-
(progn (setq haskell-emacs--bin (concat haskell-emacs-dir ".cabal-sandbox/bin/HaskellEmacs" (when (eq system-type 'windows-nt) ".exe")))
400-
(message "Compiling ...")
394+
(progn (message "Compiling ...")
401395
(+ (call-process "cabal" nil heB nil "sandbox" "init")
402396
(call-process "cabal" nil heB nil "install" "happy")
403397
(call-process "cabal" nil heB nil "install")))
404398
(if (eq tool 'stack)
405-
(progn (setq haskell-emacs--bin (concat "~/.local/bin/HaskellEmacs" (when (eq system-type 'windows-nt) ".exe")))
406-
(unless (file-exists-p (concat haskell-emacs-dir "stack.yaml"))
399+
(progn (unless (file-exists-p (concat haskell-emacs-dir "stack.yaml"))
407400
(with-temp-buffer
408401
(insert "
409402
resolver: lts-6.6
@@ -415,8 +408,7 @@ extra-deps: [ atto-lisp-0.2.2.2 ]")
415408
(+ (call-process "stack" nil heB nil "setup")
416409
(call-process "stack" nil heB nil "install")))
417410
(if (eq tool 'nix)
418-
(progn (setq haskell-emacs--bin (concat haskell-emacs-dir "result/bin/HaskellEmacs"))
419-
(unless (file-exists-p (concat haskell-emacs-dir "default.nix"))
411+
(progn (unless (file-exists-p (concat haskell-emacs-dir "default.nix"))
420412
(with-temp-buffer (insert "
421413
{ nixpkgs ? import <nixpkgs> {} }:
422414
nixpkgs.pkgs.haskellPackages.callPackage ./HaskellEmacs.nix { }")
@@ -429,6 +421,19 @@ nixpkgs.pkgs.haskellPackages.callPackage ./HaskellEmacs.nix { }")
429421
(kill-buffer heB)
430422
(error bug))))
431423

424+
(defun haskell-emacs--set-bin ()
425+
"Set the path of the executable."
426+
(setq haskell-emacs--bin
427+
(let ((tool (haskell-emacs--get-build-tool)))
428+
(if (eq tool 'nix)
429+
(concat haskell-emacs-dir "result/bin/HaskellEmacs")
430+
(if (eq tool 'stack)
431+
(concat "~/.local/bin/HaskellEmacs" (when (eq system-type 'windows-nt) ".exe"))
432+
(when (eq tool 'cabal)
433+
(concat haskell-emacs-dir
434+
".cabal-sandbox/bin/HaskellEmacs"
435+
(when (eq system-type 'windows-nt) ".exe"))))))))
436+
432437
(provide 'haskell-emacs)
433438

434439
;;; haskell-emacs.el ends here

0 commit comments

Comments
 (0)