redgreen-at-project-root.el 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. (defun redgreen-at-project-root ()
  2. (interactive)
  3. (let ((root (napr/find-project-root)))
  4. (let ((compilation-scroll-output t)
  5. (compilation-window-height 30)
  6. )
  7. (compile (format "cd %s && %s -t \"%s\" -- --with-snort -w tests -x --nologcapture" root (get-redgreen-executable) (get-nosetests-executable)) t)
  8. )
  9. )
  10. )
  11. (defun get-nosetests-executable ()
  12. (get-python-utility "nosetests"))
  13. (defun get-redgreen-executable ()
  14. (get-python-utility "redgreen"))
  15. (defun get-python-utility (name)
  16. (let ((dir (file-name-directory python-shell-interpreter)))
  17. (if dir
  18. (concat dir name)
  19. name
  20. )))
  21. (defun napr/find-project-root (&optional root)
  22. "Determines the current project root by recursively searching for an indicator."
  23. (when (null root) (setq root default-directory))
  24. (cond
  25. ((napr/root-matches root (list ".git" ".hg" ".bzr"))
  26. (expand-file-name root))
  27. ((equal (expand-file-name root) "/") nil)
  28. (t (napr/find-project-root (concat (file-name-as-directory root) "..")))))
  29. (defun napr/root-match(root names)
  30. (member (car names) (directory-files root)))
  31. (defun napr/root-matches(root names)
  32. (if (napr/root-match root names)
  33. (napr/root-match root names)
  34. (if (eq (length (cdr names)) 0)
  35. 'nil
  36. (napr/root-matches root (cdr names))
  37. )))
  38. (provide 'redgreen-at-project-root)