Fuco1 / smartparens

Minor mode for Emacs that deals with parens pairs and tries to be smart about it.
GNU General Public License v3.0
1.82k stars 195 forks source link

Add :no-enclosing-expression message #1161

Open tomdl89 opened 1 year ago

tomdl89 commented 1 year ago

I noticed quite a few commands fail with a generic error when point is not enclosed by a sexp. E.g. call sp-forward-barf-sexp when not inside parens, and you will see:

Wrong type argument: number-or-marker-p, nil

Because many commands call sp-get-enclosing-sexp which can return nil, and then subsequent operations try to do e.g. math with nil resulting in the above sort of error.

This PR adds a new sp-message error and tries to display that rather than the generic error, where possible. I gave up trying to run tests locally, but happy to be instructed if it's not too much effort :)

Fuco1 commented 1 year ago

The code which is wrapped with -when-let or when ok shouldn't give any errors because the body won't execute. Where it does, it probably misses the check and there it might be reasonable to handle it.

In non-interactive commands, we shouldn't display any errors because they might not be called by the user. Some of the functions can be called both interactively and non-interactively and this is quite a mess to handle.

Rather than adding the messages, I would handle the nil errors only.

tomdl89 commented 1 year ago

Hey @Fuco1 thanks for your reply. I'm not sure I understand it entirely.

Thanks again