Skip to content

Instantly share code, notes, and snippets.

@mikedmcfarland mikedmcfarland/js.el
Last active Aug 15, 2016

Embed
What would you like to do?
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

This comment has been minimized.

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
You can’t perform that action at this time.