diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-30 09:16:45 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-30 09:16:45 -0500 |
| commit | 51322bfff52de06f1f0977b4719669c6200ef8a4 (patch) | |
| tree | 420e3481b7e7f4fa71099c86f3fe5807d8da52dc | |
| parent | c331be66b1e00fa0f562d43c45ce04ca5e1f677c (diff) | |
| download | dotemacs-51322bfff52de06f1f0977b4719669c6200ef8a4.tar.gz dotemacs-51322bfff52de06f1f0977b4719669c6200ef8a4.zip | |
refactor(config-utilities): extract cj/--delete-compiled-files-in-dir
Splits the file-walking work out of cj/delete-emacs-home-compiled-files
so it takes a directory parameter and returns a count. The interactive
wrapper still hardcodes user-emacs-directory and prints the same
status messages, just with the count interpolated.
The split is scope-aligned with adding tests for the file-walking
behaviour. The original function couldn't be tested without spawning
files inside user-emacs-directory itself, which would pollute the
running config.
| -rw-r--r-- | modules/config-utilities.el | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/modules/config-utilities.el b/modules/config-utilities.el index 2af3effaf..e4d0cf690 100644 --- a/modules/config-utilities.el +++ b/modules/config-utilities.el @@ -107,18 +107,27 @@ Recompile natively when supported, otherwise fall back to byte compilation." (keymap-set cj/debug-config-keymap "c h" 'cj/recompile-emacs-home) +(defun cj/--delete-compiled-files-in-dir (dir) + "Delete every .elc and .eln file under DIR recursively. +Returns the count of files deleted." + (require 'find-lisp) + (let ((count 0)) + (mapc (lambda (path) + (when (or (string-suffix-p ".elc" path) + (string-suffix-p ".eln" path)) + (delete-file path) + (setq count (1+ count)))) + (find-lisp-find-files dir "")) + count)) + (defun cj/delete-emacs-home-compiled-files () - "Delete all compiled files recursively in \='user-emacs-directory\='." + "Delete all compiled files recursively in `user-emacs-directory'." (interactive) (message "Deleting compiled files under %s. This may take a while." user-emacs-directory) - (require 'find-lisp) ;; make sure the package is required - (mapc (lambda (path) - (when (or (string-suffix-p ".elc" path) - (string-suffix-p ".eln" path)) - (delete-file path))) - (find-lisp-find-files user-emacs-directory "")) - (message "Done. Compiled files removed under %s" user-emacs-directory)) + (let ((count (cj/--delete-compiled-files-in-dir user-emacs-directory))) + (message "Done. %d compiled file(s) removed under %s" + count user-emacs-directory))) (keymap-set cj/debug-config-keymap "c d" 'cj/delete-emacs-home-compiled-files) (defun cj/compile-this-elisp-buffer () |
