Skip to content
This repository has been archived by the owner on Oct 2, 2020. It is now read-only.

Commit

Permalink
Make slamhound.el work as a swank payload.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Jan 5, 2012
1 parent c98d626 commit be6dd0e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 38 deletions.
24 changes: 14 additions & 10 deletions README.md
Expand Up @@ -25,9 +25,9 @@
Slamhound rips your ns form apart and reconstructs it. No Dutch
surgeon required.

Add it to your :dev-dependencies.
Install it as a Leiningen plugin:

[slamhound "1.2.0"]
$ lein plugin install slamhound 1.2.0

## Leiningen Usage

Expand Down Expand Up @@ -79,27 +79,31 @@ You can do it manually from the repl too:

## Emacs Usage

The included slamhound.el allows for convenient access within Slime
sessions via M-x slamhound as well as running it over an entire
project with M-x slamhound-project.
The included `src/swank/payload/slamhound.el` allows for
convenient access within Slime sessions via `M-x slamhound` as well as
running it over an entire project with `M-x slamhound-project`.

You can install manually, but if you use `M-x clojure-jack-in` with
Swank Clojure 1.3.3 or newer to launch your Slime session then it will
be loaded into Emacs automatically.

Emacs version 24 or greater is required.

## The Rules

Slamhound can only rebuild your namespace if it follows the rules and
doesn't do anything too fancy. If your code depends upon a
:require clause, the required namespace must be aliased :as the last
segment of its name. The only supported option to :use is :only.
doesn't do anything too fancy. If your code depends upon a `:require`
clause, the required namespace must be aliased `:as` the last segment
of its name. Referring to fully-qualified vars is not supported. The
only supported option to `:use` is `:only`.

## Future Plans

* Better pretty-printing
* Piggy-backing elisp inside jar
* Allow for custom disambiguator functions

## License

Copyright (C) 2011 Phil Hagelberg
Copyright © 2011 Phil Hagelberg

Distributed under the Eclipse Public License, the same as Clojure.
1 change: 1 addition & 0 deletions resources/swank_elisp_payloads.clj
@@ -0,0 +1 @@
["swank/payload/slamhound.el"]
29 changes: 1 addition & 28 deletions slamhound.el → src/swank/payload/slamhound.el
Expand Up @@ -52,45 +52,18 @@
(catch Exception e
(println :error (.getMessage e)))))))

(defun slamhound-point-at-end-of-sexp (start)
(save-excursion (goto-char start) (end-of-sexp) (point)))

(defun slamhound-prettify-subclause ()
(backward-char 2)
(let ((beginning-of-sexp (point)))
(while (search-forward-regexp "[ \n]" (slamhound-point-at-end-of-sexp
beginning-of-sexp) t)
(just-one-space -1))))

(defun slamhound-prettify-clause (clause)
(just-one-space -1)
(beginning-of-line)
(let ((end-of-clause (save-excursion (end-of-sexp) (point))))
(while (search-forward-regexp "[(\\[][a-z]" end-of-clause t)
(slamhound-prettify-subclause))))

(defun slamhound-prettify ()
(interactive)
(goto-char (point-min))
(let ((end-of-ns (save-excursion (end-of-defun) (point))))
(while (search-forward-regexp "(:\\([-a-z]+\\)" end-of-ns t)
(slamhound-prettify-clause (match-string 0)))
(indent-region (point-min) end-of-ns)))

;;;###autoload
(defun slamhound ()
"Run slamhound on the current buffer. Requires active slime connection."
(interactive)
(let* ((code (slamhound-clj-string buffer-file-name))
(result (first (slime-eval `(swank:eval-and-grab-output ,code)))))
(setq rrr result)
(if (string-match "^:error \\(.*\\)" result)
(error (match-string 1 result))
(goto-char (point-min))
(kill-sexp)
;; TODO: translate \n into newline
(insert result)
(slamhound-prettify))))
(insert result))))

;; Project-wide:

Expand Down

0 comments on commit be6dd0e

Please sign in to comment.