This thread encouraged me to post what I did to make swank-clojure
1.1.0 work with the the latest SLIME. It does not use any of swank-
clojure's automatic .jar downloading features (as of version 1.1.0).
These instructions won't work on Windows, but may work if you have
Cygwin.

Note that this sets up some Common Lisp installations. Delete those
lines if you don't want them.

If you already figured out how to put SLIME and swank-clojure on your
classpath, omit that part of the setup. See the comments.

Assumptions:
 - SLIME in ~/.emacs.d/site-lisp/slime
 - swank-clojure in ~/.emacs.d/site-lisp/swank-clojure
 - your project is laid out with a src/ directory containing your
actual code; it goes on the classpath
 - you want all .jar files in your project on your classpath
 - several directories, including classes/ and resources/, also get
added to your classpath
 - you have exactly one file called clojure-<version-number>.jar in
the resulting classpath; this becomes the version of Clojure launched
by SLIME

Instructions:
 - put the code below into your .emacs.d/init.el or .emacs file
 - use M-x clojure-project to launch SLIME; this is my variant of
swank-clojure-project, but it makes no assumptions about Maven,
magical downloads, ELPA, or anything else

Limitation:
 - slime-connect doesn't seem to work right; you have to launch
Clojure and your app using clojure-project

One more thing: swank-clojure 1.1.0 requires a tiny patch to work with
the latest SLIME. This patch seems to already be in swank-clojure's
master branch, but be aware of it: 
http://groups.google.com/group/swank-clojure/msg/01ff818359061a28

Could this be a good start to making swank-clojure both newbie-and-
ELPA-friendly and Emacs-graybeard-friendly?



;;; generic Emacs utility
;;; ------------------------------------------------------------------

(defun add-subdirs-to-load-path (dir)
  (let ((default-directory (concat dir "/")))
    (normal-top-level-add-subdirs-to-load-path)))


;;; basic load-path setup
;;; ------------------------------------------------------------------

(add-to-list 'load-path "~/.emacs.d/site-lisp")
(add-subdirs-to-load-path "~/.emacs.d/site-lisp")


;;; SLIME and swank-clojure
;;; ------------------------------------------------------------------

(require 'slime-autoloads)
(add-to-list 'load-path "~/.emacs.d/site-lisp/slime/contrib")
;(slime-setup '(slime-fancy slime-asdf))
(slime-setup '(slime-repl))

(setq slime-net-coding-system 'utf-8-unix)

(setq slime-lisp-implementations
      '((acl  ("/opt/acl/alisp"))
        (sbcl ("/opt/sbcl/run-sbcl.sh"))
        (ccl  ("/opt/ccl/dx86cl64"))))

(defmacro defslime-start (name mapping)
  `(defun ,name ()
     (interactive)
     (let ((slime-default-lisp ,mapping))
       (slime))))

(defslime-start acl 'acl)
(defslime-start sbcl 'sbcl)
(defslime-start ccl 'ccl)
(defslime-start clojure 'clojure)

(setq swank-clojure-classpath '("~/.emacs.d/site-lisp/swank-clojure/
src"))
(setq swank-clojure-extra-vm-args
      (list "-server" "-Xms128M" "-Xmx512M" "-Dfile.encoding=UTF-8"))

(autoload 'clojure-mode "clojure-mode" "A major mode for Clojure" t)
(add-to-list 'auto-mode-alist '("\\.clj$" . clojure-mode))
(require 'swank-clojure)

(add-hook 'slime-mode-hook
          (lambda ()
            (setq slime-truncate-lines nil)
            (slime-redirect-inferior-output)))

(defun clojure-slime-reset ()
  "Helper function which resets Clojure in SLIME's list of
   implementations. Useful for changing Clojure's classpath."
  (setq slime-lisp-implementations
        (cons `(clojure ,(swank-clojure-cmd) :init swank-clojure-init)
              (remove-if #'(lambda (x) (eq (car x) 'clojure))
                         slime-lisp-implementations))))

(defun clojure-project-prompt (path)
  (interactive "GProject path: ")
  (list path))

(defun clojure-project (path)
  "Set up Clojure classpath and other swank-clojure variables for
   the project with root at 'path'. Include all *.jar files under
   path. Also include 'classes' subdirectory."
  (interactive
   (let* ((dominating-file (locate-dominating-file buffer-file-name
                                                   "src/"))
          (default-directory (if (and buffer-file-name dominating-
file)
                                 dominating-file
                                 default-directory)))
     (call-interactively 'clojure-project-prompt)))
  (when (and (fboundp 'slime-connected-p) (slime-connected-p))
    (slime-quit-lisp)
    (sleep-for 1)
    (slime-kill-all-buffers))
  (flet ((clojure-jar-p (s) (string-match
                             "clojure\\(-[0-9a-f\\.]*\\)?\\.jar$"
                             s))
         (validate-path (p) (when (file-accessible-directory-p p)
                              (list p))))
    (let* ((src-path
            (append
             (validate-path (expand-file-name "src" path))
             (validate-path (expand-file-name "source" path))
             (validate-path (expand-file-name "code" path))))
           (test-path
            (append
             (validate-path (expand-file-name "test" path))
             (validate-path (expand-file-name "tests" path))))
           (examples-path
            (append
             (validate-path (expand-file-name "demo" path))
             (validate-path (expand-file-name "sample" path))
             (validate-path (expand-file-name "example" path))
             (validate-path (expand-file-name "examples" path))))
           (libs-path
            (split-string
             (shell-command-to-string
              (format "find %s -type f -name '*.jar' -print0" path))
             "[\000]+"))
           (classes-path
            (append
             (validate-path (expand-file-name "classes" path))))
           (resources-path
            (append
             (validate-path (expand-file-name "resource" path))
             (validate-path (expand-file-name "resources" path))))
           (swank-clojure-classpath
            (append swank-clojure-classpath src-path libs-path
                    classes-path resources-path))
           ;; swank-clojure configuration dynamic variable rebinding
           (swank-clojure-binary nil)
           (swank-clojure-jar-path ; override if provided in project
            (let ((project-clojure-jar
                   (first (member-if #'clojure-jar-p
                                     swank-clojure-classpath))))
              (if project-clojure-jar
                  project-clojure-jar
                swank-clojure-jar-path))))
      (clojure-slime-reset)
      (save-window-excursion
        (clojure)))))

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

To unsubscribe, reply using "remove me" as the subject.

Reply via email to