Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a visual progress for when evaluating a directory recursively #3615

Closed
wants to merge 13 commits into from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### Changes

- Show progress status when loading `all-files` recursively.
- Bump the injected nREPL to 1.1.1.

## 1.13.1 (2024-02-01)
Expand Down
29 changes: 19 additions & 10 deletions cider-eval.el
Original file line number Diff line number Diff line change
Expand Up @@ -1789,14 +1789,15 @@ passing arguments."
(widen)
(substring-no-properties (buffer-string)))))

(defun cider-load-buffer (&optional buffer callback undef-all)
(defun cider-load-buffer (&optional buffer callback undef-all progress)
"Load (eval) BUFFER's file in nREPL.
If no buffer is provided the command acts on the current buffer. If the
buffer is for a cljc file, and both a Clojure and ClojureScript REPL exists
for the project, it is evaluated in both REPLs.
Optional argument CALLBACK will override the default ‘cider-load-file-handler’.
When UNDEF-ALL is non-nil or called with \\[universal-argument], removes
all ns aliases and var mappings from the namespace before reloading it."
all ns aliases and var mappings from the namespace before reloading it.
PROGRESS is a formatted progress status that's shown on the loading message."
(interactive (list (current-buffer) nil (equal current-prefix-arg '(4))))
(setq buffer (or buffer (current-buffer)))
;; When cider-load-buffer or cider-load-file are called in programs the
Expand Down Expand Up @@ -1831,33 +1832,41 @@ all ns aliases and var mappings from the namespace before reloading it."
(file-name-nondirectory filename)
repl
callback)))
(message "Loading %s..." filename))))))
(message (concat "Loading " progress "%s...") filename))))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not use concat in message, as you can just use format specifiers like %s, %d, etc. It's similar to Clojure's format.


(defun cider-load-file (filename &optional undef-all)
(defun cider-load-file (filename &optional undef-all progress)
"Load (eval) the Clojure file FILENAME in nREPL.
If the file is a cljc file, and both a Clojure and ClojureScript REPL
exists for the project, it is evaluated in both REPLs. The heavy lifting
is done by `cider-load-buffer'.
When UNDEF-ALL is non-nil or called with \\[universal-argument], removes
all ns aliases and var mappings from the namespace before reloading it."
all ns aliases and var mappings from the namespace before reloading it.
PROGRESS is a formatted progress status that's shown on the loading message."
(interactive (list
(read-file-name "Load file: " nil nil nil
(read-file-name "Load file:"
nil nil nil
(when (buffer-file-name)
(file-name-nondirectory
(buffer-file-name))))
(equal current-prefix-arg '(4))))
(if-let* ((buffer (find-buffer-visiting filename)))
(cider-load-buffer buffer nil undef-all)
(cider-load-buffer (find-file-noselect filename) nil undef-all)))
(cider-load-buffer (find-file-noselect filename) nil undef-all progress)))

(defun cider-load-all-files (directory undef-all)
"Load all files in DIRECTORY (recursively).
Useful when the running nREPL on remote host.
When UNDEF-ALL is non-nil or called with \\[universal-argument], removes
all ns aliases and var mappings from the namespaces being reloaded"
all ns aliases and var mappings from the namespaces being reloaded."
(interactive "DLoad files beneath directory: \nP")
(mapcar (lambda (file) (cider-load-file file undef-all))
(directory-files-recursively directory "\\.clj[cs]?$")))
(let* ((files (directory-files-recursively directory "\\.clj[cs]?$"))
(file-count (length files))
(i 0))
(mapcar (lambda (file)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use mapc instead of mapcar if all you care about are the side-effects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking again at the code - probably using dolist would be even better than mapc, as it reflects best what we want to do anyways.

(cider-load-file file undef-all
(format "[%s/%s] " i file-count))
(setq i (+ i 1)))
files)))

(defalias 'cider-eval-file #'cider-load-file
"A convenience alias as some people are confused by the load-* names.")
Expand Down
Loading