Skip to content

Commit c86e80c

Browse files
author
webdevred
committed
use projectile to choose haskell-build-type if possible
1 parent 2ada981 commit c86e80c

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

haskell-customize.el

+39-20
Original file line numberDiff line numberDiff line change
@@ -410,33 +410,52 @@ imports."
410410
"The path which is considered as project root, this is determined by the
411411
presence of a *.cabal file or stack.yaml file or something similar.")
412412

413+
(defun haskell-projectile-build-type ()
414+
(if (and (fboundp 'projectile-project-root) (bound-and-true-p projectile-mode))
415+
(let* ((d (projectile-project-root))
416+
(cabal (cl-find-if
417+
(lambda (f) (string-match-p ".\\.cabal\\'" f))
418+
(directory-files d))))
419+
(cond
420+
((and (file-exists-p (concat d "cabal.project")) (executable-find "cabal"))
421+
(cons 'cabal-project d))
422+
((and (file-exists-p (concat d "cabal.sandbox")) (executable-find "cabal"))
423+
(cons 'cabal-sandbox d))
424+
((and (file-exists-p (concat d "stack.yaml")) (executable-find "stack"))
425+
(cons 'stack d))
426+
((and cabal (file-exists-p (concat d cabal)) (executable-find "cabal"))
427+
(cons 'cabal d))
428+
((executable-find "ghc") (cons 'ghc nil))))
429+
nil))
430+
413431
(defun haskell-build-type ()
414432
"Looks for cabal and stack spec files.
415433
When found, returns a pair (TAG . DIR)
416434
where TAG is \\='cabal-project, \\='cabal-sandbox. \\='cabal, or \\='stack;
417435
and DIR is the directory containing cabal or stack file.
418436
When none found, DIR is nil, and TAG is \\='ghc"
419437
;; REVIEW maybe just 'cabal is enough.
420-
(let ((cabal-project (locate-dominating-file default-directory "cabal.project"))
421-
(cabal-sandbox (locate-dominating-file default-directory "cabal.sandbox.config"))
422-
(stack (locate-dominating-file default-directory "stack.yaml"))
423-
(cabal (locate-dominating-file
424-
default-directory
425-
(lambda (d)
426-
(cl-find-if
427-
(lambda (f) (string-match-p ".\\.cabal\\'" f))
428-
(directory-files d))))))
429-
(cond
430-
((and cabal-project (executable-find "cabal"))
431-
(cons 'cabal-project cabal-project))
432-
((and cabal-sandbox (executable-find "cabal"))
433-
(cons 'cabal-sandbox cabal-sandbox))
434-
((and stack (executable-find "stack"))
435-
(cons 'stack stack))
436-
((and cabal (executable-find "cabal"))
437-
(cons 'cabal cabal))
438-
((executable-find "ghc") (cons 'ghc nil))
439-
(t (error "Could not find any installation of GHC.")))))
438+
(or (haskell-projectile-build-type)
439+
(let ((cabal-project (locate-dominating-file default-directory "cabal.project"))
440+
(cabal-sandbox (locate-dominating-file default-directory "cabal.sandbox.config"))
441+
(stack (locate-dominating-file default-directory "stack.yaml"))
442+
(cabal (locate-dominating-file
443+
default-directory
444+
(lambda (d)
445+
(cl-find-if
446+
(lambda (f) (string-match-p ".\\.cabal\\'" f))
447+
(directory-files d))))))
448+
(cond
449+
((and cabal-project (executable-find "cabal"))
450+
(cons 'cabal-project cabal-project))
451+
((and cabal-sandbox (executable-find "cabal"))
452+
(cons 'cabal-sandbox cabal-sandbox))
453+
((and stack (executable-find "stack"))
454+
(cons 'stack stack))
455+
((and cabal (executable-find "cabal"))
456+
(cons 'cabal cabal))
457+
((executable-find "ghc") (cons 'ghc nil))
458+
(t (error "Could not find any installation of GHC."))))))
440459

441460
(defun haskell-process-type ()
442461
"Return `haskell-process-type', or a guess if that variable is \\='auto.

0 commit comments

Comments
 (0)