Skip to content

Commit

Permalink
refactor: extract reusable +delete-file-or-directory function, refa…
Browse files Browse the repository at this point in the history
…ctor code
  • Loading branch information
abougouffa committed Oct 21, 2023
1 parent f06b06a commit 597df98
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
22 changes: 9 additions & 13 deletions core/me-bootstrap.el
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,15 @@

;;;###autoload
(defun +straight-prune-build-cache ()
(let* ((straight-dir (file-name-concat straight-base-dir "straight/"))
(default-directory straight-dir)
(builds (seq-filter
(lambda (name)
(not (member name (list straight-build-dir
(concat straight-build-dir "-cache.el")
"versions"
"repos"))))
(directory-files straight-dir nil "[^.][^.]?$"))))
(dolist (file builds)
(if (file-directory-p file)
(delete-directory file 'recursive 'trash)
(delete-file file 'trash)))))
(let* ((default-directory (file-name-concat straight-base-dir "straight/")))
(mapc #'+delete-file-or-directory
(seq-filter
(lambda (name)
(not (member name (list straight-build-dir
(concat straight-build-dir "-cache.el")
"versions"
"repos"))))
(directory-files default-directory nil "[^.][^.]?$")))))


(provide 'me-bootstrap)
Expand Down
4 changes: 4 additions & 0 deletions core/me-loaddefs.el
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ If PATH is not specified, default to the current buffer's file.
If FORCE-P, delete without confirmation.
(fn &optional PATH FORCE-P)" t)
(autoload '+delete-file-or-directory "../elisp/+io" "\
Delete FILE-OR-DIRECTORY with `delete-file' or `delete-directory'.
(fn FILE-OR-DIRECTORY &optional TRASH RECURSIVE)")
(autoload '+move-this-file "../elisp/+io" "\
Move current buffer's file to NEW-PATH.
Expand Down
7 changes: 7 additions & 0 deletions elisp/+io.el
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ If FORCE-P, delete without confirmation."
(when (file-exists-p path)
(error "Failed to delete %S" short-path))))))

;;;###autoload
(defun +delete-file-or-directory (file-or-directory &optional trash recursive)
"Delete FILE-OR-DIRECTORY with `delete-file' or `delete-directory'."
(if (file-directory-p file-or-directory)
(delete-directory file-or-directory recursive trash)
(delete-file file-or-directory trash)))

;;;###autoload
(defun +move-this-file (new-path &optional force-p)
"Move current buffer's file to NEW-PATH.
Expand Down

0 comments on commit 597df98

Please sign in to comment.