Skip to content

Commit d29c59d

Browse files
cichlibbatsov
authored andcommitted
Add cider-ns-save-files-on-refresh-modes
1 parent 26b3c7b commit d29c59d

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### New features
66

77
### Changes
8+
* [#2546](https://github.com/clojure-emacs/cider/pull/2546): New defcustom `cider-ns-save-files-on-refresh-modes` to control for which buffers `cider-ns-refresh` should save before refreshing.
89

910
### Bug fixes
1011
* Fix values for `cider-preferred-build-tool` variable.

cider-ns.el

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
(define-obsolete-variable-alias 'cider-save-files-on-cider-ns-refresh 'cider-ns-save-files-on-refresh "0.18")
6767
(defcustom cider-ns-save-files-on-refresh 'prompt
68-
"Controls whether to prompt to save Clojure files on `cider-ns-refresh'.
68+
"Controls whether to prompt to save files before refreshing.
6969
If nil, files are not saved.
7070
If 'prompt, the user is prompted to save files if they have been modified.
7171
If t, save the files without confirmation."
@@ -75,6 +75,16 @@ If t, save the files without confirmation."
7575
:group 'cider
7676
:package-version '(cider . "0.15.0"))
7777

78+
(defcustom cider-ns-save-files-on-refresh-modes '(clojure-mode)
79+
"Controls which files might be saved before refreshing.
80+
If a list of modes, any buffers visiting files on the classpath whose major
81+
mode is derived from any of the modes might be saved.
82+
If t, all buffers visiting files on the classpath might be saved."
83+
:type '(choice listp
84+
(const t))
85+
:group 'cider
86+
:package-version '(cider . "0.21.0"))
87+
7888
(defconst cider-ns-refresh-log-buffer "*cider-ns-refresh-log*")
7989

8090
(define-obsolete-variable-alias 'cider-refresh-show-log-buffer 'cider-ns-refresh-show-log-buffer "0.18")
@@ -163,14 +173,15 @@ namespace-qualified function of zero arity."
163173

164174
(defun cider-ns-refresh--save-modified-buffers ()
165175
"Ensure any relevant modified buffers are saved before refreshing.
166-
Its behavior is controlled by `cider-ns-save-files-on-refresh'."
176+
Its behavior is controlled by `cider-ns-save-files-on-refresh' and
177+
`cider-ns-save-files-on-refresh-modes'."
167178
(when cider-ns-save-files-on-refresh
168179
(let ((dirs (seq-filter #'file-directory-p
169180
(cider-sync-request:classpath))))
170181
(save-some-buffers
171182
(not (eq cider-ns-save-files-on-refresh 'prompt))
172183
(lambda ()
173-
(and (derived-mode-p 'clojure-mode)
184+
(and (seq-some #'derived-mode-p cider-ns-save-files-on-refresh-modes)
174185
(seq-some (lambda (dir)
175186
(file-in-directory-p buffer-file-name dir))
176187
dirs)))))))

doc/miscellaneous_features.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ the echo area.
160160
(setq cider-ns-refresh-show-log-buffer t)
161161
```
162162

163-
By default, CIDER will prompt for whether to save all modified Clojure
164-
buffers. You can customize this behavior with
165-
`cider-ns-save-files-on-refresh`.
163+
By default, CIDER will prompt for whether to save all modified `clojure-mode`
164+
buffers visiting files on the classpath. You can customize this behavior with
165+
`cider-ns-save-files-on-refresh` and `cider-ns-save-files-on-refresh-modes`.
166166

167167
Sometimes, `cider-ns-refresh` may not work for you. If you're looking
168168
for a bit more forceful reloading the `cider-ns-reload`

0 commit comments

Comments
 (0)