Skip to content
This repository
Browse code

Make swank-clojure work under clojure 1.5.0.

The constructor for clojure.lang.Compiler$CompilerException takes an
additional column argument under 1.5.0. This patch handles the
different arities, and always sets the column to 0 under 1.5.0.
  • Loading branch information...
commit 12e96d0cc3a0e6ff940cccb1e5c133e9874e698e 1 parent dcb380a
Toby Crawley authored November 29, 2012
11  src/swank/commands/basic.clj
@@ -119,7 +119,7 @@
119 119
 
120 120
 ;;;; Compiler / Execution
121 121
 
122  
-(def compiler-exception-location-re #"Exception:.*\(([^:]+):([0-9]+)\)")
  122
+(def compiler-exception-location-re #"Exception:.*\(([^:]+):([0-9]+)(:[0-9]+)?\)")
123 123
 (defn- guess-compiler-exception-location [#^Throwable t]
124 124
   (when (instance? clojure.lang.Compiler$CompilerException t)
125 125
     (let [[match file line] (re-find compiler-exception-location-re (str t))]
@@ -196,12 +196,19 @@
196 196
       (.getLineNumber f))
197 197
     (catch Exception e 1)))
198 198
 
  199
+(defmacro compiler-exception [directory line ex]
  200
+  `(eval (if (>= (:minor *clojure-version*) 5)
  201
+           '(clojure.lang.Compiler$CompilerException.
  202
+             ~directory ~line 0 ~ex)
  203
+           '(clojure.lang.Compiler$CompilerException.
  204
+             ~directory ~line ~ex))))
  205
+
199 206
 (defslimefn compile-string-for-emacs [string buffer position directory debug]
200 207
   (let [start (System/nanoTime)
201 208
         line (line-at-position directory position)
202 209
         ret (with-emacs-package
203 210
               (when-not (= (name (ns-name *ns*)) *current-package*)
204  
-                (throw (clojure.lang.Compiler$CompilerException.
  211
+                (throw (compiler-exception
205 212
                         directory line
206 213
                         (Exception. (str "No such namespace: "
207 214
                                          *current-package*)))))
4  test/swank/test_swank/commands/basic.clj
@@ -22,9 +22,9 @@ list, Alan Dipert and MeikelBrandmeyer."
22 22
   (deftest guess-compiler-exception-location-test
23 23
     (is (= '(:location (:file "a.clj") (:line 1) nil)
24 24
            (guess-compiler-exception-location
25  
-            (clojure.lang.Compiler$CompilerException. "a.clj" 1 (Exception. "err"))))))
  25
+                        (compiler-exception "a.clj" 1 (Exception. "err"))))))
26 26
 
27 27
   (deftest exception-location-test
28 28
     (is (= '(:location (:file "a.clj") (:line 1) nil)
29 29
            (exception-location
30  
-            (clojure.lang.Compiler$CompilerException. "a.clj" 1 (Exception. "err")))))))
  30
+            (compiler-exception "a.clj" 1 (Exception. "err")))))))

0 notes on commit 12e96d0

Please sign in to comment.
Something went wrong with that request. Please try again.