Skip to content

Commit

Permalink
Use clojure-jack-in for SLIME
Browse files Browse the repository at this point in the history
  • Loading branch information
cdaddr committed Apr 12, 2012
1 parent 5d7f2ff commit 0923afa
Show file tree
Hide file tree
Showing 124 changed files with 672 additions and 81,694 deletions.
65 changes: 31 additions & 34 deletions .emacs
@@ -1,15 +1,18 @@
;; fix exec-path
(setq exec-path (append exec-path '("/home/brian/local/bin")))

(mapcar (lambda (x) (add-to-list 'load-path (expand-file-name x)))
'("~/.emacs.d"
"~/.emacs.d/clojure-mode"
"~/.emacs.d/slime"
"~/.emacs.d/swank-clojure-extra"
"~/.emacs.d/haskell-mode"
"~/.emacs.d/org/lisp"
"~/.emacs.d/org/contrib/lisp"))

(defun require-all (packages)
(mapcar #'require packages))

(setq inferior-lisp-program "java -cp clojure-1.3.0.jar clojure.main")

(require-all '(
mwe-log-commands
uniquify
Expand All @@ -23,8 +26,8 @@
bar-cursor
browse-kill-ring
smart-tab
clojure-test-mode
undo-tree
clojure-mode
))

(defun code-mode (x)
Expand Down Expand Up @@ -201,15 +204,6 @@

(global-set-key [C-tab] 'indent-according-to-mode)

;; Auto-wrap isearch
;;(defadvice isearch-search (after isearch-no-fail activate)
;; (unless isearch-success
;; (ad-disable-advice 'isearch-search 'after 'isearch-no-fail)
;; (ad-activate 'isearch-search)
;; (isearch-repeat (if isearch-forward 'forward))
;; (ad-enable-advice 'isearch-search 'after 'isearch-no-fail)
;; (ad-activate 'isearch-repeat)))

(setq isearch-search-fun-function 'wrapping-search-fun)

(defun wrapping-search-fun ()
Expand Down Expand Up @@ -372,29 +366,36 @@ Also moves point to the beginning of the text you just yanked."
(list "native/linux/x86_64")))
(setq swank-clojure-extra-vm-args (list "-Dfile.encoding=UTF8"))

(defun clojure () (interactive) (clojure-jack-in))
(defun restart-clojure () (interactive) (slime-quit-lisp) (kill-matching-buffers "slime-repl") (clojure-jack-in))
(defun playground () (interactive) (cd "~/code/playground") (clojure-jack-in))

(defun no-catch-slime-compile-error ()
"Redefine compile-file-for-emacs NOT to catch Throwable, so that the debugger is initiated
for compile errors. This makes compiler-notes fail to work, but I don't use those anyways."
(slime-eval-async `(swank:eval-and-grab-output "(in-ns 'swank.commands.basic)(defn- compile-file-for-emacs*
\"MONKEY PATCH\"
([file-name]
(let [start (System/nanoTime)]
(try
(let [ret (clojure.core/load-file file-name)
delta (- (System/nanoTime) start)]
`(:compilation-result nil ~(pr-str ret) ~(/ delta 1000000000.0)))))))
(defslimefn compile-file-for-emacs
([file-name load? & compile-options]
(when load?
(compile-file-for-emacs* file-name))))")))

(add-hook 'slime-connected-hook 'no-catch-slime-compile-error)

(eval-after-load "slime"
'(progn
(require 'swank-clojure-extra)

(add-to-list 'slime-lisp-implementations '(sbcl ("/usr/bin/sbcl")))
(add-hook 'slime-indentation-update-hooks 'swank-clojure-update-indentation)
(add-hook 'slime-repl-mode-hook 'swank-clojure-slime-repl-modify-syntax t)
(add-hook 'clojure-mode-hook 'swank-clojure-slime-mode-hook t)
(setq slime-highlight-compiler-notes nil)))

(defun clojure ()
(interactive)
(setq swank-clojure-classpath
(if (file-exists-p "lib")
(list "~/.clojure" "." "src" "src/clj" "src/cljs" "test" "lib/*" "lib/dev/*" "classes" "native" "/usr/local/lib/*")
(list "~/.clojure" "~/code/playground/lib/*" "~/code/playground/lib/dev/*" "/usr/share/java/*")))
(add-to-list 'slime-lisp-implementations
`(clojure ,(swank-clojure-cmd)
:init swank-clojure-init)
t)
(swank-clojure-project default-directory))

(add-to-list 'slime-lisp-implementations '(sbcl ("/usr/bin/sbcl")))

(defvar slime-override-map (make-keymap))
(define-minor-mode slime-override-mode
"Fix SLIME REPL keybindings"
Expand All @@ -404,12 +405,11 @@ Also moves point to the beginning of the text you just yanked."
(define-key slime-override-map (kbd "}") 'paredit-close-curly)
(define-key slime-override-map [delete] 'paredit-forward-delete)
(define-key slime-override-map [backspace] 'paredit-backward-delete)
;;(define-key slime-override-map (kbd "<C-return>") 'paredit-newline)
;;(define-key slime-override-map "\C-j" 'slime-repl-return)
(define-key slime-override-map (kbd "<C-return>") 'paredit-newline)
(define-key slime-override-map "\C-j" 'slime-repl-newline-and-indent)

(add-hook 'slime-repl-mode-hook (lambda ()
(slime-override-mode t)
(slime-redirect-inferior-output)
(modify-syntax-entry ?\[ "(]")
(modify-syntax-entry ?\] ")[")
(modify-syntax-entry ?\{ "(}")
Expand All @@ -420,9 +420,6 @@ Also moves point to the beginning of the text you just yanked."
auto-mode-alist))

(set-language-environment "UTF-8")
(setq slime-net-coding-system 'utf-8-unix)
(slime-setup '(slime-repl))
(add-hook 'slime-connected-hook 'slime-redirect-inferior-output)

(defmacro defclojureface (name color desc &optional others)
`(defface ,name '((((class color)) (:foreground ,color ,@others))) ,desc :group 'faces))
Expand Down
101 changes: 101 additions & 0 deletions .emacs.d/clojure-mode/README.md
@@ -0,0 +1,101 @@
# Clojure Mode

Provides Emacs font-lock, indentation, and navigation for the
[Clojure language](http://clojure.org).

## Installation

Unfortunately, the version on ELPA is outdated as of now. You can do a manual
install by downloading `clojure-mode.el` and placing it in the
`~/.emacs.d/` directory, creating it if it doesn't exist. Then add
this to the file `~/.emacs.d/init.el`:

```lisp
(add-to-list 'load-path "~/.emacs.d/")
(require 'clojure-mode)
```

### Marmalade

The version on Marmalade is up-to-date. If you use package.el but haven't added
[Marmalade](http://marmalade-repo.org), the community package source,
yet, add this to `~/.emacs.d/init.el`:

```lisp
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)
```

Then do this to load the package listing:

* <kbd>M-x eval-buffer</kbd>
* <kbd>M-x package-refresh-contents</kbd>

If you use a version of Emacs prior to 24 that doesn't include
package.el, you can get it from http://bit.ly/pkg-el23. If you have an
older package.el installed from tromey.com, you should upgrade in
order to support installation from multiple sources.

## Clojure Test Mode

This source repository also includes `clojure-test-mode.el`, which
provides support for running Clojure tests (using the clojure.test
framework) via SLIME and seeing feedback in the test buffer about
which tests failed or errored. The installation instructions above
should work for clojure-test-mode as well.

Once you have a SLIME session active (see below), you can run the
tests in the current buffer with `C-c C-,`. Failing tests and errors
will be highlighted using overlays. To clear the overlays, use `C-c k`.

You can jump between implementation and test files with `C-c t` if
your project is laid out in a way that clojure-test-mode expects. Your
project root should have a src/ directory containing files that
correspond to their namespace. It should also have a test/ directory
containing files that correspond to their namespace, and the test
namespaces should mirror the implementation namespaces with the
addition of "test" as the second-to-last segment of the namespace.

So `my.project.frob` would be found in `src/my/project/frob.clj` and
its tests would be in `test/my/project/test/frob.clj` in the
`my.project.test.frob` namespace.

## Paredit

Using clojure-mode with paredit is highly recommended. It is also
available using package.el from the above archive.

Use paredit as you normally would with any other mode; for instance:

```lisp
;; (require 'paredit) if you didn't install via package.el
(defun turn-on-paredit () (paredit-mode 1))
(add-hook 'clojure-mode-hook 'turn-on-paredit)
```

## Basic REPL

Use <kbd>M-x run-lisp</kbd> to open a simple REPL subprocess using
[Leiningen](http://github.com/technomancy/leiningen). Once that has
opened, you can use <kbd>C-c C-r</kbd> to evaluate the region or
<kbd>C-c C-l</kbd> to load the whole file.

If you don't use Leiningen, you can set `inferior-lisp-program` to
a different REPL command.

## SLIME

You can also use [Leiningen](http://github.com/technomancy/leiningen)
to start an enhanced REPL via SLIME:

$ lein plugin install swank-clojure 1.3.3

M-x clojure-jack-in # from inside a project

## License

Copyright © 2007-2011 Jeffrey Chu, Lennart Staflin, Phil Hagelberg

Distributed under the GNU General Public License; see C-h t to view.

0 comments on commit 0923afa

Please sign in to comment.