about summary refs log tree commit diff
path: root/emacs.d/wpc/packages/wpc-haskell.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs.d/wpc/packages/wpc-haskell.el')
-rw-r--r--emacs.d/wpc/packages/wpc-haskell.el25
1 files changed, 25 insertions, 0 deletions
diff --git a/emacs.d/wpc/packages/wpc-haskell.el b/emacs.d/wpc/packages/wpc-haskell.el
index a37a84030f14..5be444e51158 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