Permalink
Browse files

Merge branch 'master' of https://github.com/blais/swank-clojure

  • Loading branch information...
2 parents dabee06 + d8e58e6 commit db10ee457db779ef8abb77ab01fbd17a8ae63a6d @blais blais committed May 20, 2012
View
@@ -1,7 +1,8 @@
classes/
lib/
multi-lib/
-swank-clojure*jar
+*jar
pom.xml
-/.lein-failures
-/.lein-deps-sum
+.lein-failures
+.lein-deps-sum
+/lein-swank/.lein-plugins/checksum
View
14 NEWS.md
@@ -1,5 +1,19 @@
# Swank Clojure NEWS -- history of user-visible changes
+## 1.5.0 / ???
+
+* Spun lein-swank off into its own project for `:plugins` compatibility.
+* Add support for clearing existing namespace with load-file.
+
+## 1.4.1 / 2012-03-23
+
+* Add stop-server functionality.
+
+## 1.4.0 / 2012-01-27
+
+* Added CDT debugger.
+* Support jacking into remote machines over tramp.
+
## 1.3.4 / 2011-12-27
* Integrate clj-stacktrace with slime debugger buffers.
View
@@ -12,13 +12,17 @@ using [Leiningen](http://github.com/technomancy/leiningen):
* Install `clojure-mode` either from
[Marmalade](http://marmalade-repo.org) or from
[git](http://github.com/technomancy/clojure-mode).
-* `lein plugin install swank-clojure 1.3.4`
+* Add `[lein-swank "1.4.4"]` to the `:plugins` section of either
+ `project.clj` or your user profile.
* From an Emacs buffer inside a project, invoke `M-x clojure-jack-in`
+If you are still using Leiningen 1.x, you will need to do
+`lein plugin install swank-clojure 1.4.2` instead.
+
That's all it takes; there are no extra install steps beyond
`clojure-mode` on the Emacs side and the `swank-clojure` plugin on the
-Leiningen side. In particular be sure you don't have any other
-versions of Slime installed; see "Troubleshooting" below.
+Leiningen side. In particular, be sure you **don't have any other
+versions of SLIME loaded**; see "Troubleshooting" below.
## SLIME Commands
@@ -58,7 +62,7 @@ If you just want a standalone swank server with no third-party
libraries, you can use the shell wrapper that Leiningen installs for
you:
- $ lein plugin install swank-clojure 1.3.4
+ $ lein plugin install swank-clojure 1.4.2
$ ~/.lein/bin/swank-clojure
M-x slime-connect
@@ -81,7 +85,7 @@ If you're using Maven, add this to your pom.xml under the
<dependency>
<groupId>swank-clojure</groupId>
<artifactId>swank-clojure</artifactId>
- <version>1.3.4</version>
+ <version>1.4.2</version>
</dependency>
```
@@ -152,6 +156,7 @@ To get syntax highlighting in your repl buffer, use this elisp:
```lisp
(add-hook 'slime-repl-mode-hook
(defun clojure-mode-slime-font-lock ()
+ (require 'clojure-mode)
(let (font-lock-mode)
(clojure-mode-font-lock-setup))))
```
@@ -179,7 +184,7 @@ this problem. Judicious use of `:exclusions` make it work:
```
Since swank-clojure 1.3.4, having versions of clj-stacktrace older
-than 0.2.4 in your project or user-level plugins will cause `Unable to
+than 0.2.1 in your project or user-level plugins will cause `Unable to
resolve symbol: pst-elem-str` errors. Keep in mind that user-level
plugins in `~/.lein/plugins` are uberjars in Leiningen 1.x, so it's
possible that one of your plugins (such as `lein-difftest` before
@@ -215,6 +220,35 @@ your config:
(setenv "PATH" (shell-command-to-string "echo $PATH"))
```
+When using `clojure-jack-in`, standard out for the Leiningen process
+appears in the `*swank*` buffer, but the `*out*` var gets rebound to a
+writer that is able to redirect to the `*slime-repl*` buffer. So in
+general most Clojure output will show up in your repl buffer just
+fine, but for output coming from Java libraries you may need to check
+the `*swank*` buffer.
+
+## Cygwin
+
+If you are running Emacs from Cygwin, you'll need to add the following to your
+.emacs.d/init.el file:
+
+```lisp
+(defun cyg-slime-to-lisp-translation (filename)
+ (replace-regexp-in-string "\n" ""
+ (shell-command-to-string
+ (format "cygpath.exe --windows %s" filename))))
+
+(defun cyg-lisp-to-slime-translation (filename)
+ (replace-regexp-in-string "\n" "" (shell-command-to-string
+ (format "cygpath.exe --unix %s filename"))))
+
+(setq slime-to-lisp-filename-function #'cyg-slime-to-lisp-translation)
+(setq lisp-to-slime-filename-function #'cyg-lisp-to-slime-translation)
+```
+
+This is required because the jvm runs as a normal Windows exe and uses
+Windows style paths rather than Cygwin unix style paths.
+
## How it Works
Swank Clojure is simply a server that communicates over the Slime
@@ -268,7 +302,7 @@ either.
## License
-Copyright © 2008-2011 Jeffrey Chu, Phil Hagelberg, Hugo Duncan, and
+Copyright © 2008-2012 Jeffrey Chu, Phil Hagelberg, Hugo Duncan, and
contributors
Licensed under the EPL. (See the file COPYING.)
View
@@ -0,0 +1,19 @@
+# lein-swank
+
+Leiningen plugin for launching a swank server.
+
+## Usage
+
+From version 1.7.0 on, Leiningen uses a separate list for plugins
+rather than `:dev-dependencies`. If you are using Leiningen 1.6 or
+earlier, continue adding the main `swank-clojure` entry into your
+`:dev-dependencies`.
+
+Add `[lein-swank "1.4.3"]` to `:plugins` in `project.clj`.
+Then you should have access to the `swank` and `jack-in` tasks.
+
+## License
+
+Copyright © 2012 Phil Hagelberg
+
+Distributed under the Eclipse Public License, the same as Clojure.
View
@@ -0,0 +1,3 @@
+(defproject lein-swank "1.4.4"
+ :description "A Leiningen plugin for launching a Swank server for Slime."
+ :eval-in-leiningen true)
@@ -0,0 +1,4 @@
+["swank/payload/slime.el"
+ "swank/payload/slime-repl.el"
+ "swank/payload/slime-frame-colors.el"
+ "swank/payload/slime-eldoc.el"]
@@ -1,14 +1,13 @@
(ns leiningen.jack-in
- (:use [leiningen.compile :only [eval-in-project]]
- [leiningen.swank :only [swank]])
(:require [clojure.java.io :as io]
- [clojure.string :as string])
- (:import (java.util.jar JarFile)
- (java.security MessageDigest)))
+ [clojure.string :as string]
+ [leiningen.swank :as swank])
+ (:import (java.security MessageDigest)))
-(def payloads-file-name "swank_elisp_payloads.clj")
+(def ^:private payloads-file-name "swank_elisp_payloads.clj")
(defn elisp-payload-files []
+ ;; TODO: this may not work with lein2 plugins
(->> (.getResources (.getContextClassLoader (Thread/currentThread))
payloads-file-name)
(enumeration-seq)
@@ -24,7 +23,8 @@
(let [feature (second (re-find #".*/(.*?).el$" resource))
checksum (subs (hex-digest resource) 0 8)
filename (format "%s-%s" feature checksum)
- basename (-> (System/getProperty "user.home")
+ basename (-> (or (System/getenv "HOME")
+ (System/getProperty "user.home"))
(io/file ".emacs.d" "swank" filename)
(.getAbsolutePath)
(.replaceAll "\\\\" "/"))
@@ -43,22 +43,18 @@
(byte-compile-file \"%s\" t)))"
feature checksum bytecode bytecode elisp)))
-(defn payload-loaders []
- (for [file (elisp-payload-files)]
- (loader file)))
-
(defn jack-in
"Jack in to a Clojure SLIME session from Emacs.
This task is intended to be launched from Emacs using M-x clojure-jack-in,
which is part of the clojure-mode library."
[project port]
(println ";;; Bootstrapping bundled version of SLIME; please wait...\n\n")
- (let [loaders (string/join "\n" (payload-loaders))
+ (let [loaders (string/join "\n" (map loader (elisp-payload-files)))
colors? (.contains loaders "slime-frame-colors")]
(println loaders)
(println "(sleep-for 0.1)") ; TODO: remove
(println "(run-hooks 'slime-load-hook) ; on port" port)
(println ";;; Done bootstrapping.")
- (swank project port "localhost" ":colors?" (str colors?)
- ":message" "\";;; proceed to jack in\"")))
+ (swank/swank project port "localhost" ":colors?" (str colors?)
+ ":message" "\";;; proceed to jack in\"")))
@@ -0,0 +1,74 @@
+(ns leiningen.swank
+ "Launch swank server for Emacs to connect."
+ (:require [clojure.java.io :as io]))
+
+(defn opts-list [project-opts port host cli-opts]
+ (apply concat (merge {:repl-out-root true :block true
+ :host "localhost" :port 4005}
+ project-opts
+ (apply hash-map (map read-string cli-opts))
+ (if host {:host host})
+ (if port {:port (Integer. port)}))))
+
+(defn swank-form [project port host cli-opts]
+ ;; bootclasspath workaround: http://dev.clojure.org/jira/browse/CLJ-673
+ (when (:eval-in-leiningen project)
+ (require '[clojure walk template stacktrace]))
+ `(do
+ (when-let [repl-init# '~(:repl-init project)]
+ (require repl-init#))
+ (swank.swank/start-server ~@(opts-list (:swank-options project)
+ port host cli-opts))))
+
+(def ^{:private true} jvm-opts
+ "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n")
+
+(defn- add-cdt-jvm-opts [project]
+ (if (seq (filter #(re-find #"jdwp" %)
+ (:jvm-opts project)))
+ project
+ (update-in project [:jvm-opts] conj jvm-opts)))
+
+(defn add-cdt-project-args
+ "CDT requires the JDK's tools.jar and sa-jdi.jar. Add them to the classpath."
+ [project]
+ (if (:swank-cdt project true)
+ (let [libdir (io/file (System/getProperty "java.home") ".." "lib")
+ extra-cp (for [j ["tools.jar" "sa-jdi.jar"]
+ :when (.exists (io/file libdir j))]
+ (.getAbsolutePath (io/file libdir j)))]
+ (-> project
+ (update-in [:extra-classpath-dirs] concat extra-cp)
+ add-cdt-jvm-opts))
+ project))
+
+(defn eval-in-project
+ "Support eval-in-project in both Leiningen 1.x and 2.x."
+ [project form init]
+ (let [[eip two?] (or (try (require 'leiningen.core.eval)
+ [(resolve 'leiningen.core.eval/eval-in-project)
+ true]
+ (catch java.io.FileNotFoundException _))
+ (try (require 'leiningen.compile)
+ [(resolve 'leiningen.compile/eval-in-project)]
+ (catch java.io.FileNotFoundException _)))]
+ (if two?
+ (eip project form init)
+ (eip project form nil nil init))))
+
+(defn add-swank-dep [project]
+ (if (some #(= 'swank-clojure (first %)) (:dependencies project))
+ project
+ (update-in project [:dependencies] conj ['swank-clojure "1.4.2"])))
+
+(defn swank
+ "Launch swank server for Emacs to connect. Optionally takes PORT and HOST."
+ ([project port host & opts]
+ ;; TODO: only add the dependency if it's not already present
+ (eval-in-project (-> project
+ (add-cdt-project-args)
+ (add-swank-dep))
+ (swank-form project port host opts)
+ '(require 'swank.swank)))
+ ([project port] (swank project port nil))
+ ([project] (swank project nil)))
@@ -0,0 +1,16 @@
+(ns leiningen.swank-wrap
+ (:require [leiningen.swank :as swank]
+ [leiningen.run]))
+
+(defn swank-wrap
+ "Launch a swank server on the specified port, then run a -main function.
+
+ALPHA: subject to change."
+ [project port main & args]
+ (swank/eval-in-project (-> project
+ (swank/add-cdt-project-args)
+ (swank/add-swank-dep))
+ `(do ~(swank/swank-form project port "localhost"
+ [":block" "false"])
+ ~((resolve 'leiningen.run/run-form) main args))
+ `(require '~(symbol main) '~'swank.swank)))
@@ -0,0 +1,37 @@
+;;; slime-compile-presave.el --- Refuse to save non-compiling Slime buffers
+
+;; Copyright © 2011 Phil Hagelberg
+;;
+;; Authors: Phil Hagelberg <technomancy@gmail.com>
+;; URL: http://github.com/technomancy/swank-clojure
+;; Version: 1.0.0
+;; Keywords: languages, lisp
+
+;; This file is not part of GNU Emacs.
+
+;;; Code:
+
+(defvar slime-compile-presave? nil
+ "Refuse to save slime-enabled buffers if they don't compile.")
+
+;;;###autoload
+(defun slime-compile-presave-toggle ()
+ (interactive)
+ (message "slime-compile-presave %s."
+ (if (setq slime-compile-presave? (not slime-compile-presave?))
+ "enabled" "disabled")))
+
+;;;###autoload
+(defun slime-compile-presave-enable ()
+ (make-local-variable 'before-save-hook)
+ (add-hook 'before-save-hook (defun slime-compile-presave ()
+ (when slime-compile-presave?
+ (slime-eval `(swank:eval-and-grab-output
+ ,(buffer-substring-no-properties
+ (point-min) (point-max))))))))
+
+;;;###autoload
+(add-hook 'slime-mode-hook 'slime-compile-presave-enable)
+
+(provide 'slime-compile-presave)
+;;; slime-compile-presave.el ends here
@@ -0,0 +1,12 @@
+(require 'eldoc)
+(defun clojure-slime-eldoc-message ()
+ (when (and (featurep 'slime)
+ (slime-background-activities-enabled-p))
+ (slime-echo-arglist) ; async, return nil for now
+ nil))
+
+(defun clojure-localize-documentation-function ()
+ (set (make-local-variable 'eldoc-documentation-function)
+ 'clojure-slime-eldoc-message))
+
+(add-hook 'slime-mode-hook 'clojure-localize-documentation-function)
@@ -0,0 +1,18 @@
+(require 'ansi-color)
+
+(defadvice sldb-insert-frame (around colorize-clj-trace (frame &optional face))
+ (progn
+ (ad-set-arg 0 (list (sldb-frame.number frame)
+ (ansi-color-apply (sldb-frame.string frame))
+ (sldb-frame.plist frame)))
+ ad-do-it
+ (save-excursion
+ (forward-line -1)
+ (skip-chars-forward "0-9 :")
+ (let ((beg-line (point)))
+ (end-of-line)
+ (remove-text-properties beg-line (point) '(face nil))))))
+
+(ad-activate #'sldb-insert-frame)
+
+(provide 'slime-frame-colors)
Oops, something went wrong.

0 comments on commit db10ee4

Please sign in to comment.