swank-clojure

7 views
Skip to first unread message

Apurva Sharan

unread,
Sep 15, 2008, 11:19:30 AM9/15/08
to clo...@googlegroups.com
I was still facing some issues with using swank-clojure with the latest
svn release of clojure. Below is my local patch to get this to work.

It turned out, that this was not working because I don't have anything set
for java.library.path. The "(delete-if ..." line below takes care of that.
I also made some changes to load the dependencies for swank.clj.

Is there a better way to handle this?

---------------->8-------------------
diff --git a/swank-clojure.el b/swank-clojure.el
index 96d4e30..1631bf7 100644
--- a/swank-clojure.el
+++ b/swank-clojure.el
@@ -84,20 +84,21 @@ swank-clojure-java-path) if non-nil."
(list swank-clojure-binary))
(if (not swank-clojure-jar-path)
(error "Error: You must specify a swank-clojure-jar-path. Please see RE
- (list swank-clojure-java-path
- (if swank-clojure-library-paths
- (concat "-Djava.library.path="
- (mapconcat 'identity
- swank-clojure-library-paths
- path-separator))
- "")
- "-cp"
- (mapconcat 'identity
- (cons swank-clojure-jar-path
- swank-clojure-extra-classpaths)
- path-separator)
-
- "clojure.lang.Repl"))))
+ (delete-if (lambda (x) (string= "" x))
+ (list swank-clojure-java-path
+ (if swank-clojure-library-paths
+ (concat "-Djava.library.path="
+ (mapconcat 'identity
+ swank-clojure-library-paths
+ path-separator))
+ "")
+ "-cp"
+ (mapconcat 'identity
+ (cons swank-clojure-jar-path
+ swank-clojure-extra-classpaths)
+ path-separator)
+ "clojure.lang.Repl")))))
+

;; Change the repl to be more clojure friendly
(defun swank-clojure-slime-repl-modify-syntax ()
diff --git a/swank/swank.clj b/swank/swank.clj
index 864ab53..87931af 100644
--- a/swank/swank.clj
+++ b/swank/swank.clj
@@ -6,6 +6,7 @@
OutputStream PrintStream File)
(clojure.lang LineNumberingPushbackReader)
(java.net ServerSocket Socket InetAddress)
- (java.util.zip ZipFile)))
-
-(load "swank-clojure.clj" "swank-c-p-c.clj" "swank-arglists.clj")
+ (java.util.zip ZipFile))
+ (:load "swank-clojure.clj")
+ (:load "swank-c-p-c.clj")
+ (:load "swank-arglists.clj"))

---------------->8-------------------


Regards,
Apurva

Stephen C. Gilardi

unread,
Sep 15, 2008, 11:22:37 AM9/15/08
to clo...@googlegroups.com

On Sep 15, 2008, at 11:19 AM, Apurva Sharan wrote:

> + (:load "swank-clojure.clj")
> + (:load "swank-c-p-c.clj")
> + (:load "swank-arglists.clj"))

In case it's helpful: a single :load could load all three files. load
takes multiple arguments.

--Steve

Apurva Sharan

unread,
Sep 15, 2008, 11:44:00 AM9/15/08
to clo...@googlegroups.com
Thanks Steve,

Yes - that's definitely helpful.

Regards,
Apurva

Feng

unread,
Sep 15, 2008, 12:14:38 PM9/15/08
to Clojure


On Sep 15, 11:19 am, Apurva Sharan <apurv...@gmail.com> wrote:
> I was still facing some issues with using swank-clojure with the latest
> svn release of clojure. Below is my local patch to get this to work.
>
> It turned out, that this was not working because I don't have anything set
> for java.library.path. The "(delete-if ..." line below takes care of that.
> I also made some changes to load the dependencies for swank.clj.
>
> Is there a better way to handle this?
>

I found it's much easier and flexible to start swank-clojure outside
of emacs.

I'm re-posting my previous reply to "clojure rant" thread (lesson
learned, never post or reply "rant" if one needs or gives help ;-).

Here is my local patch to make swank-clojure work with latest svn
clojure. tab completion, minibuffer args, M-. (jump to source), C-c C-
f (print-doc) all work with new ns/alias/require/use features.

Also, if the issue is that you can't install emacs 22 on the machine
at work (data center?) you want to use clojure. You can try slime-
connect via ssh tunneling to a remote swank-clojure server (security
alert,
it's listening on 127.0.0.1 without any auth. So you have to trust
others who can login to that machine).
Setup ssh tunneling to remote port 4005 (something like ssh -L
4005:localhost:4005 user@remotehost). Then finally, M-x slime-connect
localhost 4005 from anywhere you have emacs22+slime (no need to
install clojure or swank-clojure here if you don't want to)

;; A boot script to start swank-clojure from clojure repl

(add-classpath "file:///path/to/swank-clojure")
(require 'swank)
(swank/create-server :port 4005 :dont-close true)

Hope it helps,
cheers!
Feng

--------------------------8<-------------------------------------

diff --git a/swank/swank-clojure.clj b/swank/swank-clojure.clj
index dcb0988..aad6ba8 100644
--- a/swank/swank-clojure.clj
+++ b/swank/swank-clojure.clj
@@ -1021,13 +1021,13 @@
(defn connection-info []
`(:pid ~(get-pid)
:style ~(*emacs-connection* :communication-style)
- :lisp-implementation (:type "clojure")
+ :lisp-implementation (:type "clojure" :name "clojure")
:package (:name ~(str (ns-name *ns*))
:prompt ~(str (ns-name *ns*)))
:version ~(deref *protocol-version*)))

-(defn quit-lisp []
- (. System exit 0))
+(defn quit-lisp [])
+;; (. System exit 0))

;;;; Evaluation

@@ -1146,10 +1146,15 @@
[(. symbol (substring 0 ns-pos))
(. symbol (substring (+ ns-pos 1)))]))))

+(defn maybe-alias [sym pkg]
+ (if-let ns (find-ns sym)
+ ns
+ (sym (ns-aliases (maybe-ns pkg)))))
+
(defn simple-completions [string package]
(try
(let [[sym-ns sym-name] (symbol-name-parts string)
- ns (if sym-ns (find-ns (symbol sym-ns)) (maybe-ns package))
+ ns (if sym-ns (maybe-alias (symbol sym-ns) package) (maybe-
ns package))
vars (vals (if sym-ns (ns-publics ns) (ns-map ns)))
matches (sort (vars-start-with sym-name vars))]
(if sym-ns
@@ -1198,7 +1203,7 @@

(defn describe-symbol [symbol-name]
(with-buffer-syntax
- (if-let v (resolve (symbol symbol-name))
+ (if-let v (ns-resolve (maybe-ns *buffer-package*) (symbol symbol-
name))
(describe-to-string v)
(str "Unknown symbol " symbol-name))))

@@ -1250,20 +1255,26 @@
(get-path-prop "java.class.path")
(get-path-prop "sun.boot.class.path")))

+(defn ns-path [ns]
+ (.. (ns-name ns)
+ toString
+ (replace \- \_)
+ (replace \. \/)))
+
(defn find-definitions-for-emacs [name]
(let [sym-name (from-string name)
- metas (map meta (vals (ns-map (maybe-ns *buffer-package*))))
- definition
- (fn definition [meta]
- (if-let path (slime-find-file-in-paths (:file meta) (slime-
search-paths))
- `(~(str "(defn " (:name meta) ")")
- (:location
- ~path
- (:line ~(:line meta))
- nil))
- `(~(str (:name meta))
- (:error "Source definition not found."))))]
- (map definition (filter #(= (:name %) sym-name) metas))))
+ sym-var (ns-resolve (maybe-ns *buffer-package*) sym-name)]
+ (if-let meta (meta sym-var)
+ (list (if-let path (slime-find-file-in-paths
+ (str (ns-path (:ns meta)) "/" (:file meta))
+ (slime-search-paths))
+ `(~(str "(defn " (:name meta) ")")
+ (:location
+ ~path
+ (:line ~(:line meta))
+ nil))
+ `(~(str (:name meta))
+ (:error "Source definition not found.")))))))

;;;; Indentation & indentation cache

diff --git a/swank/swank.clj b/swank/swank.clj
index 559fb0a..864ab53 100644
--- a/swank/swank.clj
+++ b/swank/swank.clj
@@ -8,4 +8,4 @@
(java.net ServerSocket Socket InetAddress)
(java.util.zip ZipFile)))

-(load-resources "swank-clojure.clj" "swank-c-p-c.clj" "swank-
arglists.clj")
+(load "swank-clojure.clj" "swank-c-p-c.clj" "swank-arglists.clj")

----------------------8<-----------------------------

Alexey Goldin

unread,
Sep 15, 2008, 12:49:35 PM9/15/08
to Clojure
Feng, your answer in other thread started by me is very much
appreciated, sorry for ranting :-) Your diff works great (emacs 22,
svn clojure, Ubuntu 7.04) .

Matt Revelle

unread,
Sep 15, 2008, 4:24:20 PM9/15/08
to clo...@googlegroups.com
Not sure why the empty string would cause you problems, but will add
the delete-if portion (thanks, was looking for that).

There's no need to have separate loads for the .clj files.

On Sep 15, 2008, at 11:19 AM, Apurva Sharan wrote:

Reply all
Reply to author
Forward
0 new messages