technomancy/clojure-mode — pull request #133 by leathekd (2013-01-21 02:44:38+00:00)
Title: Make configurable the behavior of jump-to-test/impl

This is achieved by making the functions clojure-test-for and
clojure-test-implementation-for return the full path of the test or
src file. Next clojure-jump-to-test and
clojure-test-jump-to-implementation simply calls these functions
through a defvar to get the path. That var can be changed by users who
want a different implementation.

The added defvars are:
clojure-test-for-fn - defaults to clojure-test-for
clojure-test-implementation-for-fn - defaults to clojure-test-implementation-for

The existing behavior of where test files are create was left
unchanged.

An example of overriding the defaults to get the old behavior of tests
and impls such as:
```
src/project/foo/bar => (ns project.foo.bar)
test/project/test/foo/bar => (ns project.test.foo.bar)
```

```lisp
(defun my-clojure-test-for (namespace)
(let* ((namespace (clojure-underscores-for-hyphens namespace))
(segments (split-string namespace "\\."))
(before (subseq segments 0 1))
(after (subseq segments 1))
(test-segments (append before (list "test") after)))
(format "%stest/%s.clj"
(locate-dominating-file buffer-file-name "src/")
(mapconcat 'identity test-segments "/"))))

(defun my-clojure-test-implementation-for (namespace)
(let* ((namespace (clojure-underscores-for-hyphens namespace))
(segments (split-string namespace "\\."))
(before (subseq segments 0 1))
(after (subseq segments 2))
(impl-segments (append before after)))
(format "%s/src/%s.clj"
(locate-dominating-file buffer-file-name "src/")
(mapconcat 'identity impl-segments "/"))))

(setq clojure-test-for-fn 'my-clojure-test-for)
(setq clojure-test-implementation-for-fn
'my-clojure-test-implementation-for)
```