unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juanma Barranquero <lekktu@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: martin rudalics <rudalics@gmx.at>,
	Emacs developers <emacs-devel@gnu.org>
Subject: Re: Delayed warnings
Date: Wed, 27 Apr 2011 02:55:57 +0200	[thread overview]
Message-ID: <BANLkTin8q6+-WOaxa73TAjjU5woV0wGYHQ@mail.gmail.com> (raw)
In-Reply-To: <AANLkTi=UM7BJeM+6rsJbRic6X6TAuS3mSZ4OeM-eV2jU@mail.gmail.com>

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)))))


    Juanma



2011-04-26  Juanma Barranquero  <lekktu@gmail.com>

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

2011-04-26  Juanma Barranquero  <lekktu@gmail.com>

	* 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")
 \f
+(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.")
+
+\f
 ;;;; 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	other threads:[~2011-04-27  0:55 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-20  5:44 Delayed warnings Juanma Barranquero
2011-03-21  8:01 ` martin rudalics
2011-03-21 12:01   ` Juanma Barranquero
2011-03-21 13:17     ` martin rudalics
2011-03-21 13:43       ` Eli Zaretskii
2011-03-21 18:06         ` martin rudalics
2011-03-21 14:48       ` Juanma Barranquero
2011-03-21 18:06         ` martin rudalics
2011-03-21 20:19           ` Juanma Barranquero
2011-03-21 22:05             ` Stefan Monnier
2011-03-22  7:59               ` martin rudalics
2011-03-22 11:59               ` Juanma Barranquero
2011-03-23 13:50               ` Jeff Sparkes
2011-03-25 13:10               ` Juanma Barranquero
2011-04-27  0:55                 ` Juanma Barranquero [this message]
2011-04-27  3:05                   ` Eli Zaretskii
2011-04-27 11:27                     ` Juanma Barranquero
2011-04-27 17:32                   ` Stefan Monnier
2011-04-27 22:11                     ` Juanma Barranquero
2011-04-28  0:40                       ` Stefan Monnier
2011-04-28  0:59                         ` Juanma Barranquero
2011-04-28 15:26                           ` Stefan Monnier
2011-04-28 16:22                             ` Juanma Barranquero
2011-04-28 18:39                               ` Stefan Monnier
2011-05-08 17:58                               ` Chong Yidong
2011-05-08 18:43                                 ` Juanma Barranquero
2011-05-09 14:15                                   ` Stefan Monnier
2011-05-09 18:28                                   ` Richard Stallman
2011-03-22  7:58             ` martin rudalics
2011-03-22 12:04               ` Juanma Barranquero

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BANLkTin8q6+-WOaxa73TAjjU5woV0wGYHQ@mail.gmail.com \
    --to=lekktu@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).