Created
April 19, 2016 16:42
-
-
Save timcharper/e5550105a2d18c53249b5b6340c7801d to your computer and use it in GitHub Desktop.
the functions are specific for scala... but this is general enough to work for anything
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defvar scala-test:main-file-format | |
"%s/src/main/scala/%s%s.scala" | |
"scala test format") | |
(defvar scala-test:test-file-format | |
"%s/src/test/scala/%s%sSpec.scala" | |
"scala test format") | |
;; (setq scala-test:main-file-format "%s/src/main/scala/%s%s.scala") | |
;; (setq scala-test:test-file-format "%s/src/test/scala/%sTest%s.scala") | |
(defun scala-test:format-to-regex (fmt) | |
(format | |
(replace-regexp-in-string "\\." "\\\\." fmt) | |
"\\(.+\\)" "\\(.+/\\)?" "\\([^/]+\\)")) | |
(defun scala-test:toggle-spec-test () | |
"Toggle between test and spec" | |
(interactive) | |
(let* ((path buffer-file-name) | |
(main-regex (scala-test:format-to-regex scala-test:main-file-format)) | |
(spec-regex (scala-test:format-to-regex scala-test:test-file-format)) | |
(other-path | |
(cond ((string-match spec-regex path) | |
(format scala-test:main-file-format | |
(match-string 1 path) | |
(match-string 2 path) | |
(match-string 3 path))) | |
((string-match main-regex path) | |
(format scala-test:test-file-format | |
(match-string 1 path) | |
(match-string 2 path) | |
(match-string 3 path)))))) | |
(message "%s" other-path) | |
(find-file other-path))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment