Last active
January 6, 2021 15:57
-
-
Save camsaul/c9036017d499e347c654636e279883af to your computer and use it in GitHub Desktop.
Run cljr-clean-ns on every file in project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; -*- lexical-binding: t; -*- | |
(defun cam/clean-file (file &optional callback) | |
(save-current-buffer | |
(find-file file) | |
(save-buffer) | |
(condition-case err | |
(cider-load-buffer | |
(current-buffer) | |
(cider-load-file-handler | |
nil | |
(lambda (buffer) | |
(with-current-buffer buffer | |
(condition-case err | |
(progn | |
(cljr-clean-ns) | |
(save-buffer)) | |
(error | |
(warn "Error cleaning namespace for %s: %s" file err)))) | |
(message "CLEANED %s" file) | |
(kill-buffer buffer) | |
(when callback | |
(funcall callback))))) | |
(error | |
(warn "Error loading buffer for %s: %s" file err) | |
(kill-buffer buffer) | |
(when callback | |
(funcall callback)))))) | |
(defun cam/clean-files (files &optional count) | |
(when files | |
(cam/clean-file | |
(car files) | |
(lambda () | |
(setq count (1+ (or count 0))) | |
(message "Cleaned %d files" count) | |
(cam/clean-files (cdr files) count))))) | |
(let ((files (cam/clean-files (split-string (shell-command-to-string "find src test enterprise modules backend -name '*.clj'") "\n")))) | |
(cam/clean-files files)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When you need to run
cljr-clean-ns
on 800+ source files in programmatically e.g. for metabase/metabase#14281