33 [leiningen.swank :only [swank]])
44 (:require [clojure.java.io :as io]
55 [clojure.string :as string])
6- (:import (java.util.jar JarFile)))
6+ (:import (java.util.jar JarFile)
7+ (java.security MessageDigest)))
78
89(defn- get-manifest [file]
910 (let [attrs (-> file JarFile. .getManifest .getMainAttributes)]
2122 (filter #(jar-file? (.getName (:file %))))
2223 (get-payloads ))))
2324
24- (defn payloads []
25+ (defn hex-digest [file]
26+ (format " %x" (BigInteger. 1 (.digest (MessageDigest/getInstance " SHA1" )
27+ (-> file io/resource slurp .getBytes)))))
28+
29+ (defn loader [file]
30+ (let [feature (second (re-find #".*/(.*?).el$" file))
31+ checksum (subs (hex-digest file) 0 8 )
32+ user-file (format " %s/.emacs.d/swank/%s-%s.elc"
33+ (System/getProperty " user.home" )
34+ feature checksum)]
35+ (.mkdirs (.getParentFile (io/file user-file)))
36+ (io/copy (io/file (.getFile (io/resource file))) (io/file user-file))
37+ (with-open [w (io/writer user-file :append true )]
38+ (.write w (format " \n (provide '%s-%s)\n " feature checksum)))
39+ (format " (when (not (featurep '%s-%s))
40+ (if (file-readable-p \" %s\" )
41+ (load-file \" %s\" )
42+ (byte-compile-file \" %s\" t)))"
43+ feature checksum user-file user-file user-file)))
44+
45+ (defn payload-loaders []
2546 (for [file (elisp-payload-files )]
26- (slurp ( io/resource file) )))
47+ (loader file)))
2748
2849(defn jack-in
2950 " Jack in to a Clojure SLIME session from Emacs.
@@ -32,6 +53,6 @@ This task is intended to be launched from Emacs using M-x clojure-jack-in,
3253which is part of the clojure-mode library."
3354 [project port]
3455 (println " ;;; Bootstrapping bundled version of SLIME; please wait...\n\n " )
35- (println (string/join " \n " (payloads )))
56+ (println (string/join " \n " (payload-loaders )))
3657 (println " (run-hooks 'slime-load-hook)" )
3758 (swank project port " localhost" " :message" " \" ;;; proceed to jack in\" " ))
0 commit comments