reddit / emacs

How do I "describe" `scan-error`?

pedzsanReddit · 2022-12-25 17:48
`scan-error` is a symbol created in syntax.c that appears to have a documentation string of "Scan Error" and other properties. `describe-symbol` doesn't find it. `apropos` does. But this is really a more general question: how do I get the description of "errors"? `describe-*` doesn't seem to have anything appropriate.
your_sweetpea · 2022-12-25 22:59
The Emacs Lisp reference manual contains a "Standard Errors" appendix. This can either be accessed via `C-h R elisp RET` then navigating to the "Standard Errors" appendix, or online [here](https://www.gnu.org/software/emacs/manual/html_node/elisp/Standard-Errors.html). If you wish to access the properties apropros lists programmatically, you can use the noninteractive function `symbol-plist` to view a symbol's property list -- in this case it returns `(error-conditions (scan-error error) error-message "Scan error")` or `get` to get a specific entry from it (`(get 'scan-error 'error-message)` returns `"Scan error"`, for example). Looking at the function `define-error`, which is used to define new error types from elisp, it seems to just insert `'error-conditions` and `'error-message` entries into the symbol's plist, and `syntax.c` does the same thing, just manually, as follows: DEFSYM (Qscan_error, "scan-error"); Fput (Qscan_error, Qerror_conditions, pure_list (Qscan_error, Qerror)); Fput (Qscan_error, Qerror_message, build_pure_c_string ("Scan error")); It's worth noting the `message` argument to `define-error` seems to be allowed to be `nil`, leading to there being no `'error-message` entry, so you'd want to handle that case as well if you were to write such a `describe-error` function as you're talking about. EDIT: Oh, as an additional note, `'error-conditions` seems to be the "inheritance chain" of the error, or more specifically the list of symbols that can be used to catch the error, it looks like. So for `'scan-error` you could handle it by handling either `'error` or `'scan-error` in your condition-case.
ieure · 2022-12-26 00:30
Great answer!