From ba62307cfb0633637cc1fa9351c942cf79f34b90 Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Fri, 9 Mar 2018 16:41:36 +0100 Subject: [PATCH] Show log suppression buttons in display-warning buffer * lisp/emacs-lisp/warnings.el (warning-suppress-warning): Define button. (warning-suppress-action): New function. (warning-suppress-log-warning): Define button. (warning-suppress-log-action): New function. (display-warning): Show buttons to allow permanent modification of warning-suppress-types and warning-suppress-log-types per warning. * etc/NEWS: Describe 'display-warning' button change. --- etc/NEWS | 10 +++++++++- lisp/emacs-lisp/warnings.el | 26 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 14926ba2e3..a36967d473 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -69,7 +69,15 @@ in your init file. However, if your init file changes the values of moved to the early init file (see above). -* Changes in Emacs 27.1 +* Changes in Emacs 27. + +--- +** Specific warnings can now be disabled from the warning buffer. +When a warning is displayed to the user, the resulting buffer now has +buttons which allow making permanent changes to the treatment of that +warning. Automatic showing of the warning can be disabled (although +it is still generated), or generation of the warning can be disabled +entirely. --- ** The new option 'tooltip-resize-echo-area' avoids truncating tooltip text diff --git a/lisp/emacs-lisp/warnings.el b/lisp/emacs-lisp/warnings.el index 489611d4d1..245cd3f39a 100644 --- a/lisp/emacs-lisp/warnings.el +++ b/lisp/emacs-lisp/warnings.el @@ -197,6 +197,21 @@ warning-suppress-p ;; we return t. some-match)) +(define-button-type 'warning-suppress-warning + 'action #'warning-suppress-action + 'help-echo "mouse-2, RET: Don't display this warning automatically") +(defun warning-suppress-action (button) + (customize-save-variable 'warning-suppress-types + (cons (list (button-get button 'warning-type)) + warning-suppress-types))) +(define-button-type 'warning-suppress-log-warning + 'action #'warning-suppress-log-action + 'help-echo "mouse-2, RET: Never generate this warning again") +(defun warning-suppress-log-action (button) + (customize-save-variable 'warning-suppress-log-types + (cons (list (button-get button 'warning-type)) + warning-suppress-types))) + ;;;###autoload (defun display-warning (type message &optional level buffer-name) "Display a warning message, MESSAGE. @@ -223,7 +238,12 @@ display-warning See the `warnings' custom group for user customization features. See also `warning-series', `warning-prefix-function' and -`warning-fill-prefix' for additional programming features." +`warning-fill-prefix' for additional programming features. + +This will also display buttons allowing the user to permanently +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). @@ -264,6 +284,10 @@ display-warning (insert (format (nth 1 level-info) (format warning-type-format typename)) message) + (insert " ") + (insert-button "Disable showing automatically" 'type 'warning-suppress-warning 'warning-type type) + (insert " ") + (insert-button "Never generate" 'type 'warning-suppress-log-warning 'warning-type type) (newline) (when (and warning-fill-prefix (not (string-match "\n" message))) (let ((fill-prefix warning-fill-prefix) -- 2.16.1.72.g5be1f00a9