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