Subject: Re: bug#40774: Error messages shouldn't be hidden when the user is idle

From: Juri Linkov <[email-masked]>
Date: Fri, 24 Apr 2020 01:16:36 +0300

> So the only change needed is that error messages can only be cleared
> from the echo area by the user doing some command. Otherwise they
> are collected and shown.

I see now what you mean.  This can be easily implemented with the
following patch.  So you can set `clear-message-function' to a function
that returns a non-nil, and the echo area won't be cleared.

Such predicate function could contain a complex logic, but for testing
you could use just:

  (setq clear-message-function (lambda () t))

diff --git a/src/xdisp.c b/src/xdisp.c
index 01f272033e..fb9def57ef 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -11825,18 +11825,23 @@ set_message_1 (ptrdiff_t a1, Lisp_Object string)
 void
 clear_message (bool current_p, bool last_displayed_p)
 {
+  Lisp_Object preserve = Qnil;
+
   if (current_p)
     {
-      echo_area_buffer[0] = Qnil;
-      message_cleared_p = true;
-
       if (FUNCTIONP (Vclear_message_function))
         {
           ptrdiff_t count = SPECPDL_INDEX ();
           specbind (Qinhibit_quit, Qt);
-          safe_call (1, Vclear_message_function);
+          preserve = safe_call (1, Vclear_message_function);
           unbind_to (count, Qnil);
         }
+
+      if (NILP (preserve))
+        {
+          echo_area_buffer[0] = Qnil;
+          message_cleared_p = true;
+        }
     }
 
   if (last_displayed_p)