Skip to content

Instantly share code, notes, and snippets.

@mikedmcfarland
Last active August 15, 2016 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikedmcfarland/ea661781d7028e9a2e22 to your computer and use it in GitHub Desktop.
Save mikedmcfarland/ea661781d7028e9a2e22 to your computer and use it in GitHub Desktop.
js toggle implementation
(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"))
)))
@fhdhsni
Copy link

fhdhsni commented Aug 15, 2016

├── src
│   └── js
│       └── foo.js
└── test
      └── foo_test.js

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment