From 24d1c9ca25a29f35464089939cf36a7e1e31a0a3 Mon Sep 17 00:00:00 2001
From: Stefan Monnier <monnier@iro.umontreal.ca>
Date: Mon, 16 Dec 2024 09:27:01 -0500
Subject: * lisp/files.el (trusted-content-p): Make `:all` work in non-file
 buffers

(cherry picked from commit b9dc337ea7416ee7ee4d873a91f6d6d9f109c04c)
---
 lisp/files.el | 42 ++++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index 075d97c2a6c..a9a9bba5a7f 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -659,26 +659,28 @@ trusted-content-p
   ;; to try and avoid marking as trusted a file that's merely accessed
   ;; via a symlink that happens to be inside a trusted dir.
   (and (not untrusted-content)
-       buffer-file-truename
-       (with-demoted-errors "trusted-content-p: %S"
-         (let ((exists (file-exists-p buffer-file-truename)))
-           (or
-            (eq trusted-content :all)
-            ;; We can't avoid trusting the user's init file.
-            (if (and exists user-init-file)
-                (file-equal-p buffer-file-truename user-init-file)
-              (equal buffer-file-truename user-init-file))
-            (let ((file (abbreviate-file-name buffer-file-truename))
-                  (trusted nil))
-              (dolist (tf trusted-content)
-                (when (or (if exists (file-equal-p tf file) (equal tf file))
-                          ;; We don't use `file-in-directory-p' here, because
-                          ;; we want to err on the conservative side: "guilty
-                          ;; until proven innocent".
-                          (and (string-suffix-p "/" tf)
-                               (string-prefix-p tf file)))
-                  (setq trusted t)))
-              trusted))))))
+       (or
+        (eq trusted-content :all)
+        (and
+         buffer-file-truename
+         (with-demoted-errors "trusted-content-p: %S"
+           (let ((exists (file-exists-p buffer-file-truename)))
+             (or
+              ;; We can't avoid trusting the user's init file.
+              (if (and exists user-init-file)
+                  (file-equal-p buffer-file-truename user-init-file)
+                (equal buffer-file-truename user-init-file))
+              (let ((file (abbreviate-file-name buffer-file-truename))
+                    (trusted nil))
+                (dolist (tf trusted-content)
+                  (when (or (if exists (file-equal-p tf file) (equal tf file))
+                            ;; We don't use `file-in-directory-p' here, because
+                            ;; we want to err on the conservative side: "guilty
+                            ;; until proven innocent".
+                            (and (string-suffix-p "/" tf)
+                                 (string-prefix-p tf file)))
+                    (setq trusted t)))
+                trusted))))))))
 
 ;; This is an odd variable IMO.
 ;; You might wonder why it is needed, when we could just do:
