@@ -410,33 +410,52 @@ imports."
410
410
" The path which is considered as project root, this is determined by the
411
411
presence of a *.cabal file or stack.yaml file or something similar." )
412
412
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
+
413
431
(defun haskell-build-type ()
414
432
" Looks for cabal and stack spec files.
415
433
When found, returns a pair (TAG . DIR)
416
434
where TAG is \\= 'cabal-project, \\= 'cabal-sandbox. \\= 'cabal, or \\= 'stack;
417
435
and DIR is the directory containing cabal or stack file.
418
436
When none found, DIR is nil, and TAG is \\= 'ghc"
419
437
; ; 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. " ))))))
440
459
441
460
(defun haskell-process-type ()
442
461
" Return `haskell-process-type' , or a guess if that variable is \\= 'auto.
0 commit comments