Skip to content
This repository has been archived by the owner on Jan 23, 2018. It is now read-only.

Commit

Permalink
Fixed compile-string for emacs to use the passed file and line number
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoduncan committed Mar 30, 2010
1 parent 3f25f3e commit 7ff3c89
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/swank/commands/basic.clj
Expand Up @@ -40,6 +40,14 @@
(eval (with-env-locals form))
form)))))))

(defn- compile-region
"Compile region."
([string file line]
(with-open [rdr (proxy [LineNumberingPushbackReader] ((StringReader. string))
(getLineNumber [] line))]
(clojure.lang.Compiler/load rdr file (.getName (File. file))))))


(defslimefn interactive-eval-region [string]
(with-emacs-package
(pr-str (first (eval-region string)))))
Expand Down Expand Up @@ -146,7 +154,12 @@
(defslimefn compile-string-for-emacs [string buffer position directory debug]
(let [start (System/nanoTime)
line (line-at-position directory position)
ret (with-emacs-package (eval-region string directory line))
ret (with-emacs-package
(when-not (= (name (ns-name *ns*)) *current-package*)
(throw (clojure.lang.Compiler$CompilerException.
directory line
(Exception. (str "No such namespace: " *current-package*)))))
(compile-region string directory line))
delta (- (System/nanoTime) start)]
`(:compilation-result nil ~(pr-str ret) ~(/ delta 1000000000.0))))

Expand Down

0 comments on commit 7ff3c89

Please sign in to comment.