 For example
 
   (doom--resolve-path-forms
-    '(or \"some-file\" (and path-var \"/an/absolute/path\"))
+    '(or A (and B C))
     \"~\")
 
-Returns
-
-  '(let ((_directory \"~\"))
-     (or (file-exists-p (expand-file-name \"some-file\" _directory))
-         (and (file-exists-p (expand-file-name path-var _directory))
-              (file-exists-p \"/an/absolute/path\"))))
+Returns (approximately):
+
+  '(let* ((_directory \"~\")
+          (A (expand-file-name A _directory))
+          (B (expand-file-name B _directory))
+          (C (expand-file-name C _directory)))
+     (or (and (file-exists-p A) A)
+         (and (if (file-exists-p B) B)
+              (if (file-exists-p C) C))))
 
 This is used by `associate!', `file-exists-p!' and `project-file-exists-p!'."
   (declare (pure t) (side-effect-free t))
   (cond ((stringp spec)
-         `(file-exists-p
-           ,(if (file-name-absolute-p spec)
-                spec
-              `(expand-file-name ,spec ,directory))))
+         `(let ((--file-- ,(if (file-name-absolute-p spec)
+                             spec
+                           `(expand-file-name ,spec ,directory))))
+            (and (file-exists-p --file--)
+                 --file--)))
         ((and (listp spec)
               (memq (car spec) '(or and)))
          `(,(car spec)

                       mode modes match files when)))))

(defmacro file-exists-p! (spec &optional directory)
  "Returns t if the files in SPEC all exist.

SPEC can be a single file or a list of forms/files. It understands nested (and
...) and (or ...), as well.

DIRECTORY is where to look for the files in SPEC if they aren't absolute. This
doesn't apply to variables, however.

For example:

  (file-exists-p! (or doom-core-dir \"~/.config\" \"some-file\") \"~\")"
  (if directory
      `(let ((--directory-- ,directory))

                      collect (doom--resolve-path-forms i directory))))
        ((or (symbolp spec)
             (listp spec))
         `(let ((--file-- ,(if (and directory
                                    (or (not (stringp directory))
                                        (file-name-absolute-p directory)))
                               `(expand-file-name ,spec ,directory)
                             spec)))
            (and (file-exists-p --file--)
                 --file--)))
        (spec)))

(defun doom--resolve-hook-forms (hooks)
  (declare (pure t) (side-effect-free t))
