refactor(lib): enforce namespace for helpers
This commit is contained in:
parent
9b4973198b
commit
b93f398568
1 changed files with 10 additions and 10 deletions
|
@ -1,16 +1,16 @@
|
||||||
;;; lisp/lib/files.el -*- lexical-binding: t; -*-
|
;;; 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
|
"Converts a simple nested series of or/and forms into a series of
|
||||||
`file-exists-p' checks.
|
`file-exists-p' checks.
|
||||||
|
|
||||||
For example
|
For example
|
||||||
|
|
||||||
(doom--resolve-path-forms
|
(doom-files--build-checks
|
||||||
'(or A (and B C))
|
'(or A (and B C))
|
||||||
\"~\")
|
\"~\")
|
||||||
|
|
||||||
Returns (approximately):
|
Returns (not precisely, but effectively):
|
||||||
|
|
||||||
'(let* ((_directory \"~\")
|
'(let* ((_directory \"~\")
|
||||||
(A (expand-file-name A _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)
|
(if (and (listp spec)
|
||||||
(memq (car spec) '(or and)))
|
(memq (car spec) '(or and)))
|
||||||
(cons (car spec)
|
(cons (car spec)
|
||||||
(mapcar (doom-rpartial #'doom--resolve-path-forms directory)
|
(cl-loop for it in (cdr spec)
|
||||||
(cdr spec)))
|
collect (doom-files--build-checks it directory)))
|
||||||
(let ((filevar (make-symbol "file")))
|
(let ((filevar (make-symbol "file")))
|
||||||
`(let ((,filevar ,spec))
|
`(let ((,filevar ,spec))
|
||||||
(and (stringp ,filevar)
|
(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
|
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."
|
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))))
|
(and p (expand-file-name p ,directory))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
@ -358,7 +358,7 @@ some optimizations for `binary' IO."
|
||||||
;;
|
;;
|
||||||
;;; Helpers
|
;;; Helpers
|
||||||
|
|
||||||
(defun doom--update-files (&rest files)
|
(defun doom-files--update-refs (&rest files)
|
||||||
"Ensure FILES are updated in `recentf', `magit' and `save-place'."
|
"Ensure FILES are updated in `recentf', `magit' and `save-place'."
|
||||||
(let (toplevels)
|
(let (toplevels)
|
||||||
(dolist (file files)
|
(dolist (file files)
|
||||||
|
@ -412,7 +412,7 @@ If FORCE-P, delete without confirmation."
|
||||||
;; Ensures that windows displaying this buffer will be switched to
|
;; Ensures that windows displaying this buffer will be switched to
|
||||||
;; real buffers (`doom-real-buffer-p')
|
;; real buffers (`doom-real-buffer-p')
|
||||||
(doom/kill-this-buffer-in-all-windows buf t)
|
(doom/kill-this-buffer-in-all-windows buf t)
|
||||||
(doom--update-files path)
|
(doom-files--update-refs path)
|
||||||
(message "Deleted %S" short-path))))))
|
(message "Deleted %S" short-path))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
@ -429,7 +429,7 @@ If FORCE-P, overwrite the destination file if it exists, without confirmation."
|
||||||
(new-path (expand-file-name new-path)))
|
(new-path (expand-file-name new-path)))
|
||||||
(make-directory (file-name-directory new-path) 't)
|
(make-directory (file-name-directory new-path) 't)
|
||||||
(copy-file old-path new-path (or force-p 1))
|
(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))))
|
(message "File copied to %S" (abbreviate-file-name new-path))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###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)
|
(make-directory (file-name-directory new-path) 't)
|
||||||
(rename-file old-path new-path (or force-p 1))
|
(rename-file old-path new-path (or force-p 1))
|
||||||
(set-visited-file-name new-path t t)
|
(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))))
|
(message "File moved to %S" (abbreviate-file-name new-path))))
|
||||||
|
|
||||||
(defun doom--sudo-file-path (file)
|
(defun doom--sudo-file-path (file)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue