-
-
Notifications
You must be signed in to change notification settings - Fork 642
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
base: master
Are you sure you want to change the base?
Changes from 8 commits
cb018dd
7485ef6
95b64aa
c322996
c8d0112
c6b15be
4077fc6
cb68e30
fed71ae
ee7c956
263f40e
1c89bef
36490e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 thats 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 | ||
|
@@ -1831,33 +1832,50 @@ 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)))))) | ||
|
||
(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 thats 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 index-files (files) | ||
"Index each file in FILES with its formatted progress." | ||
(let* ((file-count (length files)) | ||
(indexes (number-sequence 1 file-count))) | ||
(cl-mapcar (lambda (index file) | ||
(list file (format "[%s/%s] " index file-count))) | ||
indexes | ||
files))) | ||
|
||
(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]?$")) | ||
(indexed-files (index-files files))) | ||
(mapcar (lambda (indexed-file) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While An example: (let* ((files '("a" "b" "c"))
(i 0))
(mapcar (lambda (file)
(message (format "%s %s" file i))
(setq i (inc i)))
files)) So, you can use the existing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for pointing out. My elisp knowledge is really limited and that helped a lot. Thanks! |
||
(let ((filename (car indexed-file)) | ||
(progress (car (cdr indexed-file)))) | ||
(cider-load-file filename undef-all progress))) | ||
indexed-files))) | ||
|
||
|
||
(defalias 'cider-eval-file #'cider-load-file | ||
"A convenience alias as some people are confused by the load-* names.") | ||
|
There was a problem hiding this comment.
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
inmessage
, as you can just use format specifiers like%s
,%d
, etc. It's similar to Clojure'sformat
.