From 50947fd51202dbdd86b1cc677722ab2031c5050b Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 10 Apr 2025 14:36:43 +0300 Subject: [PATCH] Avoid warnings about lexbind cookies where they aren't needed * lisp/emacs-lisp/warnings.el (warning-inhibit-types): New variable. (display-warning): If TYPE matches 'warning-inhibit-types', don't display the warning, even if it's emitted during startup. * lisp/startup.el (normal-top-level): * lisp/savehist.el (savehist-mode): * lisp/url/url-cookie.el (url-cookie-parse-file): * lisp/recentf.el (recentf-load-list): * lisp/abbrev.el (read-abbrev-file): Bind 'warning-inhibit-types' to avoid warning about missing lexbind cookie when loading files that Emacs itself generates. --- lisp/abbrev.el | 3 ++- lisp/emacs-lisp/warnings.el | 11 ++++++++--- lisp/recentf.el | 3 ++- lisp/savehist.el | 4 +++- lisp/startup.el | 6 ++++-- lisp/url/url-cookie.el | 3 ++- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lisp/abbrev.el b/lisp/abbrev.el index 93eb086da7a..d2dc96fe5ca 100644 --- a/lisp/abbrev.el +++ b/lisp/abbrev.el @@ -225,7 +225,8 @@ about loading the abbrevs." (list (read-file-name (format-prompt "Read abbrev file" abbrev-file-name) nil abbrev-file-name t))) - (load (or file abbrev-file-name) nil quietly) + (let ((warning-inhibit-types '((files missing-lexbind-cookie)))) + (load (or file abbrev-file-name) nil quietly)) (setq abbrevs-changed nil)) (defun quietly-read-abbrev-file (&optional file) diff --git a/lisp/emacs-lisp/warnings.el b/lisp/emacs-lisp/warnings.el index 2e930f6bbc8..6c77d57a6ba 100644 --- a/lisp/emacs-lisp/warnings.el +++ b/lisp/emacs-lisp/warnings.el @@ -176,6 +176,9 @@ also call that function before the next warning.") "Format for displaying the warning type in the warning message. The result of formatting the type this way gets included in the message under the control of the string in `warning-levels'.") +;;;###autoload +(defvar warning-inhibit-types nil + "Like `warning-suppress-log-types', but intended for programs to let-bind.") (defun warning-numeric-level (level) "Return a numeric measure of the warning severity level LEVEL." @@ -277,9 +280,10 @@ disable automatic display of the warning or disable the warning entirely by setting `warning-suppress-types' or `warning-suppress-log-types' on their behalf." (if (not (or after-init-time noninteractive (daemonp))) - ;; Ensure warnings that happen early in the startup sequence - ;; are visible when startup completes (bug#20792). - (delay-warning type message level buffer-name) + (or (warning-suppress-p type warning-inhibit-types) + ;; Ensure warnings that happen early in the startup sequence + ;; are visible when startup completes (bug#20792). + (delay-warning type message level buffer-name)) (unless level (setq level :warning)) (unless buffer-name @@ -290,6 +294,7 @@ entirely by setting `warning-suppress-types' or (setq level new))) (or (< (warning-numeric-level level) (warning-numeric-level warning-minimum-log-level)) + (warning-suppress-p type warning-inhibit-types) (warning-suppress-p type warning-suppress-log-types) (let* ((typename (if (consp type) (car type) type)) (old (get-buffer buffer-name)) diff --git a/lisp/recentf.el b/lisp/recentf.el index 172ce704d93..09f3b046ef2 100644 --- a/lisp/recentf.el +++ b/lisp/recentf.el @@ -1362,7 +1362,8 @@ empty `file-name-history' with the recent list." ;; We do not want Tramp asking for passwords. (non-essential t)) (when (file-readable-p file) - (load-file file) + (let ((warning-inhibit-types '((files missing-lexbind-cookie)))) + (load-file file)) (and recentf-initialize-file-name-history (not file-name-history) (setq file-name-history (mapcar #'abbreviate-file-name diff --git a/lisp/savehist.el b/lisp/savehist.el index 2a5ffb8c904..f5e680196f7 100644 --- a/lisp/savehist.el +++ b/lisp/savehist.el @@ -205,7 +205,9 @@ histories, which is probably undesirable." ;; coding cookie to convey that information. That way, if ;; the user changes the value of savehist-coding-system, ;; we can still correctly load the old file. - (load savehist-file nil (not (called-interactively-p 'interactive))) + (let ((warning-inhibit-types '((files missing-lexbind-cookie)))) + (load savehist-file nil + (not (called-interactively-p 'interactive)))) (setq savehist-loaded t)) (error ;; Don't install the mode if reading failed. Doing so would diff --git a/lisp/startup.el b/lisp/startup.el index d3b5b2e3b66..230b50311c6 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -620,13 +620,15 @@ It is the default value of the variable `top-level'." dir) (while tail (setq dir (car tail)) - (let ((default-directory dir)) + (let ((default-directory dir) + (warning-inhibit-types '((files missing-lexbind-cookie)))) (load (expand-file-name "subdirs.el") t t t)) ;; Do not scan standard directories that won't contain a leim-list.el. ;; https://lists.gnu.org/r/emacs-devel/2009-10/msg00502.html ;; (Except the preloaded one in lisp/leim.) (or (string-prefix-p lispdir dir) - (let ((default-directory dir)) + (let ((default-directory dir) + (warning-inhibit-types '((files missing-lexbind-cookie)))) (load (expand-file-name "leim-list.el") t t t))) ;; We don't use a dolist loop and we put this "setq-cdr" command at ;; the end, because the subdirs.el files may add elements to the end diff --git a/lisp/url/url-cookie.el b/lisp/url/url-cookie.el index c2cbdf131cd..d8bf76647a0 100644 --- a/lisp/url/url-cookie.el +++ b/lisp/url/url-cookie.el @@ -73,7 +73,8 @@ telling Microsoft that." (defun url-cookie-parse-file (&optional fname) "Load FNAME, default `url-cookie-file'." ;; It's completely normal for the cookies file not to exist yet. - (load (or fname url-cookie-file) t t)) + (let ((warning-inhibit-types '((files missing-lexbind-cookie)))) + (load (or fname url-cookie-file) t t))) (defun url-cookie-parse-file-netscape (filename &optional long-session) "Load cookies from FILENAME in Netscape/Mozilla format.