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.
This commit is contained in:
Eli Zaretskii 2025-04-10 14:36:43 +03:00
parent 426a016d61
commit 50947fd512
6 changed files with 21 additions and 9 deletions

View file

@ -225,7 +225,8 @@ about loading the abbrevs."
(list (list
(read-file-name (format-prompt "Read abbrev file" abbrev-file-name) (read-file-name (format-prompt "Read abbrev file" abbrev-file-name)
nil abbrev-file-name t))) 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)) (setq abbrevs-changed nil))
(defun quietly-read-abbrev-file (&optional file) (defun quietly-read-abbrev-file (&optional file)

View file

@ -176,6 +176,9 @@ also call that function before the next warning.")
"Format for displaying the warning type in the warning message. "Format for displaying the warning type in the warning message.
The result of formatting the type this way gets included in the The result of formatting the type this way gets included in the
message under the control of the string in `warning-levels'.") 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) (defun warning-numeric-level (level)
"Return a numeric measure of the warning severity 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 entirely by setting `warning-suppress-types' or
`warning-suppress-log-types' on their behalf." `warning-suppress-log-types' on their behalf."
(if (not (or after-init-time noninteractive (daemonp))) (if (not (or after-init-time noninteractive (daemonp)))
;; Ensure warnings that happen early in the startup sequence (or (warning-suppress-p type warning-inhibit-types)
;; are visible when startup completes (bug#20792). ;; Ensure warnings that happen early in the startup sequence
(delay-warning type message level buffer-name) ;; are visible when startup completes (bug#20792).
(delay-warning type message level buffer-name))
(unless level (unless level
(setq level :warning)) (setq level :warning))
(unless buffer-name (unless buffer-name
@ -290,6 +294,7 @@ entirely by setting `warning-suppress-types' or
(setq level new))) (setq level new)))
(or (< (warning-numeric-level level) (or (< (warning-numeric-level level)
(warning-numeric-level warning-minimum-log-level)) (warning-numeric-level warning-minimum-log-level))
(warning-suppress-p type warning-inhibit-types)
(warning-suppress-p type warning-suppress-log-types) (warning-suppress-p type warning-suppress-log-types)
(let* ((typename (if (consp type) (car type) type)) (let* ((typename (if (consp type) (car type) type))
(old (get-buffer buffer-name)) (old (get-buffer buffer-name))

View file

@ -1362,7 +1362,8 @@ empty `file-name-history' with the recent list."
;; We do not want Tramp asking for passwords. ;; We do not want Tramp asking for passwords.
(non-essential t)) (non-essential t))
(when (file-readable-p file) (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 (and recentf-initialize-file-name-history
(not file-name-history) (not file-name-history)
(setq file-name-history (mapcar #'abbreviate-file-name (setq file-name-history (mapcar #'abbreviate-file-name

View file

@ -205,7 +205,9 @@ histories, which is probably undesirable."
;; coding cookie to convey that information. That way, if ;; coding cookie to convey that information. That way, if
;; the user changes the value of savehist-coding-system, ;; the user changes the value of savehist-coding-system,
;; we can still correctly load the old file. ;; 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)) (setq savehist-loaded t))
(error (error
;; Don't install the mode if reading failed. Doing so would ;; Don't install the mode if reading failed. Doing so would

View file

@ -620,13 +620,15 @@ It is the default value of the variable `top-level'."
dir) dir)
(while tail (while tail
(setq dir (car 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)) (load (expand-file-name "subdirs.el") t t t))
;; Do not scan standard directories that won't contain a leim-list.el. ;; Do not scan standard directories that won't contain a leim-list.el.
;; https://lists.gnu.org/r/emacs-devel/2009-10/msg00502.html ;; https://lists.gnu.org/r/emacs-devel/2009-10/msg00502.html
;; (Except the preloaded one in lisp/leim.) ;; (Except the preloaded one in lisp/leim.)
(or (string-prefix-p lispdir dir) (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))) (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 ;; 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 ;; the end, because the subdirs.el files may add elements to the end

View file

@ -73,7 +73,8 @@ telling Microsoft that."
(defun url-cookie-parse-file (&optional fname) (defun url-cookie-parse-file (&optional fname)
"Load FNAME, default `url-cookie-file'." "Load FNAME, default `url-cookie-file'."
;; It's completely normal for the cookies file not to exist yet. ;; 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) (defun url-cookie-parse-file-netscape (filename &optional long-session)
"Load cookies from FILENAME in Netscape/Mozilla format. "Load cookies from FILENAME in Netscape/Mozilla format.