about summary refs log tree commit diff
path: root/emacs.d/wpc/packages
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2018-06-15T18·25-0400
committerWilliam Carroll <wpcarro@gmail.com>2018-07-19T16·00-0400
commit27b1a74d074a6a0cbf1b7b7376b38127ee2471e9 (patch)
tree4ffd84dd68358350243cc4a6f8e6d93be369afcc /emacs.d/wpc/packages
parent30cdf1e94183dd2ca761e2283dea7c756eb814c5 (diff)
Support Haskell test toggling
Toggle between Haskell modules and test files.
Diffstat (limited to 'emacs.d/wpc/packages')
-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