2

I am writing an emacs package which provides some commands to the user. The user can run things like M-x foobar and M-x eggsspam. However, some of these commands can fail. As an example, without running M-x foobar once, M-x spameggs will make no sense and has to report an error.

What's the right way to signal such errors to the user? Should I use (message...) or (user-error ...) or something else?

1 Answer 1

4

You can use whatever you think is most appropriate for your context. There is no "right" way for all contexts.

  • message does not prevent continued processing of the current command. If you want to be sure the user sees the message, you can use sit-for or sleep-for (which see).

  • You can pop up a window, frame, or tooltip with a message. Like message, this does not, by itself, interrupt program execution.

  • user-error raises an error that is intended to be for a pilot (user) error, rather than an error of the program itself.

  • error raises an error that is (generally) intended for a programmatic error (e.g. division by zero, wrong number of arguments). In general, error is more general than user-error.

  • signal is more general than error.

See the Elisp manual, node Signaling Errors. See also node Error Debugging, where you can learn some of the behavior differences between user-error and error (see option debug-ignored-errors).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.