From a9763eaf9468e4c92b05dc1410774374c115ffba Mon Sep 17 00:00:00 2001 From: Karsten Lang Date: Sun, 7 Apr 2013 16:05:41 +0200 Subject: [PATCH] fix nrepl-jump on remote nrepl connection minor changes made to conform with travis tests Depending on tramp. Using tramp functions to determine tramp prefix. home-prefix-adjustment will consider windows. nrepl-emacs-or-colojure-side-adjustment pushed up the call chain. Tested on Windows, MacOS, Linux. Travis is being picky :-) --- CHANGELOG.md | 2 ++ nrepl.el | 54 +++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c9380c04..efa9b6429 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ ### Bugs fixed +* M-. (nrepl-jump) on remote nrepl connection (across OS hosts) has been fixed. + ## 0.1.7 / 2013-03-13 ### New features diff --git a/nrepl.el b/nrepl.el index e10c041f3..94c060447 100644 --- a/nrepl.el +++ b/nrepl.el @@ -58,6 +58,7 @@ (require 'cl) (require 'easymenu) (require 'compile) +(require 'tramp) (eval-when-compile (defvar paredit-version)) @@ -429,14 +430,53 @@ With a PREFIX argument, print the result in the current buffer." (save-excursion (backward-sexp) (point)) (point))) +(defcustom nrepl-use-local-resources t + "Use local resources under HOME if possible." + :type 'boolean + :group 'nrepl) + +(defun nrepl-tramp-prefix () + "Top element on `find-tag-marker-ring` used to determine Clojure host." + (let ((jump-origin (buffer-file-name + (marker-buffer + (ring-ref find-tag-marker-ring 0))))) + (when (tramp-tramp-file-p jump-origin) + (let ((vec (tramp-dissect-file-name jump-origin))) + (tramp-make-tramp-file-name (tramp-file-name-method vec) + (tramp-file-name-user vec) + (tramp-file-name-host vec) + nil))))) + +(defun nrepl-home-prefix-adjustment (resource) + "System dependend HOME location will be adjusted in RESOURCE. +Removes any leading slash if on Windows." + (save-match-data + (cond ((string-match "^\\/\\(Users\\|home\\)\\/\\w+\\(\\/.+\\)" resource) + (concat (getenv "HOME") (match-string 2 resource))) + ((and (eq system-type 'windows-nt) + (string-match "^/" resource) + (not (tramp-tramp-file-p resource))) + (substring resource 1)) + resource))) + +(defun nrepl-emacs-or-clojure-side-adjustment (resource) + "Fix the RESOURCE path depending on `nrepl-use-local-resources`." + (let ((resource (nrepl-home-prefix-adjustment resource)) + (clojure-side-res (concat (nrepl-tramp-prefix) resource)) + (emacs-side-res resource)) + (cond ((equal resource "") resource) + ((and nrepl-use-local-resources + (file-exists-p emacs-side-res)) + emacs-side-res) + ((file-exists-p clojure-side-res) + clojure-side-res) + (t + resource)))) + (defun nrepl-find-file (filename) "Switch to a buffer visiting FILENAME. -Removes any leading slash if on Windows. Uses `find-file'." - (let ((fn (if (and (eq system-type 'windows-nt) - (string-match "^/" filename)) - (substring filename 1) - filename))) - (find-file fn))) +Adjusts for HOME location using `nrepl-home-prefix-adjustment'. Uses `find-file'." + (find-file (nrepl-emacs-or-clojure-side-adjustment filename))) (defun nrepl-find-resource (resource) "Find and display RESOURCE." @@ -444,7 +484,7 @@ Removes any leading slash if on Windows. Uses `find-file'." (nrepl-find-file (match-string 1 resource))) ((string-match "^\\(jar\\|zip\\):file:\\(.+\\)!/\\(.+\\)" resource) (let* ((jar (match-string 2 resource)) - (path (match-string 3 resource)) + (path (match-string 3 resource)) (buffer-already-open (get-buffer (file-name-nondirectory jar)))) (nrepl-find-file jar) (goto-char (point-min))