From: Stefan Monnier Date: Tue, 8 Apr 2025 17:10:30 +0000 (-0400) Subject: (internal--get-default-lexical-binding): Be more failsafe X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a6b8721511aa2fb94e4083bcaf15314cb14536b3;p=emacs.git (internal--get-default-lexical-binding): Be more failsafe * lisp/files.el (internal--get-default-lexical-binding): Try and avoid signaling an error. Make it easier to suppress the warning for a specific file. (cherry picked from commit 7ff674d7125452b0ce6a8d39cb667eacb90f3df2) --- diff --git a/lisp/files.el b/lisp/files.el index 22731e5789c..322245ea922 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -4291,24 +4291,31 @@ all the specified local variables, but ignores any settings of \"mode:\"." load-file-name)) from (abbreviate-file-name load-file-name)))) - (display-warning - '(files missing-lexbind-cookie) - (format-message "Missing `lexical-binding' cookie in %S. + (condition-case nil + (display-warning + `(files missing-lexbind-cookie + ,(if (bufferp source) 'eval-buffer source)) + (format-message "Missing `lexical-binding' cookie in %S. You can add one with `M-x %s RET'. See `%s' and `%s' for more information." - source - (buttonize "elisp-enable-lexical-binding" - (lambda (_) - (pop-to-buffer - (if (bufferp source) source - (find-file-noselect source))) - (call-interactively - #'elisp-enable-lexical-binding)) - nil "mouse-2: Add cookie") - (funcall mib "(elisp)Selecting Lisp Dialect") - (funcall mib "(elisp)Converting to Lexical Binding")) - :warning))) + source + (buttonize "elisp-enable-lexical-binding" + (lambda (_) + (pop-to-buffer + (if (bufferp source) source + (find-file-noselect source))) + (call-interactively + #'elisp-enable-lexical-binding)) + nil "mouse-2: Add cookie") + (funcall mib "(elisp)Selecting Lisp Dialect") + (funcall mib "(elisp)Converting to Lexical Binding")) + :warning) + ;; In various corner-case situations, `display-warning' may + ;; fail (e.g. not yet defined, or can't be (auto)loaded), + ;; so use a simple fallback that won't get in the way. + (error + (message "Missing `lexical-binding' cookie in %S" source))))) (default-toplevel-value 'lexical-binding))) (setq internal--get-default-lexical-binding-function