Generalize doom-file-cookie-p
And move it to doom-file-cookie-p for anyone to use.
This commit is contained in:
parent
5b5dbe1c47
commit
297728bf74
5 changed files with 21 additions and 12 deletions
|
@ -137,6 +137,24 @@ MATCH is a string regexp. Only entries that match it will be included."
|
||||||
result))))
|
result))))
|
||||||
result))
|
result))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom-file-cookie-p (file &optional cookie null-value)
|
||||||
|
"Returns the evaluated result of FORM in a ;;;###COOKIE FORM at the top of
|
||||||
|
FILE.
|
||||||
|
|
||||||
|
If COOKIE doesn't exist, return NULL-VALUE."
|
||||||
|
(unless (file-exists-p file)
|
||||||
|
(signal 'file-missing file))
|
||||||
|
(unless (file-readable-p file)
|
||||||
|
(error "%S is unreadable" file))
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert-file-contents file nil 0 256)
|
||||||
|
(if (re-search-forward (format "^;;;###%s " (regexp-quote (or cookie "if")))
|
||||||
|
nil t)
|
||||||
|
(let ((load-file-name file))
|
||||||
|
(eval (sexp-at-point) t))
|
||||||
|
null-value)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defmacro file-exists-p! (files &optional directory)
|
(defmacro file-exists-p! (files &optional directory)
|
||||||
"Returns non-nil if the FILES in DIRECTORY all exist.
|
"Returns non-nil if the FILES in DIRECTORY all exist.
|
||||||
|
|
|
@ -101,7 +101,7 @@ even if it doesn't need reloading!"
|
||||||
(dolist (file targets)
|
(dolist (file targets)
|
||||||
(insert
|
(insert
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(cond ((not (doom-file-cookie-p file))
|
(cond ((not (doom-file-cookie-p file "if" t))
|
||||||
(print! (debug "Ignoring %s") (relpath file)))
|
(print! (debug "Ignoring %s") (relpath file)))
|
||||||
|
|
||||||
((let ((generated-autoload-load-name (file-name-sans-extension file)))
|
((let ((generated-autoload-load-name (file-name-sans-extension file)))
|
||||||
|
|
|
@ -156,7 +156,7 @@ If RECOMPILE-P is non-nil, only recompile out-of-date files."
|
||||||
(and (file-exists-p elc-file)
|
(and (file-exists-p elc-file)
|
||||||
(file-newer-than-file-p target elc-file)))))
|
(file-newer-than-file-p target elc-file)))))
|
||||||
total-noop
|
total-noop
|
||||||
(pcase (if (doom-file-cookie-p target)
|
(pcase (if (doom-file-cookie-p target "if" t)
|
||||||
(byte-compile-file target)
|
(byte-compile-file target)
|
||||||
'no-byte-compile)
|
'no-byte-compile)
|
||||||
(`no-byte-compile
|
(`no-byte-compile
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
(message "%s" (buffer-string))
|
(message "%s" (buffer-string))
|
||||||
(error "Failed to bootstrap unit tests")))
|
(error "Failed to bootstrap unit tests")))
|
||||||
(dolist (file files)
|
(dolist (file files)
|
||||||
(if (doom-file-cookie-p file)
|
(if (doom-file-cookie-p file "if" t)
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(unless
|
(unless
|
||||||
(zerop
|
(zerop
|
||||||
|
|
|
@ -21,15 +21,6 @@ commands like `doom-packages-install', `doom-packages-update' and
|
||||||
;;
|
;;
|
||||||
;;; Dispatcher API
|
;;; Dispatcher API
|
||||||
|
|
||||||
(defun doom-file-cookie-p (file)
|
|
||||||
(with-temp-buffer
|
|
||||||
(insert-file-contents-literally file nil 0 256)
|
|
||||||
(if (and (re-search-forward "^;;;###if " nil t)
|
|
||||||
(<= (line-number-at-pos) 3))
|
|
||||||
(let ((load-file-name file))
|
|
||||||
(eval (sexp-at-point) t))
|
|
||||||
t)))
|
|
||||||
|
|
||||||
(defun doom-sh (command &rest args)
|
(defun doom-sh (command &rest args)
|
||||||
"Execute COMMAND with ARGS in the shell and return (STATUS . OUTPUT).
|
"Execute COMMAND with ARGS in the shell and return (STATUS . OUTPUT).
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue