From 0ab3032947fb6dbff0fcbf8a666b7fdcd8f08a5a Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 30 Apr 2026 09:16:45 -0500 Subject: 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. --- modules/config-utilities.el | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'modules') diff --git a/modules/config-utilities.el b/modules/config-utilities.el index 2af3effa..e4d0cf69 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 () -- cgit v1.2.3