clj-defuns.el 930 B

12345678910111213141516171819202122232425262728293031323334
  1. (require 's)
  2. (defun clj--src-file-name-from-test (name)
  3. (s-with name
  4. (s-replace "/test/" "/src/")
  5. (s-replace "_test.clj" ".clj")))
  6. (defun clj--test-file-name-from-src (name)
  7. (s-with name
  8. (s-replace "/src/" "/test/")
  9. (s-replace ".clj" "_test.clj")))
  10. (defun clj-other-file-name ()
  11. (let ((name (buffer-file-name)))
  12. (if (string-match-p "/test/" name)
  13. (clj--src-file-name-from-test name)
  14. (clj--test-file-name-from-src name))))
  15. (defun clj-jump-to-other-file (arg)
  16. (interactive "P")
  17. (let ((file (clj-other-file-name)))
  18. (cond
  19. ((file-exists-p file) (find-file file))
  20. (arg (find-file file)
  21. (save-buffer))
  22. (t (error "%s not found." file)))))
  23. (defun clj-jump-to-other-file-other-window (arg)
  24. (interactive "P")
  25. (let ((file (clj-other-file-name)))
  26. (if (or (file-exists-p file) arg)
  27. (find-file-other-window file)
  28. (error "%s not found." file))))