kingtim/nrepl.el — pull request #311 by klang (2013-04-07 14:22:03+00:00)
Title: Feature/remote nrepl and nrepl jump

TL;DR; this fixes M-. when connecting emacs to a remote instance of clojure.

---

When running emacs and clojure on different host types, nrepl-jump (M-.) will not jump to the correct location.

The Clojure snippet in `nrepl-jump-to-def` will always return a local path, in relation to Clojure, disregarding host and username information. Unfortunately, emacs need that information to locate the resources to jump to.

There are two cases:
- emacs has to jump to a resource located on the remote host. Clojure has give a local host, which is devastating if emacs is running on Linux and Clojure on MacOSX. (the location of the the files WILL differ on /home and /Users)

- emacs _could_ jump to a resource located locally (under ~/.m2, for example), but again, the path could be wrong.

Both these situations are fixed by `nrepl-emacs-or-clojure-side-adjustment` and the user has a choice: it is possible to let emacs save time by opening local resource files under ~/.m2 by leaving the custom variable `nrepl-use-local-resources` as initially defined.
If this variable is set to nil (via M-x customize-variable), emacs will still adjust the path of the file returned by Clojure, because it is still wrong, as it is NOT pointing on the host running Clojure (the tramp information is simply missing because Clojure doesn't know that it is running on a remote host, when seen from emacs)

I have made the changes as minimal as possible, only injecting `nrepl-emacs-or-clojure-side-adjustment` in two of the original nrepl.el functions (nrepl-find-file and nrepl-find-resource).

The patch has been tested in these ways, with nrepl-use-local-resources on or off
;; OK OK- clojure running remotely via "lein run"
;; OK OK - clojure running remotely via "java -jar target/repl-tests-0.1.0-SNAPSHOT-standalone.jar"
;; OK OK - clojure running locally via "lein run"
;; OK OK - clojure running locally via "java -jar target/repl-tests-0.1.0-SNAPSHOT-standalone.jar"

I hope that this change can find it's way into nrepl.el.

Yours faithfully,
Karsten Lang Pedersen