Skip to content

Commit 2efbee4

Browse files
authored
Prefer find-file-noselect to with-temp-file (#503)
`with-temp-file` causes `(buffer-file-name)` to return nil which is the root cause of #139. Additionally, `cljr--update-file` does not leave files open (unless they were alrady open), improving performance / UX. Fixes #139
1 parent 9eab946 commit 2efbee4

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

CHANGELOG.md

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

33
## Unreleased
44

5+
- [#139](https://github.com/clojure-emacs/clj-refactor.el/issues/139): avoid a repeated prompt when using `(cljr-project-clean)`.
6+
57
## 3.0.0 (2021-10-25)
68

79
- [#483](https://github.com/clojure-emacs/clj-refactor.el/issues/483): Improve performance of `cljr-slash` when typing fraction literals.

clj-refactor.el

+11-12
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,18 @@ Otherwise open the file and do the changes non-interactively."
337337
(declare (debug (form body))
338338
(indent 1))
339339
(let ((fn (make-symbol "filename"))
340-
(bf (make-symbol "buffer")))
340+
(bf (make-symbol "buffer"))
341+
(wo (make-symbol "was-open")))
341342
`(let* ((,fn ,filename)
342-
(,bf (get-file-buffer ,fn)))
343-
(if ,bf
344-
(progn
345-
(set-buffer ,bf)
346-
,@body
347-
(save-buffer))
348-
(with-temp-file ,fn
349-
(insert-file-contents ,fn)
350-
(delay-mode-hooks
351-
(clojure-mode)
352-
,@body))))))
343+
(,wo (get-file-buffer ,fn))
344+
(,bf (find-file-noselect ,fn)))
345+
(when ,bf
346+
(set-buffer ,bf)
347+
,@body
348+
(save-buffer)
349+
(when (not ,wo)
350+
;; Don't accumulate open buffers, since this can slow down Emacs for large projects:
351+
(kill-buffer))))))
353352

354353
(define-key clj-refactor-map [remap paredit-raise-sexp] 'cljr-raise-sexp)
355354
(define-key clj-refactor-map [remap paredit-splice-sexp-killing-backward] 'cljr-splice-sexp-killing-backward)

0 commit comments

Comments
 (0)