Skip to content

Instantly share code, notes, and snippets.

@iquiw
Last active August 29, 2015 14:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iquiw/3905d5a51347b82a9369 to your computer and use it in GitHub Desktop.
Save iquiw/3905d5a51347b82a9369 to your computer and use it in GitHub Desktop.
ghc-modi flycheck checkers
(require 'flycheck)
(setq-default flycheck-disabled-checkers '(haskell-ghc haskell-lint))
(defconst ghc-check-regexp
"^\\([^\n]*\\):\\([0-9]+\\):\\([0-9]+\\):\\(Warning:\\)? *\\([^\t]+\\)")
(defun ghc-flycheck-start (cmd checker callback)
(let ((errs (ghc-sync-process
(format "%s %s\n" cmd
(car (flycheck-substitute-argument 'source-original checker))))))
(let (result)
(dolist (err errs)
(when (string-match ghc-check-regexp err)
(setq result
(nconc result
(list (flycheck-error-new-at
(string-to-number (match-string 2 err))
(string-to-number (match-string 3 err))
(if (match-string 4 err) 'warning 'error)
(match-string 5 err)))))))
(funcall callback 'finished result))))
(defun ghc-flycheck-start-check (checker callback)
(ghc-flycheck-start "check" checker callback))
(defun ghc-flycheck-start-lint (checker callback)
(ghc-flycheck-start "lint" checker callback))
(flycheck-define-generic-checker 'haskell-ghc-modi-check
"A Haskell syntax and type checker using ghc-modi."
:start #'ghc-flycheck-start-check
:error-filter
(lambda (errors)
(flycheck-sanitize-errors (flycheck-dedent-error-messages errors)))
:modes '(haskell-mode literate-haskell-mode)
:next-checkers '((warning . haskell-ghc-modi-lint)))
(flycheck-define-generic-checker 'haskell-ghc-modi-lint
"A Haskell linter using ghc-modi."
:start #'ghc-flycheck-start-lint
:error-filter
(lambda (errors)
(flycheck-sanitize-errors (flycheck-dedent-error-messages errors)))
:modes '(haskell-mode literate-haskell-mode))
(add-to-list 'flycheck-checkers 'haskell-ghc-modi-lint)
(add-to-list 'flycheck-checkers 'haskell-ghc-modi-check)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment