Permalink
Browse files

Spin off lein-swank back into its own plugin.

  • Loading branch information...
1 parent 9063d9f commit 5da066803c4abf48e31ebd62d3d72ca58e4041f6 @technomancy committed Jan 31, 2012
View
@@ -1,7 +1,7 @@
classes/
lib/
multi-lib/
-swank-clojure*jar
+*jar
pom.xml
-/.lein-failures
-/.lein-deps-sum
+.lein-failures
+.lein-deps-sum
View
@@ -0,0 +1,19 @@
+# lein-swank
+
+Leiningen plugin for launching a swank server.
+
+## Usage
+
+From version 1.7.0 on, Leiningen uses a separate list for plugins
+rather than `:dev-dependencies`. If you are using Leiningen 1.6 or
+earlier, continue adding the main `swank-clojure` entry into your
+`:dev-dependencies`.
+
+Add `[lein-swank "1.4.0"]` to `:plugins` in `project.clj`.
+Then you should have access to the `swank` and `jack-in` tasks.
+
+## License
+
+Copyright © 2012 Phil Hagelberg
+
+Distributed under the Eclipse Public License, the same as Clojure.
View
@@ -0,0 +1,3 @@
+(defproject lein-swank "1.4.0"
+ :description "A Leiningen plugin for launching a Swank server for Slime."
+ :eval-in-leiningen true)
@@ -1,14 +1,13 @@
(ns leiningen.jack-in
- (:use [leiningen.compile :only [eval-in-project]]
- [leiningen.swank :only [swank]])
(:require [clojure.java.io :as io]
- [clojure.string :as string])
- (:import (java.util.jar JarFile)
- (java.security MessageDigest)))
+ [clojure.string :as string]
+ [leiningen.swank :as swank])
+ (:import (java.security MessageDigest)))
-(def payloads-file-name "swank_elisp_payloads.clj")
+(def ^:private payloads-file-name "swank_elisp_payloads.clj")
(defn elisp-payload-files []
+ ;; TODO: this may not work with lein2 plugins
(->> (.getResources (.getContextClassLoader (Thread/currentThread))
payloads-file-name)
(enumeration-seq)
@@ -37,31 +36,24 @@
(io/copy r elisp-file))
(with-open [w (io/writer elisp-file :append true)]
(.write w (format "\n(provide '%s-%s)\n" feature checksum))))
- (format "
-
-(when (not (or (featurep '%s-%s) (file-remote-p default-directory)))
- (if (file-readable-p \"%s\")
- (load-file \"%s\")
- (byte-compile-file \"%s\" t)))"
+ (format "(when (not (featurep '%s-%s))
+ (if (file-readable-p \"%s\")
+ (load-file \"%s\")
+ (byte-compile-file \"%s\" t)))"
feature checksum bytecode bytecode elisp)))
-(defn payload-loaders []
- (for [file (elisp-payload-files)]
- (loader file)))
-
(defn jack-in
"Jack in to a Clojure SLIME session from Emacs.
This task is intended to be launched from Emacs using M-x clojure-jack-in,
which is part of the clojure-mode library."
- ([project port] (jack-in project port "localhost"))
- ([project port hostname]
- (println ";;; Bootstrapping bundled version of SLIME; please wait...\n\n")
- (let [loaders (string/join "\n" (payload-loaders))
- colors? (.contains loaders "slime-frame-colors")]
- (println loaders)
- (println "(sleep-for 0.1)") ; TODO: remove
- (println "(run-hooks 'slime-load-hook) ; on port" port)
- (println ";;; Done bootstrapping.")
- (swank project port hostname ":colors?" (str colors?)
- ":message" "\";;; proceed to jack in\""))))
+ [project port]
+ (println ";;; Bootstrapping bundled version of SLIME; please wait...\n\n")
+ (let [loaders (string/join "\n" (map loader (elisp-payload-files)))
+ colors? (.contains loaders "slime-frame-colors")]
+ (println loaders)
+ (println "(sleep-for 0.1)") ; TODO: remove
+ (println "(run-hooks 'slime-load-hook) ; on port" port)
+ (println ";;; Done bootstrapping.")
+ (swank/swank project port "localhost" ":colors?" (str colors?)
+ ":message" "\";;; proceed to jack in\"")))
@@ -1,7 +1,6 @@
(ns leiningen.swank
"Launch swank server for Emacs to connect."
- (:require [clojure.java.io :as io])
- (:use [leiningen.compile :only [eval-in-project]]))
+ (:require [clojure.java.io :as io]))
(defn swank-form [project port host opts]
;; bootclasspath workaround: http://dev.clojure.org/jira/browse/CLJ-673
@@ -42,10 +41,21 @@
add-cdt-jvm-opts))
project))
+(defn eval-in-project
+ "Support eval-in-project in both Leiningen 1.x and 2.x."
+ [& args]
+ (let [eip (try (require 'leiningen.compile)
+ (resolve 'leiningen.compile/eval-in-project)
+ (catch java.io.FileNotFoundException _
+ (require 'leiningen.core.eval)
+ (resolve 'leiningen.core.eval/eval-in-project)))]
+ (apply eip args)))
+
(defn swank
"Launch swank server for Emacs to connect. Optionally takes PORT and HOST."
([project port host & opts]
- (eval-in-project (add-cdt-project-args project)
+ (eval-in-project (update-in (add-cdt-project-args project)
+ [:dependencies] conj ['swank-clojure "1.4.0"])
(swank-form project port host opts)))
([project port] (swank project port "localhost"))
([project] (swank project 4005)))

0 comments on commit 5da0668

Please sign in to comment.