Is there a way to configure
C-g (or some other key?) to not be usable as normal input in any context, part of a key binding, etc, and instead have it quit in more contexts? e.g. I'd like
C-x C-g to quit immediately (instead of saying
C-x C-g is undefined, then quitting)
(advice-add #'undefined :override #'keyboard-quit)
It is a hack.
C-g isn't treated specially. Any undefined key will prompt the message "key is undefined". For example, with
C-c C-g and
C-c a both give you that message.
If you really need to change this behaviour, you can define
(global-set-key (kbd "C-x C-g") 'keyboard-quit)
For what you're asking, you'll need to do this for every prefix key, and new prefix keys can be created by you, or by add-on packages. Which means I don't think there's a straightforward way to impose this globally.
You might have better success if you can explain why this behaviour is a problem for you; then we might be able to find a more general solution.