Skip to content

Commit 8758f34

Browse files
cichlibbatsov
authored andcommitted
Check the entire classpath for files to save before refreshing
Previously this relied on `clojure-project-dir` from clojure-mode, but tools.namespace will refresh any modified files on the entire classpath, so they are worth including too. Additionally, path comparisons are now made using `file-in-directory-p` rather than `string-prefix-p`, obviating any issues around path expansion, symlinks, and platform-specific issues such as case sensitivity.
1 parent b85848b commit 8758f34

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
### New features
66

77
### Changes
8-
* Fix values for `cider-preferred-build-tool` variable.
9-
* Fix value and safe property for `cider-allow-jack-in-without-project` variable.
108

119
### Bug fixes
10+
* Fix values for `cider-preferred-build-tool` variable.
11+
* Fix value and safe property for `cider-allow-jack-in-without-project` variable.
12+
* `cider-ns-save-files-on-refresh` will now save any modified buffers visiting files on the classpath, rather than just in the current project.
1213

1314
## 0.20.0 (2019-01-14)
1415

@@ -40,6 +41,7 @@
4041

4142
### Bug fixes
4243

44+
* `cider-expected-ns` no longer requires an absolute path as its argument, and now internally handles paths canonically and consistently.
4345
* [#2474](https://github.com/clojure-emacs/cider/issues/2474): Fix incorrect detection of output and out-of-order printing.
4446
* [#2514](https://github.com/clojure-emacs/cider/issues/2514): Don't auto-jump to warnings when `cider-auto-jump-to-error` is set to 'errors-only.
4547
* [#2453](https://github.com/clojure-emacs/cider/issues/2453): Make it possible to debug deftype methods by direct insertion of #dbg and #break readers into the deftype methods.

cider-ns.el

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,19 @@ namespace-qualified function of zero arity."
161161
(when (member "error" status)
162162
(cider--render-stacktrace-causes error))))
163163

164-
(defun cider-ns-refresh--save-project-buffers ()
165-
"Ensure modified project buffers are saved before certain operations.
164+
(defun cider-ns-refresh--save-modified-buffers ()
165+
"Ensure any relevant modified buffers are saved before refreshing.
166166
Its behavior is controlled by `cider-save-files-on-cider-ns-refresh'."
167-
(when-let* ((project-root (clojure-project-dir)))
168-
(when cider-save-files-on-cider-ns-refresh
167+
(when cider-save-files-on-cider-ns-refresh
168+
(let ((dirs (seq-filter #'file-directory-p
169+
(cider-sync-request:classpath))))
169170
(save-some-buffers
170-
(eq cider-save-files-on-cider-ns-refresh t)
171+
(not (eq cider-save-files-on-cider-ns-refresh 'prompt))
171172
(lambda ()
172-
(and
173-
(derived-mode-p 'clojure-mode)
174-
(string-prefix-p project-root
175-
(file-truename default-directory)
176-
(eq system-type 'windows-nt))))))))
173+
(and (derived-mode-p 'clojure-mode)
174+
(seq-some (lambda (dir)
175+
(file-in-directory-p buffer-file-name dir))
176+
dirs)))))))
177177

178178
;;;###autoload
179179
(defun cider-ns-reload (&optional prompt)
@@ -226,7 +226,7 @@ refresh functions (defined in `cider-ns-refresh-before-fn' and
226226
(interactive "p")
227227
(cider-ensure-connected)
228228
(cider-ensure-op-supported "refresh")
229-
(cider-ns-refresh--save-project-buffers)
229+
(cider-ns-refresh--save-modified-buffers)
230230
(let ((clear? (member mode '(clear 16)))
231231
(refresh-all? (member mode '(refresh-all 4)))
232232
(inhibit-refresh-fns (member mode '(inhibit-fns -1))))

0 commit comments

Comments
 (0)