Permalink
Browse files

inferior-lisp/lein repl thingies

  • Loading branch information...
1 parent 353f7ab commit 0305d644f34304e4dfb462e9d4f7cc472a6750f9 @alandipert committed Sep 10, 2011
Showing with 38 additions and 5 deletions.
  1. +38 −5 init.el
View
43 init.el
@@ -2,15 +2,21 @@
;; path
;;
+(defcustom exec-paths '("/usr/local/bin" "~/.local/bin")
+ "Directories to be added to exec-path"
+ :type 'string)
+
(defun add-to-path (dir)
"Adds a dir to PATH if dir exists."
(when (file-exists-p dir)
- (progn (push dir exec-path)
+ (progn (add-to-list 'exec-path dir)
(setenv "PATH" (concat (getenv "PATH") (concat ":" dir))))))
-(dolist (dir '("/usr/local/bin"
- "~/.local/bin"))
- (add-to-path dir))
+(defun initialize-exec-path ()
+ (interactive)
+ (dolist (dir exec-paths) (add-to-path dir)))
+
+(initialize-exec-path)
;;
;; init el-get, installing if necessary
@@ -331,11 +337,38 @@ Goes backward if ARG is negative; error if CHAR not found."
(let ((clj-jar (concat clj-dir "/clojure.jar")))
(if (file-exists-p clj-jar)
(inferior-lisp (concat "java -cp " clj-jar " clojure.main"))
- (when (yes-or-no-p (concat "clojure.jar not found. Build?"))
+ (when (yes-or-no-p "clojure.jar not found. Build?")
(if (shell-command (concat "cd " clj-dir " && ant"))
(cljrepl)
(message "Building Clojure failed."))))))
+(defun leinrepl ()
+ "Launch a Leiningen REPL for current file's project. Runs only
+ if lib exists. Requires cl."
+ (interactive)
+ (if (not (executable-find "lein"))
+ (message "lein command not found.")
+ (labels ((locate-project (file name)
+ ;; adapted from https://github.com/technomancy/emacs-starter-kit/blob/master/dominating-file.el
+ (let* ((file (abbreviate-file-name file))
+ (stop-dir-regexp "\\`\\(?:[\\/][\\/][^\\/]+\\|/\\(?:net\\|afs\\|\\.\\.\\.\\)/\\)\\'")
+ (root nil)
+ (prev-file file)
+ try)
+ (while (not (or root
+ (null file)
+ (string-match stop-dir-regexp file)))
+ (setq try (file-exists-p (expand-file-name name file)))
+ (cond (try (setq root file))
+ ((equal file (setq prev-file file
+ file (file-name-directory
+ (directory-file-name file))))
+ (setq file nil))))
+ root)))
+ (let ((project-dir (locate-project buffer-file-name "project.clj")))
+ (if (file-exists-p (concat project-dir "lib"))
+ (inferior-lisp "lein repl")
+ (message "lib directory not found. Have you run lein deps?"))))))
;;
;; change font size
;;

0 comments on commit 0305d64

Please sign in to comment.