Skip to content

Instantly share code, notes, and snippets.

@camsaul
Last active January 6, 2021 15:57
Show Gist options
  • Save camsaul/c9036017d499e347c654636e279883af to your computer and use it in GitHub Desktop.
Save camsaul/c9036017d499e347c654636e279883af to your computer and use it in GitHub Desktop.
Run cljr-clean-ns on every file in project
;;; -*- 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))
@camsaul
Copy link
Author

camsaul commented Jan 6, 2021

When you need to run cljr-clean-ns on 800+ source files in programmatically e.g. for metabase/metabase#14281

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment