diff --git a/lisp/lib/files.el b/lisp/lib/files.el index 329d53b9f..5208d1c83 100644 --- a/lisp/lib/files.el +++ b/lisp/lib/files.el @@ -1,16 +1,16 @@ ;;; lisp/lib/files.el -*- lexical-binding: t; -*- -(defun doom--resolve-path-forms (spec &optional directory) +(defun doom-files--build-checks (spec &optional directory) "Converts a simple nested series of or/and forms into a series of `file-exists-p' checks. For example - (doom--resolve-path-forms + (doom-files--build-checks '(or A (and B C)) \"~\") -Returns (approximately): +Returns (not precisely, but effectively): '(let* ((_directory \"~\") (A (expand-file-name A _directory)) @@ -25,8 +25,8 @@ This is used by `file-exists-p!' and `project-file-exists-p!'." (if (and (listp spec) (memq (car spec) '(or and))) (cons (car spec) - (mapcar (doom-rpartial #'doom--resolve-path-forms directory) - (cdr spec))) + (cl-loop for it in (cdr spec) + collect (doom-files--build-checks it directory))) (let ((filevar (make-symbol "file"))) `(let ((,filevar ,spec)) (and (stringp ,filevar) @@ -166,7 +166,7 @@ DIRECTORY is a path; defaults to `default-directory'. Returns the last file found to meet the rules set by FILES, which can be a single file or nested compound statement of `and' and `or' statements." - `(let ((p ,(doom--resolve-path-forms files directory))) + `(let ((p ,(doom-files--build-checks files directory))) (and p (expand-file-name p ,directory)))) ;;;###autoload @@ -358,7 +358,7 @@ some optimizations for `binary' IO." ;; ;;; Helpers -(defun doom--update-files (&rest files) +(defun doom-files--update-refs (&rest files) "Ensure FILES are updated in `recentf', `magit' and `save-place'." (let (toplevels) (dolist (file files) @@ -412,7 +412,7 @@ If FORCE-P, delete without confirmation." ;; Ensures that windows displaying this buffer will be switched to ;; real buffers (`doom-real-buffer-p') (doom/kill-this-buffer-in-all-windows buf t) - (doom--update-files path) + (doom-files--update-refs path) (message "Deleted %S" short-path)))))) ;;;###autoload @@ -429,7 +429,7 @@ If FORCE-P, overwrite the destination file if it exists, without confirmation." (new-path (expand-file-name new-path))) (make-directory (file-name-directory new-path) 't) (copy-file old-path new-path (or force-p 1)) - (doom--update-files old-path new-path) + (doom-files--update-refs old-path new-path) (message "File copied to %S" (abbreviate-file-name new-path)))) ;;;###autoload @@ -449,7 +449,7 @@ If FORCE-P, overwrite the destination file if it exists, without confirmation." (make-directory (file-name-directory new-path) 't) (rename-file old-path new-path (or force-p 1)) (set-visited-file-name new-path t t) - (doom--update-files old-path new-path) + (doom-files--update-refs old-path new-path) (message "File moved to %S" (abbreviate-file-name new-path)))) (defun doom--sudo-file-path (file)