Show the file name of theme when warning about lexical-binding cookie

* lisp/custom.el (custom--theme-load-file): New variable.
(load-theme): Set it to the theme file being loaded.
* lisp/files.el (internal--get-default-lexical-binding): Use
'custom--theme-load-file', if non-nil, to show the file name of a
theme which caused the lexbind warning.  Do not merge to master.
(Bug#81686)
This commit is contained in:
Eli Zaretskii 2026-08-30 10:14:18 +03:00
parent b115e349e3
commit d6381e5df9
2 changed files with 16 additions and 8 deletions

View file

@ -1338,6 +1338,9 @@ This variable cannot be set in a Custom theme."
:risky t
:version "24.1")
(defvar custom--theme-load-file nil
"File name of a theme being loaded.")
(defun load-theme (theme &optional no-confirm no-enable)
"Load Custom theme named THEME from its file and possibly enable it.
The theme file is named THEME-theme.el, in one of the directories
@ -1397,10 +1400,12 @@ Return t if THEME was successfully loaded, nil otherwise."
(equal (file-name-directory file)
(expand-file-name "themes/" data-directory))))
;; Theme is safe; load byte-compiled version if available.
(load (file-name-sans-extension file) nil t nil t))
(let ((custom--theme-load-file file))
(load (file-name-sans-extension file) nil t nil t)))
((with-temp-buffer
(insert-file-contents file)
(let ((hash (secure-hash 'sha256 (current-buffer))))
(let ((hash (secure-hash 'sha256 (current-buffer)))
(custom--theme-load-file file))
(when (or (member hash custom-safe-themes)
(custom-theme-load-confirm hash))
(eval-buffer nil nil file)

View file

@ -4304,6 +4304,7 @@ all the specified local variables, but ignores any settings of \"mode:\"."
(push elem file-local-variables-alist)))
(hack-local-variables-apply))))))
(defvar custom--theme-load-file)
(defun internal--get-default-lexical-binding (from)
(let ((mib (lambda (node) (buttonize node (lambda (_) (info node))
nil "mouse-2: Jump to Info node"))))
@ -4311,12 +4312,14 @@ all the specified local variables, but ignores any settings of \"mode:\"."
(and (stringp from)
(eql 0 (file-attribute-size (file-attributes from))))
(let ((source
(if (not (and (bufferp from)
(string-match-p "\\` \\*load\\*\\(-[0-9]+\\)?\\'"
(buffer-name from))
load-file-name))
from
(abbreviate-file-name load-file-name))))
(if custom--theme-load-file
(abbreviate-file-name custom--theme-load-file)
(if (not (and (bufferp from)
(string-match-p "\\` \\*load\\*\\(-[0-9]+\\)?\\'"
(buffer-name from))
load-file-name))
from
(abbreviate-file-name load-file-name)))))
(condition-case nil
(display-warning
`(files missing-lexbind-cookie