branch: elpa/haskell-tng-mode commit 0d04664bd72c41c78bf378d201fc8b79e6d3784b Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
implement batch compilation --- haskell-tng-compile.el | 41 +++++++++++++++++++++++++++++++++++++++- haskell-tng-contrib.el | 33 ++++++++++++++++++++++++++++++++ haskell-tng-font-lock.el | 2 +- haskell-tng-util.el | 7 +++++++ test/haskell-tng-compile-test.el | 2 ++ 5 files changed, 83 insertions(+), 2 deletions(-) diff --git a/haskell-tng-compile.el b/haskell-tng-compile.el index 019729a..0aad467 100644 --- a/haskell-tng-compile.el +++ b/haskell-tng-compile.el @@ -13,16 +13,55 @@ (require 'compile) (require 'ansi-color) -;; FIXME implement batch compilation ;; TODO prettify-symbol rules for home dirs and project dirs, etc ;; TODO set compilation-directory when opening the file ;; TODO set compilation-environment to include TASTY envvars (defvar haskell-tng-compile-error-regexp-alist "The `compilation-error-regexp-alist' for `haskell-tng'." + ;; FIXME error-regexp-alist nil ) +(defvar haskell-tng-compile:history '("cabal v2-build -O0")) +(defvar-local haskell-tng-compile:command nil) +(defvar-local haskell-tng-compile:alt "cabal v2-clean") + +(defun haskell-tng-compile (&optional edit-command) + "`compile' specialised to Haskell: + +1. Runs the command from the cabal project directory. +2. ghc info, warning and error detection. + +First use in a buffer or calling with a prefix will prompt for a +command, otherwise the last command is used. + +The command history is global across all Haskell files. + +A universal argument will invoke `haskell-tng-compile:alt'." + (interactive "P") + (save-some-buffers (not compilation-ask-about-save) + compilation-save-buffers-predicate) + (let* ((last haskell-tng-compile:command) + (command (pcase edit-command + ((and 'nil (guard last)) last) + ('- haskell-tng-compile:alt) + (_ (read-shell-command + "Compile command: " + (or last (car haskell-tng-compile:history)) + '(haskell-tng-compile:history . 1)))))) + (setq-local haskell-tng-compile:command command) + + (when-let (default-directory + (haskell-tng:locate-dominating-file + (rx (| "cabal.project" "cabal.project.local" "cabal.project.freeze" + (: (+ any) ".cabal"))))) + (compilation-start + command + 'haskell-tng-compilation-mode + ;; TODO name the compilation buffer + )))) + (defun haskell-tng-compile:ansi-color () (ansi-color-apply-on-region compilation-filter-start (point-max))) diff --git a/haskell-tng-contrib.el b/haskell-tng-contrib.el new file mode 100644 index 0000000..db43386 --- /dev/null +++ b/haskell-tng-contrib.el @@ -0,0 +1,33 @@ +;;; haskell-tng-contrib.el --- Untested features -*- lexical-binding: t -*- + +;; Copyright (C) 2019 Tseen She +;; License: GPL 3 or any later version + +;;; Commentary: +;; +;; Untested / untestable commands that are either contributed by the community +;; or require an external process to exist on PATH. +;; +;;; Code: + +(require 'subr-x) + +;; TODO a generic wrapper around commands that can be downloaded and built using +;; cabal v2-install. + +(defun haskell-tng-contrib:stylish-haskell () + "Apply `stylish-haskell' rules." + (interactive) + (save-buffer) + (call-process "stylish-haskell" nil nil nil "-i" buffer-file-name) + (revert-buffer t t t)) + +(defun haskell-tng-contrib:stack2cabal () + "Prepare a stack project for use with cabal." + (interactive) + (when-let (default-directory + (locate-dominating-file default-directory "stack.yaml")) + (call-process "stack2cabal"))) + +(provide 'haskell-tng-contrib) +;;; haskell-tng-contrib.el ends here diff --git a/haskell-tng-font-lock.el b/haskell-tng-font-lock.el index 70b98b5..1732d3d 100644 --- a/haskell-tng-font-lock.el +++ b/haskell-tng-font-lock.el @@ -69,7 +69,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Here is the `font-lock-keywords' table of matchers and highlighters. -(defvar +(defconst haskell-tng:keywords ;; These regexps use the `rx' library so we can reuse common subpatterns. It ;; also increases the readability of the code and, in many cases, allows us to diff --git a/haskell-tng-util.el b/haskell-tng-util.el index 6c1e27e..aca9515 100644 --- a/haskell-tng-util.el +++ b/haskell-tng-util.el @@ -39,5 +39,12 @@ (forward-symbol -1) (haskell-tng:indent-close))) +(defun haskell-tng:locate-dominating-file (regexp) + "`locate-dominating-file' but starting from `default-directory' +and taking a regexp." + (locate-dominating-file + default-directory + (lambda (dir) (directory-files dir nil regexp)))) + (provide 'haskell-tng-util) ;;; haskell-tng-util.el ends here diff --git a/test/haskell-tng-compile-test.el b/test/haskell-tng-compile-test.el index 8f214cf..062c363 100644 --- a/test/haskell-tng-compile-test.el +++ b/test/haskell-tng-compile-test.el @@ -70,4 +70,6 @@ ;; fontified t (should (have-expected-errors (testdata "src/tasty-failure.compile")))) +;; TODO test invoking haskell-tng-compile in a real project directory + ;;; haskell-tng-compile-test.el ends here