Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

nrepl.el support for Midje-mode.

  • Loading branch information...
commit df09c3b995f7bda8f457b5b36168c1e26d55dc5a 1 parent 6794f98
@bonega authored
Showing with 25 additions and 44 deletions.
  1. +1 −1  midje-mode-pkg.el
  2. +24 −43 midje-mode.el
View
2  midje-mode-pkg.el
@@ -1,3 +1,3 @@
(define-package "midje-mode" "0.1.1"
"Minor mode for running Midje tests in emacs, see: https://github.com/dnaumov/midje-mode"
- '((slime "1.0") (clojure-mode "1.0")))
+ '((nrepl "0.1.4") (clojure-mode "1.0")))
View
67 midje-mode.el
@@ -1,7 +1,7 @@
;;; midje-mode.el --- Minor mode for Midje tests
(require 'clojure-mode)
-(require 'slime)
+(require 'nrepl)
(require 'newcomment)
(require 'midje-mode-praise)
@@ -12,16 +12,13 @@
(defvar midje-fact-regexp "^(facts?\\([[:space:]]\\|$\\)")
(defvar midje-syntax-table nil)
-;; Callbacks
-(defun midje-insert-above-fact (result)
+(defun midje-goto-above-fact ()
(if (bolp) (forward-char)) ; at first character of defun, beginning-of-defun moves back.
- (beginning-of-defun)
- (midje-provide-result-info result))
+ (beginning-of-defun))
-(defun midje-insert-below-code-under-test (result)
+(defun midje-goto-below-code-under-test ()
(end-of-defun)
- (next-line)
- (midje-provide-result-info result))
+ (next-line))
;; Util
@@ -73,7 +70,7 @@
(defun midje-eval-unfinished ()
(midje-to-unfinished)
(end-of-defun)
- (slime-eval-last-expression))
+ (nrepl-eval-last-expression))
(defun midje-add-identifier-to-unfinished-list (identifier)
(save-excursion
@@ -108,12 +105,6 @@
(search-backward "[]")
(forward-char))
-(defun midje-provide-result-info (result)
- (destructuring-bind (output value) result
- (if (string= output "")
- (midje-display-reward)
- (midje-insert-failure-message output))))
-
(defun midje-insert-failure-message (str &optional justify)
(let ((start-point (point))
(end-point (progn (insert str) (point))))
@@ -190,6 +181,17 @@ all such comments."
(beginning-of-line)
(kill-line)))))
+(defun nrepl-check-fact-handler (buffer)
+ (nrepl-make-response-handler buffer
+ (lambda (buffer str)
+ (with-current-buffer buffer
+ (if (string-equal str "true") (midje-display-reward))))
+ (lambda (buffer str)
+ (with-current-buffer buffer
+ (midje-insert-failure-message (format "%s" str))))
+ '()
+ '()))
+
(defun midje-check-fact-near-point ()
"Used when `point' is on or just after a Midje fact.
Check that fact and also save it for use of
@@ -200,8 +202,9 @@ Check that fact and also save it for use of
(mark-defun)
(buffer-substring-no-properties (mark) (point)))))
(setq last-checked-midje-fact string)
- (slime-eval-async `(swank:eval-and-grab-output ,string)
- 'midje-insert-above-fact)))
+ (midje-goto-above-fact)
+ (nrepl-send-string string nrepl-buffer-ns
+ (nrepl-check-fact-handler (current-buffer)))))
(defun midje-recheck-last-fact-checked ()
"Used when `point` is on or just after a def* form.
@@ -210,28 +213,9 @@ the last fact checked (by `midje-check-fact-near-point')."
(interactive)
(midje-clear-comments)
- (setq midje-running-fact t)
- (slime-compile-defun)
- ; Callback is slime-compilation-finished, then midje-after-compilation-check-fact
- )
-
-;; This is a HACK. I want to add midje-after-compilation-check-fact to
-;; the slime-compilation-finished-hook, but I can't seem to override the
-;; :options declaration in the original slime.el defcustom.
-(unless (fboundp 'original-slime-compilation-finished)
- (setf (symbol-function 'original-slime-compilation-finished)
- (symbol-function 'slime-compilation-finished)))
-
-(defun slime-compilation-finished (result)
- (original-slime-compilation-finished result)
- (with-struct (slime-compilation-result. notes duration successp) result
- (if successp (midje-after-compilation-check-fact))))
-
-(defun midje-after-compilation-check-fact ()
- (if midje-running-fact
- (slime-eval-async `(swank:eval-and-grab-output ,last-checked-midje-fact)
- 'midje-insert-below-code-under-test))
- (setq midje-running-fact nil))
+ (midje-goto-below-code-under-test)
+ (nrepl-send-string last-checked-midje-fact nrepl-buffer-ns
+ (nrepl-check-fact-handler (current-buffer))))
(defun midje-check-fact ()
"If on or near a Midje fact, check it with
@@ -285,13 +269,10 @@ nearby Clojure form and recheck the last fact checked
;;;###autoload
(define-minor-mode midje-mode
- "A minor mode for running Midje tests when in `slime-mode'.
+ "A minor mode for running Midje tests when in `nrepl-mode'.
\\{midje-mode-map}"
nil " Midje" midje-mode-map
- ;; This doesn't seem to work.
- ;; (custom-add-option 'slime-compilation-finished-hook
- ;; 'midje-post-compilation-action)
(hs-minor-mode 1))
;;;###autoload
Please sign in to comment.
Something went wrong with that request. Please try again.