Created
October 22, 2009 01:40
-
-
Save regularfry/215647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Some fairly nasty elisp for a very simple purpose: to set up a new clojure-project | |
;; and run clojure-project in it. For those of us who Know Not The Ways Of Maven. | |
(defun clojure-project-setup (path) | |
"Set up a project structure for clojure-project and copy any | |
interesting-looking jars into lib/." | |
(interactive (list | |
(ido-read-directory-name | |
"Project root: " | |
(locate-dominating-file default-directory "~")))) | |
(if (not (file-directory-p path)) | |
(let | |
((subpaths '("" "lib" "src" "test" "target/classes" "target/dependency"))) | |
(dolist (subpath subpaths) | |
(make-directory (file-join path subpath) t)) | |
(copy-fun-jars-to-project clojure-src-root path) | |
(clojure-project path)) | |
(error "The directory %s already exists. I won't overwrite it." path))) | |
;; Internals | |
(defun copy-fun-jars-to-project (src-root dest-root) | |
"Copy important jars from the src-root into the new project." | |
(if (file-directory-p path) | |
(dolist (jar (find-fun-jars src-root)) | |
(copy-file jar (file-join dest-root "lib"))) | |
(error "The directory %s doesn't exist, so can't be a clojure project." dest-root))) | |
(defun find-fun-jars (src-root) | |
"Return a list of filenames of important jar files. Currently looks | |
for jars of the form src-root/foo/foo.jar; that is, named the same | |
as the folder they're in. This seems to be a convention." | |
(let* ((directories (select | |
(lambda (d) (file-directory-p (file-join src-root d))) | |
(directory-files src-root nil "^[^\.].*$"))) | |
(maybe-jars (mapcar | |
(lambda (d) (file-join src-root d (concat d ".jar"))) | |
directories))) | |
(select (lambda (j) (file-exists-p j)) maybe-jars))) | |
;; Utils | |
(defun file-join (&rest path-parts) | |
(defun file-join-rec (cur rest) | |
(if rest | |
(file-join-rec (concat (file-name-as-directory (car rest)) cur) (cdr rest)) | |
cur)) | |
(let ((rpath (reverse path-parts))) | |
(file-join-rec (car rpath) (cdr rpath)))) | |
(defun select (fun lst) | |
(defun select-recur (running fun lst) | |
(if lst | |
(let ((fst (car lst)) | |
(rest (cdr lst))) | |
(let ((new-running (if (apply fun (list fst)) | |
(cons fst running) | |
running))) | |
(select-recur new-running fun rest))) | |
running)) | |
(reverse (select-recur () fun lst))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment