Skip to content

Commit b476345

Browse files
committed
Support TRAMP connections
Fixes #552
1 parent d006e2e commit b476345

File tree

3 files changed

+53
-15
lines changed

3 files changed

+53
-15
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## 3.10.0
6+
7+
* [#552](https://github.com/clojure-emacs/clj-refactor.el/issues/552): support TRAMP connections.
8+
59
## 3.9.4
610

711
* Fix `cljr-version`.

clj-refactor.el

+30-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
;; Lars Andersen <[email protected]>
88
;; Benedek Fazekas <[email protected]>
99
;; Bozhidar Batsov <[email protected]>
10-
;; Version: 3.9.4
10+
;; Version: 3.10.0
1111
;; Keywords: convenience, clojure, cider
1212

13-
;; Package-Requires: ((emacs "26.1") (seq "2.19") (yasnippet "0.6.1") (paredit "24") (multiple-cursors "1.2.2") (clojure-mode "5.16.1") (cider "1.7.0") (parseedn "1.1.0") (inflections "2.6") (hydra "0.13.2"))
13+
;; Package-Requires: ((emacs "26.1") (seq "2.19") (yasnippet "0.6.1") (paredit "24") (multiple-cursors "1.2.2") (clojure-mode "5.17.0") (cider "1.7.0") (parseedn "1.1.0") (inflections "2.6") (hydra "0.13.2"))
1414

1515
;; This program is free software; you can redistribute it and/or
1616
;; modify it under the terms of the GNU General Public License
@@ -746,26 +746,43 @@ if the point is currently placed at the opening parentheses of an anonymous func
746746
;; evenp lives in cl.el...
747747
(zerop (mod n 2)))
748748

749+
(defun cljr--remove-tramp-prefix-from-msg (entry)
750+
(let* ((k (car entry))
751+
(v (cadr entry)))
752+
(list k
753+
(if (and (member k '("file" "dir" "path" "old-path" "new-path"))
754+
(stringp v))
755+
(if-let* ((p (cider-tramp-prefix)))
756+
(string-remove-prefix p v)
757+
v)
758+
v))))
759+
749760
(defun cljr--create-msg (op &rest kvs)
750761
"Create a msg for the middleware for OP and optionally include the kv pairs KVS.
751762
752763
All config settings are included in the created msg."
753764
(cl-assert (cljr--evenp (length kvs)) nil "Can't create msg to send to the middleware.\
754765
Received an uneven number of kv pairs: %s " kvs)
755-
(apply #'list "op" op
766+
(apply #'list
767+
"op" op
768+
756769
"prefix-rewriting"
757770
(if cljr-favor-prefix-notation
758771
"true"
759772
"false")
773+
760774
"insert-newline-after-require"
761775
(if cljr-insert-newline-after-require
762776
"true"
763777
"false")
778+
764779
"debug"
765780
(if cljr--debug-mode
766781
"true"
767782
"false")
768-
kvs))
783+
784+
(seq-mapcat #'cljr--remove-tramp-prefix-from-msg
785+
(seq-partition kvs 2))))
769786

770787
(defun cljr--post-command-message (format-string &rest args)
771788
"Display msg in a post command hook, to ensure it doesn't drown in emacs' general chatter."
@@ -2709,8 +2726,14 @@ See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-promote-function
27092726
(string-remove-prefix (cljr--project-dir) path))
27102727

27112728
(defun cljr--get-valid-filename (hash)
2712-
"Get :file value from the hash table and convert path if necessary."
2713-
(funcall cider-from-nrepl-filename-function (gethash :file hash)))
2729+
"Get :file value from the hash table and convert path if necessary.
2730+
2731+
Translate it back to TRAMP notation if needed."
2732+
(let ((file (funcall cider-from-nrepl-filename-function (gethash :file hash)))
2733+
(current (funcall cider-from-nrepl-filename-function (buffer-file-name))))
2734+
(if (tramp-tramp-file-p current)
2735+
(concat (cider-tramp-prefix) file)
2736+
file)))
27142737

27152738
(defun cljr--format-symbol-occurrence (occurrence)
27162739
(let ((file (cljr--get-valid-filename occurrence))
@@ -3429,7 +3452,7 @@ See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-inline-symbol"
34293452
(cljr--post-command-message "No occurrences of '%s' found. Deleted the definition." symbol)))))
34303453
(cljr--indent-defun)))
34313454

3432-
(defconst cljr-version "3.9.4"
3455+
(defconst cljr-version "3.10.0"
34333456
"The current version of clj-refactor.")
34343457

34353458
(defun cljr--pkg-version ()

tests/unit-test.el

+19-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
(delay-mode-hooks (clojure-mode))
1919
,@body))
2020

21+
(defmacro with-point-at (text &rest body)
22+
(declare (indent 1))
23+
`(progn (insert ,text)
24+
(goto-char (point-min))
25+
(re-search-forward "|")
26+
(delete-char -1)
27+
,@body))
28+
2129
(describe "cljr--insert-require-libspec"
2230
:var (after-inserting-a
2331
after-inserting-b)
@@ -170,14 +178,6 @@
170178
(expect (cljr--unresolved-alias-ref "js")
171179
:to-equal "js"))))
172180

173-
(defmacro with-point-at (text &rest body)
174-
(declare (indent 1))
175-
`(progn (insert ,text)
176-
(goto-char (point-min))
177-
(re-search-forward "|")
178-
(delete-char -1)
179-
,@body))
180-
181181
(describe "cljr--language-context-at-point"
182182
(it "identifies a clj file"
183183
(cljr--with-clojure-temp-file "foo.clj"
@@ -396,3 +396,14 @@ ex/")))
396396
(expect (buffer-string) :to-equal "(ns foo
397397
(:require [baz.example :as ex :refer [a b c] ]))
398398
ex/"))))
399+
400+
(describe "cljr--remove-tramp-prefix-from-msg"
401+
(it "Removes the tramp prefix from specifc nrepl message attributes"
402+
(with-temp-buffer
403+
(setq buffer-file-name "/ssh:[email protected]#22:a.clj")
404+
(let* ((v (seq-mapcat #'cljr--remove-tramp-prefix-from-msg
405+
(seq-partition (list "file" "/ssh:[email protected]#22:a.clj"
406+
"something" "else")
407+
2))))
408+
(setq-local tramp-mode nil) ;; prevent hanging
409+
(expect v :to-equal '("file" "a.clj" "something" "else"))))))

0 commit comments

Comments
 (0)