Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
80 lines (68 sloc) 3.02 KB
(require 'tools)
(defvar *default-compilation-file* "Makefile")
"I use it like this"
(global-set-key [(f9)] 'smart-compile)
(eval-after-load "compile"
[remap compile-goto-error]
(defun smart-compile ()
"Saves current buffer, and depending on context:
- in an Elisp file, runs elk tests.
- in a Clojure file, runs clojure-test-run-tests.
- if the compile command contains \"make\", and a makefile is
found in the current directory or upward, runs the compile
- otherwise, switches to rake for the current buffer and
(labels ((run-elisp-tests ()
(when (fboundp 'elk-test-run-all-buffers)
(elk-test-run-all-buffers t)))
(run-clojure-tests ()
(cond ((slime-connected-p)
(unless (symbol-value 'clojure-test-mode)
(-?>> (buffer-file-name)
(replace-regexp-in-string "\\.clj$" "_test.clj")
(replace-regexp-in-string "/src/" "/test/")
(with-current-buffer "*slime-repl clojure*"
(t (when (y-or-n-p "Slime is not connected, open a terminal?")
(shell-command "cygterm&")))))
(make-or-rake ()
(let ((compilation-file (nearest-compilation-file default-directory)))
(when (and (not (string-match "rake" compile-command))
(null compilation-file))
(message "No Makefile found, switching to rake")
(set (make-local-variable 'compile-command) "rake"))
(let ((default-directory (if compilation-file
(file-name-directory compilation-file)
(compile compile-command)))))
(cond (eldoc-mode (run-elisp-tests))
((eq major-mode 'clojure-mode) (run-clojure-tests))
(t (make-or-rake)))))
(defun nearest-compilation-file (dir)
"Search for the compilation file traversing up the directory tree."
(let ((file-path (concat dir *default-compilation-file*))
(parent (file-name-directory (directory-file-name dir))))
((file-exists-p file-path) file-path)
((string= dir parent) nil)
(t (nearest-compilation-file parent)))))
(defun compile-goto-error-and-close-compilation-window ()
"Useful to close compilation windows, so you have only one
window open at any time (I set `pop-up-windows' to nil)."
(delete-windows-on "*compilation*"))
(provide 'smart-compile)