Skip to content

Instantly share code, notes, and snippets.

@tobias
Last active August 29, 2015 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobias/10182549 to your computer and use it in GitHub Desktop.
Save tobias/10182549 to your computer and use it in GitHub Desktop.
(require 'compile)
(defun locate-all-dominating-files (dir filename)
"Searches for FILENAME in DIR and its parents, returning a list
of all dirs containing the file."
(let ((found-dir (locate-dominating-file (expand-file-name dir) filename)))
(if found-dir
(cons found-dir (locate-all-dominating-files
(concat found-dir "..")
filename)))))
(defvar lein-history nil)
(defun lein ()
"Searches up the path for all project.clj's, asks at what level
to run the command (if more than one are found), then asks for a
lein command."
(interactive)
(let* ((dirs (locate-all-dominating-files default-directory "project.clj"))
(dir (case (length dirs)
(0 nil)
(1 (first dirs))
(t (ido-completing-read "Project? " dirs)))))
(if dir
(compile (concat (format "cd %s;lein " dir)
(read-from-minibuffer "Lein task: " "install"
nil nil 'lein-history)))
(message "No project.clj found"))))
(define-key clojure-mode-map (kbd "C-c l") 'lein)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment