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 support nrepl or slime. Remove slamhound-project.
Browse files Browse the repository at this point in the history
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 99167c1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 55 deletions.
14 changes: 3 additions & 11 deletions README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -77,17 +77,9 @@ You can do it manually from the repl too to avoid the slow startup time:


## Emacs Usage ## Emacs Usage


The included `src/swank/payload/slamhound.el` allows for The included `slamhound.el` allows for convenient access within nREPL
convenient access within Slime sessions via `M-x slamhound` as well as or SLIME sessions via `M-x slamhound`. Install manually or via
running it over an entire project with `M-x slamhound-project`. [Marmalade](http://marmalade-repo.org).

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


## Shortcomings ## Shortcomings


Expand Down
57 changes: 13 additions & 44 deletions slamhound.el
Original file line number Original file line Diff line number Diff line change
@@ -1,23 +1,21 @@
;;; slamhound.el --- Rip Clojure namespaces apart and rebuild them. ;;; slamhound.el --- Rip Clojure namespaces apart and rebuild them.


;; Copyright (C) 2011 Phil Hagelberg ;; Copyright © 2011-2012 Phil Hagelberg
;; ;;
;; Author: Phil Hagelberg <technomancy@gmail.com> ;; Author: Phil Hagelberg <technomancy@gmail.com>
;; URL: http://github.com/technomancy/slamhound ;; URL: https://github.com/technomancy/slamhound
;; Version: 1.0.0 ;; Version: 2.0.0
;; Keywords: tools, lisp ;; Keywords: tools, lisp


;; This file is not part of GNU Emacs. ;; This file is not part of GNU Emacs.


;;; Commentary: ;;; Commentary:


;; Destroys the ns form of a clojure-mode buffer and attempts to ;; Destroys the ns form of a clojure-mode buffer and attempts to
;; rebuild it by searching the classpath. Requires an active slime ;; rebuild it by searching the classpath. Requires an active
;; connection. ;; connection to either slime or nrepl.


;; M-x slamhound operates on the current buffer ;; M-x slamhound

;; M-x slamhound-project operates on the current source tree


;; If the namespace cannot be reconstructed for whatever reason, the ;; If the namespace cannot be reconstructed for whatever reason, the
;; file will remain untouched and the reason will be shown. ;; file will remain untouched and the reason will be shown.
Expand All @@ -41,10 +39,6 @@


;;; Code: ;;; Code:


(require 'slime)

;; Single-file:

(defun slamhound-clj-string (filename) (defun slamhound-clj-string (filename)
(format "%s" `(do (require 'slam.hound) (format "%s" `(do (require 'slam.hound)
(try (print (.trim (slam.hound/reconstruct (try (print (.trim (slam.hound/reconstruct
Expand All @@ -54,45 +48,20 @@


;;;###autoload ;;;###autoload
(defun slamhound () (defun slamhound ()
"Run slamhound on the current buffer. Requires active slime connection." "Run slamhound on the current buffer.
Requires active nrepl or slime connection."
(interactive) (interactive)
(let* ((code (slamhound-clj-string buffer-file-name)) (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) (if (string-match "^:error \\(.*\\)" result)
(error (match-string 1 result)) (error (match-string 1 result))
(goto-char (point-min)) (goto-char (point-min))
(kill-sexp) (kill-sexp)
;; TODO: translate \n into newline
(insert result)))) (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))))

;;;###autoload
(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) (provide 'slamhound)
;;; slamhound.el ends here ;;; slamhound.el ends here

0 comments on commit 99167c1

Please sign in to comment.