1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-28 07:45:00 +00:00

Improve command-error-function discoverability

* lisp/subr.el (error, user-error): Point to command-error-function.

* src/keyboard.c (syms_of_keyboard): Add an example (bug#40750).
This commit is contained in:
Lars Ingebrigtsen 2022-05-23 13:56:03 +02:00
parent a3fce23e3b
commit 250b728284
2 changed files with 16 additions and 2 deletions

View File

@ -441,7 +441,10 @@ To signal with MESSAGE without interpreting format characters
like `%', `\\=`' and `\\='', use (error \"%s\" MESSAGE).
In Emacs, the convention is that error messages start with a capital
letter but *do not* end with a period. Please follow this convention
for the sake of consistency."
for the sake of consistency.
To alter the look of the displayed error messages, you can use
the `command-error-function' variable."
(declare (advertised-calling-convention (string &rest args) "23.1"))
(signal 'error (list (apply #'format-message args))))
@ -457,7 +460,10 @@ To signal with MESSAGE without interpreting format characters
like `%', `\\=`' and `\\='', use (user-error \"%s\" MESSAGE).
In Emacs, the convention is that error messages start with a capital
letter but *do not* end with a period. Please follow this convention
for the sake of consistency."
for the sake of consistency.
To alter the look of the displayed error messages, you can use
the `command-error-function' variable."
(signal 'user-error (list (apply #'format-message format args))))
(defun define-error (name message &optional parent)

View File

@ -12863,6 +12863,14 @@ Called with three arguments:
- the context (a string which normally goes at the start of the message),
- the Lisp function within which the error was signaled.
For instance, to make error messages stand out more in the echo area,
you could say something like:
(setq command-error-function
(lambda (data _ _)
(message "%s" (propertize (error-message-string data)
\\='face \\='error))))
Also see `set-message-function' (which controls how non-error messages
are displayed). */);
Vcommand_error_function = intern ("command-error-default-function");