Last active
August 15, 2016 19:00
-
-
Save mikedmcfarland/ea661781d7028e9a2e22 to your computer and use it in GitHub Desktop.
js toggle implementation
This file contains 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
(defun js-jump-to (current from to format-name) | |
(find-file | |
(cl-loop with parts = (reverse current) | |
with fname = (file-name-sans-extension (cl-first parts)) | |
for (name . rest) on (cl-rest parts) | |
until (string-equal name from) | |
collect name into names | |
finally (cl-return | |
(mapconcat 'identity | |
(nconc (reverse rest) | |
(list to) | |
(reverse names) | |
(list (funcall format-name fname) )) "/" ))))) | |
(defun js-format-impl-name (fname) | |
(format "%s.js" (replace-regexp-in-string "Spec" "" fname))) | |
(defun js-format-test-name (fname) | |
(format "%sSpec.js" fname)) | |
(defun js-jump-to-implementation-or-test () | |
(interactive) | |
(let ((current (split-string (buffer-file-name) "/"))) | |
(cond | |
((member "test" current) (js-jump-to current "test" "lib" 'js-format-impl-name)) | |
((member "lib" current) (js-jump-to current "lib" "test" 'js-format-test-name)) | |
(t (error "not within a test or lib directory")) | |
))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Mike. As you can see my project tree is different. Could you please help me to make this work for me? I don't know lisp. Thank you