From 27b1a74d074a6a0cbf1b7b7376b38127ee2471e9 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Fri, 15 Jun 2018 14:25:17 -0400 Subject: [PATCH] Support Haskell test toggling Toggle between Haskell modules and test files. --- emacs.d/wpc/packages/wpc-haskell.el | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/emacs.d/wpc/packages/wpc-haskell.el b/emacs.d/wpc/packages/wpc-haskell.el index a37a84030..5be444e51 100644 --- a/emacs.d/wpc/packages/wpc-haskell.el +++ b/emacs.d/wpc/packages/wpc-haskell.el @@ -28,5 +28,30 @@ (dolist (item m-symbols) (add-to-list 'haskell-font-lock-symbols-alist item))) (setq haskell-font-lock-symbols t)) +(defun empire/haskell/module->test () + "Jump from a module to a test." + (let ((filename (->> buffer-file-name + (s-replace "/src/" "/test/") + (s-replace ".hs" "Test.hs") + find-file))) + (make-directory (f-dirname filename) t) + (find-file filename))) + +(defun empire/haskell/test->module () + "Jump from a test to a module." + (let ((filename (->> buffer-file-name + (s-replace "/test/" "/src/") + (s-replace "Test.hs" ".hs") + ))) + (make-directory (f-dirname filename) t) + (find-file filename))) + +(defun empire/haskell/test<->module () + "Toggle between test and module in Haskell." + (interactive) + (if (s-contains? "/src/" buffer-file-name) + (empire/haskell/module->test) + (empire/haskell/test->module))) + (provide 'wpc-haskell) ;;; haskell.el ends here