Browse files

Make slamhound.el support nrepl or slime. Remove slamhound-project.

I'd drop support for slime, but it's only a couple lines.

Got rid of slamhound-project since it never worked all that well and
invoking from the command-line makes more sense when it's over a large
number of files.
  • Loading branch information...
technomancy committed Dec 27, 2012
1 parent a92a540 commit 99167c1c3dfc15ebef74d20e6a977e77051f4681
Showing with 16 additions and 55 deletions.
  1. +3 −11
  2. +13 −44 slamhound.el
@@ -77,17 +77,9 @@ You can do it manually from the repl too to avoid the slow startup time:
## Emacs Usage
-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.
-TODO: port to nrepl.el
+The included `slamhound.el` allows for convenient access within nREPL
+or SLIME sessions via `M-x slamhound`. Install manually or via
## Shortcomings
@@ -1,23 +1,21 @@
;;; slamhound.el --- Rip Clojure namespaces apart and rebuild them.
-;; Copyright (C) 2011 Phil Hagelberg
+;; Copyright © 2011-2012 Phil Hagelberg
;; Author: Phil Hagelberg <>
-;; URL:
-;; Version: 1.0.0
+;; URL:
+;; Version: 2.0.0
;; Keywords: tools, lisp
;; This file is not part of GNU Emacs.
;;; Commentary:
;; Destroys the ns form of a clojure-mode buffer and attempts to
-;; rebuild it by searching the classpath. Requires an active slime
-;; connection.
+;; rebuild it by searching the classpath. Requires an active
+;; connection to either slime or nrepl.
-;; M-x slamhound operates on the current buffer
-;; M-x slamhound-project operates on the current source tree
+;; M-x slamhound
;; If the namespace cannot be reconstructed for whatever reason, the
;; file will remain untouched and the reason will be shown.
@@ -41,10 +39,6 @@
;;; Code:
-(require 'slime)
-;; Single-file:
(defun slamhound-clj-string (filename)
(format "%s" `(do (require 'slam.hound)
(try (print (.trim (slam.hound/reconstruct
@@ -54,45 +48,20 @@
(defun slamhound ()
- "Run slamhound on the current buffer. Requires active slime connection."
+ "Run slamhound on the current buffer.
+ Requires active nrepl or slime connection."
(let* ((code (slamhound-clj-string buffer-file-name))
- (result (first (slime-eval `(swank:eval-and-grab-output ,code)))))
+ (result (if (and (boundp 'nrepl-connection-buffer)
+ (get-buffer-process nrepl-connection-buffer))
+ (plist-get (nrepl-send-string-sync code) :stdout)
+ (first (slime-eval `(swank:eval-and-grab-output ,code))))))
(if (string-match "^:error \\(.*\\)" result)
(error (match-string 1 result))
(goto-char (point-min))
- ;; TODO: translate \n into newline
(insert result))))
-;; Project-wide:
-(defun slamhound-project-files (project-root)
- (split-string (shell-command-to-string
- (format "find %s -name \"*.clj\"" project-root))))
-(defun slamhound-track-failures (failures file)
- (condition-case failure
- (save-excursion
- (find-file file)
- (slamhound)
- failures)
- (error (cons (cons file (cadr failure)) failures))))
-(defun slamhound-project ()
- "Run slamhound on an entire project. Experimental."
- (interactive)
- (save-some-buffers)
- (save-excursion
- (let* ((root (locate-dominating-file default-directory "src"))
- (files (slamhound-project-files (format "%s/src" root)))
- (errors (reduce 'slamhound-track-failures files :initial-value nil)))
- (setq eee errors)
- (if errors
- (message "Couldn't slam %s." errors)
- (message "All namespaces successfully slammed.")))))
(provide 'slamhound)
;;; slamhound.el ends here

0 comments on commit 99167c1

Please sign in to comment.