Skip to content

Makes clojure-test-maybe-enable more discriminating. #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 25, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions clojure-test-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -521,15 +521,25 @@ Clojure src file for the given test namespace.")

(add-hook 'nrepl-connected-hook 'clojure-test-load-reporting)

(defconst clojure-test-regex
(rx "clojure.test"))

(defun clojure-find-clojure-test ()
(let ((regexp clojure-test-regex))
(save-restriction
(save-excursion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might also want save-match-data here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(save-match-data
(goto-char (point-min))
(when (re-search-forward regexp nil t)
(match-string-no-properties 0)))))))

;;;###autoload
(progn
(defun clojure-test-maybe-enable ()
"Enable clojure-test-mode if the current buffer contains a namespace
with a \"test.\" bit on it."
(let ((ns (clojure-find-package))) ; defined in clojure-mode.el
(when (and ns (string-match "test\\(\\.\\|$\\)" ns))
(save-window-excursion
(clojure-test-mode t)))))
"Enable clojure-test-mode if the current buffer contains a \"clojure.test\" bit in it."
(when (clojure-find-clojure-test)
(save-window-excursion
(clojure-test-mode t))))

(add-hook 'clojure-mode-hook 'clojure-test-maybe-enable))

Expand Down