[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Delayed warnings

From: Juanma Barranquero
Subject: Re: Delayed warnings
Date: Wed, 27 Apr 2011 02:55:57 +0200

No decision was reached about delayed warnings, so I'm proposing
installing the attached patch.

It is basically a trio of variables:

- delayed-warnings-list: the list where desired warnigns are added.
- delayed-warnings-function: the function to show warnings and reset
`delayed-warning-list'. Defaults to `display-delayed-warnings'.
- delayed-warnings-filter: a function that sould be called from
`delayed-warnings-function' to filter out unwanted messages.

plus one function:

- display-delayed-warnings: Default value of
`delayed-warnings-function'. It calls `display-warning' on the
warnings (after filtering them with `delayed-warnings-filter'), then
resets the warnings list to nil.

I think this is conveniently flexible, and allows the user to filter
out unwanted warnings with ease:

(lexical-let* ((unwanted '("unwanted warning 1" "unwanted warning 2" ...))
               (unwanted-re (regexp-opt unwanted)))
  (defun my-delayed-warnings-filter (warning)
    (let ((text (cadr warning)))
      (and (string-match-p unwanted-re text)
           (message "%s: %s" (car warning) text)))))


2011-04-26  Juanma Barranquero  <address@hidden>

        * subr.el (display-delayed-warnings): New function.
        (delayed-warnings-function, delayed-warnings-filter): New variables.

2011-04-26  Juanma Barranquero  <address@hidden>

        * keyboard.c (Qdelayed_warnings_function): Define.
        (command_loop_1): Run Qdelayed_warnings_function "hook" if
        Vdelayed_warnings_list is non-nil.
        (syms_of_keyboard) <Qdelayed_warnings_function>: DEFSYM it.
        (syms_of_keyboard) <delayed-warnings-list, delayed-warnings-function>:
        DEFVAR_LISP them.

=== modified file 'lisp/subr.el'
--- lisp/subr.el        2011-04-26 10:44:03 +0000
+++ lisp/subr.el        2011-04-27 00:01:44 +0000
@@ -1773,6 +1773,31 @@
   (eval-after-load file (read)))
 (make-obsolete 'eval-next-after-load `eval-after-load "23.2")
+(defun display-delayed-warnings ()
+  "Display delayed warnings in `delayed-warnings-list'.
+Warnings are filtered through `delayed-warning-filter' (which see).
+This is the default function for `delayed-warnings-function'."
+  (dolist (warning (nreverse delayed-warnings-list))
+    (unless (and delayed-warnings-filter
+                 (funcall delayed-warnings-filter warning))
+      (apply 'display-warning warning)))
+  (setq delayed-warnings-list nil))
+(defvar delayed-warnings-function 'display-delayed-warnings
+  "Function called to display delayed warnings.
+The function should access variables `delayed-warnings-list', containing
+the warnings waiting to be displayed, and `delayed-warnings-filter',
+a function used to filter out warnings.
+It is the responsibility of this function to clear `delayed-warnings-list'
+as needed.")
+(defvar delayed-warnings-filter nil
+  "Function to filter delayed warnings.
+It must be nil, meaning do not filter out any warning, or a function
+of one argument, a list (TYPE MESSAGE [LEVEL [BUFFER-NAME]]), which must
+return nil for warnings that should be displayed, non-nil otherwise.")
 ;;;; Process stuff.

 (defun process-lines (program &rest args)

=== modified file 'src/keyboard.c'
--- src/keyboard.c      2011-04-26 18:02:10 +0000
+++ src/keyboard.c      2011-04-26 23:47:10 +0000
@@ -267,6 +267,8 @@

 static Lisp_Object Qdeferred_action_function;

+static Lisp_Object Qdelayed_warnings_function;
 static Lisp_Object Qinput_method_exit_on_first_char;
 static Lisp_Object Qinput_method_use_echo_area;

@@ -1356,6 +1358,10 @@
       if (!NILP (echo_area_buffer[0]))
        resize_echo_area_exactly ();

+      /* If there are warnings waiting, process them.  */
+      if (!NILP (Vdelayed_warnings_list))
+        safe_run_hooks (Qdelayed_warnings_function);
       if (!NILP (Vdeferred_action_list))
        safe_run_hooks (Qdeferred_action_function);
@@ -1573,6 +1579,10 @@
       if (!NILP (echo_area_buffer[0]))
        resize_echo_area_exactly ();

+      /* If there are warnings waiting, process them.  */
+      if (!NILP (Vdelayed_warnings_list))
+        safe_run_hooks (Qdelayed_warnings_function);
       safe_run_hooks (Qdeferred_action_function);

       /* If there is a prefix argument,
@@ -11498,6 +11508,7 @@
   DEFSYM (Qpre_command_hook, "pre-command-hook");
   DEFSYM (Qpost_command_hook, "post-command-hook");
   DEFSYM (Qdeferred_action_function, "deferred-action-function");
+  DEFSYM (Qdelayed_warnings_function, "delayed-warnings-function");
   DEFSYM (Qfunction_key, "function-key");
   DEFSYM (Qmouse_click, "mouse-click");
   DEFSYM (Qdrag_n_drop, "drag-n-drop");
@@ -12069,6 +12080,14 @@
 whenever `deferred-action-list' is non-nil.  */);
   Vdeferred_action_function = Qnil;

+  DEFVAR_LISP ("delayed-warnings-list", Vdelayed_warnings_list,
+               doc: /* List of warnings to be displayed as soon as possible.
+Each element must be a list (TYPE MESSAGE [LEVEL [BUFFER-NAME]]),
+as per the args of `display-warning' (which see).
+If this variable is non-nil, `delayed-warnings-function' will be called
+immediately after running `post-command-hook'.  */);
+  Vdelayed_warnings_list = Qnil;
   DEFVAR_LISP ("suggest-key-bindings", Vsuggest_key_bindings,
               doc: /* *Non-nil means show the equivalent key-binding when
M-x command has one.
 The value can be a length of time to show the message for.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]