Skip to content

Instantly share code, notes, and snippets.

@rpglover64
Created March 14, 2015 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpglover64/30bb21d04605ed0feb61 to your computer and use it in GitHub Desktop.
Save rpglover64/30bb21d04605ed0feb61 to your computer and use it in GitHub Desktop.
diff --git a/flycheck-haskell.el b/flycheck-haskell.el
index a51b879..d263e1e 100644
--- a/flycheck-haskell.el
+++ b/flycheck-haskell.el
@@ -143,6 +143,9 @@ Return the configuration."
(or (flycheck-haskell-get-cached-configuration cabal-file)
(flycheck-haskell-read-and-cache-configuration cabal-file)))
+(defconst flycheck-haskell-cabal-config "cabal.config"
+ "The file name of a Cabal configuration.")
+
(defconst flycheck-haskell-sandbox-config "cabal.sandbox.config"
"The file name of a Cabal sandbox configuration.")
@@ -164,6 +167,33 @@ database was not found."
(when (re-search-forward flycheck-haskell-package-db-re nil 'noerror)
(match-string 1))))
+(defconst flycheck-haskell-compiler-re
+ (rx line-start (zero-or-more (any space)) "with-compiler:"
+ (zero-or-more (any space))
+ (group (one-or-more (not (any space))))
+ (zero-or-more (any space) line-end))
+ "Regular expression to parse the compiler path.")
+
+(defun flycheck-haskell-get-compiler (cabal-config)
+ "Get the compiler path from CABAL-CONFIG.
+
+Return the compiler path as string, or nil, if the database was
+not found."
+ (with-temp-buffer
+ (insert-file-contents cabal-config)
+ (goto-char (point-min))
+ (when (re-search-forward flycheck-haskell-compiler-re nil 'noerror)
+ (match-string 1))))
+
+(defun flycheck-haskell-find-cabal-config ()
+ "Find Cabal configuration for the current buffer.
+
+Return the absolute path of the configuration file as
+string, or nil, if no sandbox configuration file was found."
+ (-when-let (root-dir (locate-dominating-file (buffer-file-name)
+ flycheck-haskell-cabal-config))
+ (expand-file-name flycheck-haskell-sandbox-config root-dir)))
+
(defun flycheck-haskell-find-sandbox-config ()
"Find Cabal sandbox configuration for the current buffer.
@@ -191,6 +221,10 @@ string, or nil, if no sandbox configuration file was found."
(config (flycheck-haskell-get-configuration cabal-file)))
(flycheck-haskell-process-configuration config))
+ (-when-let* ((config (flycheck-haskell-find-cabal-config))
+ (compiler (flycheck-haskell-get-compiler config)))
+ (setq-local flycheck-haskell-ghc-executable compiler))
+
(-when-let* ((config (flycheck-haskell-find-sandbox-config))
(package-db (flycheck-haskell-get-package-db config)))
(setq-local flycheck-ghc-package-databases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment