Q: how does one approximate the functionality of the non-existent
This question is inspired by the curiosity that is the combination of
self-insert-command. The docstring for the latter:
Insert the character you type.
Whichever character you type to run this command is inserted. Before insertion,
expand-abbrevis executed if the inserted character does not have word syntax and the previous character in the buffer does. After insertion, the value of
auto-fill-functionis called if the
auto-fill-charstable has a non-nil value for the inserted character. At the end, it runs
It looks to be the case that the call to
expand-abbrev is baked directly into
self-insert-command -- I assume for efficiency reasons, because it is ancient, or both (feel free to comment if you happen to know why). Ordinarily, I would have expected such a function to run via a hook. However, although there is a
post-self-insert-hook, there is no
In the absence of such a hook, how does one approximate that functionality, and, more importantly, do so with a minimum of fuss?
None of the options I can think of are ideal:
self-insert-commandis a primitive defined in C and therefore ignores advice
- pre-command-hook: simple, but it's overkill because it runs before every command, and not just
self-insert-command, and one may only want to run the command as part of
- define a wrapper around
self-insert-command: this appears to be what
sp--self-insert-command), but seems complicated by the fact that a) you'd need to rebind an awful lot of keys to use it, b) if one uses multiple major or minor modes that use their own wrapper functions, one needs to keep track of fallback functions so that one does not lose the functionality of other wrappers when rebinding keys (at least I think so; I'm not so sure I understand this part).