Skip to content

Customizable jump between test-/impl ns #196

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
20 changes: 19 additions & 1 deletion clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,23 @@ in :db/id[:db.part/user]"
(and (listp value)
(every 'characterp value))))

(defcustom clojure-test-dir-prefix "test"
"Used by clojure-test-for-fn to resolve a test namespace for the current
buffer. This is the path component between the project root and the test.
Leiningen puts sources and tests in <root>/src and <root>/test respectively.
Omit leading and trailing slashes!"
:type 'string
:group 'clojure
:safe 'stringp)

(defcustom clojure-src-dir-prefix "src"
"The folder that contains the source namespaces. Used by
clojure-test-implementation-for to resolve a test namespace
to its corresponding source. Omit leading and trailing slashes!"
:type 'string
:group 'clojure
:safe 'stringp)

(defvar clojure-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map lisp-mode-shared-map)
Expand Down Expand Up @@ -1173,9 +1190,10 @@ word test in it and whether the file lives under the test/ directory."
"Return the path of the test file for the given NAMESPACE."
(let* ((namespace (clojure-underscores-for-hyphens namespace))
(segments (split-string namespace "\\.")))
(format "%stest/%s_test.clj"
(format "%s/%s/%s_test.clj"
(file-name-as-directory
(locate-dominating-file buffer-file-name "src/"))
clojure-test-dir-prefix
(mapconcat 'identity segments "/"))))

(defvar clojure-test-for-fn 'clojure-test-for
Expand Down
3 changes: 2 additions & 1 deletion clojure-test-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,9 @@ Retuns the problem overlay if such a position is found, otherwise nil."
(namespace-end (split-string (car (last segments)) "_"))
(namespace-end (mapconcat 'identity (butlast namespace-end 1) "_"))
(impl-segments (append (butlast segments 1) (list namespace-end))))
(format "%s/src/%s.clj"
(format "%s/%s/%s.clj"
(locate-dominating-file buffer-file-name "src/")
clojure-src-dir-prefix
(mapconcat 'identity impl-segments "/"))))

(defvar clojure-test-implementation-for-fn 'clojure-test-implementation-for
Expand Down