Subject: bug#34939: Some minibuffer behaviour is annoying

From: Juri Linkov <[email-masked]>
Date: Thu, 30 May 2019 00:53:46 +0300

>>> So um, what's the best way to make this behavior the default?
>>
>> This is a nice behavior but the problem is that overriding
>> command-error-function also removes other useful default features
>> such as logging error messages to the *Messages* buffer
>> (see more at ‘print_error_message’).
>
> Could we first print it and then call minibuffer-message?

Here is a complete 1-to-1 rewrite of the C function ‘print_error_message’
in Lisp that now can be used for more user-friendly displaying error messages
in the minibuffer:
diff --git a/lisp/simple.el b/lisp/simple.el
index 4454791ad2..5f5c6b1a59 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2440,6 +2440,45 @@ minibuffer-history-isearch-pop-state
   (goto-history-element hist-pos))
 
 
+(add-hook 'minibuffer-setup-hook 'minibuffer-error-initialize)
+
+(defun minibuffer-error-initialize ()
+  "Set up minibuffer error processing."
+  (setq-local command-error-function 'minibuffer-error-function))
+
+(defun minibuffer-error-function (data context caller)
+  "Display output error messages in the active minibuffer.
+Its arguments are the same as in `command-error-default-function'."
+  (discard-input)
+  (ding)
+  (let* ((errname (car data))
+         errmsg file-error tail text
+         (sep ": "))
+    (cond
+     ((eq errname 'error)
+      (setq data (cdr data))
+      (when (consp data) (setq data nil))
+      (setq errmsg (car data)))
+     (t
+      (setq errmsg (substitute-command-keys (get errname 'error-message))
+            file-error (memq 'file-error (get errname 'error-conditions)))))
+    (setq tail (cdr-safe data))
+    (when (and file-error (consp tail))
+      (setq errmsg (car tail)
+            tail (cdr tail)))
+    (setq text (if (stringp errmsg) errmsg "peculiar error"))
+    (while tail
+      (setq text (concat text sep))
+      (if (or file-error (eq errname 'end-of-file) (eq errname 'user-error))
+          (setq text (concat text (format "%s" (car tail))))
+        (setq text (concat text (format "%S" (car tail)))))
+      (setq sep ", ")
+      (setq tail (cdr tail)))
+    (let ((inhibit-message t))
+      (message "%s%s" (if caller (format "%s: " caller) "") text))
+    (minibuffer-message (concat context text))))
+
+
 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
 (define-obsolete-function-alias 'advertised-undo 'undo "23.2")