Andreas, you might be interested in reading:
https://www.ics.uci.edu/~taylor/ics228/SynGen.pdf
and
Teitelbaum, T.; T. Reps (September 1981). "The Cornell Program
Synthesizer: A syntax-directed programming
environment". Communications of the ACM 24 (9):
563–573. doi:10.1145/358746.358755.
if you can get your hands on it.
Check also: https://en.wikipedia.org/wiki/Structure_editor
Basically, you could generate the whole mode all the structured editing
commands, from a grammar of the language you want to edit.
And since you could include in the grammar, grammars of other languages
when you have such escape, such as html scripts, or php, etc, you would
get automatically "multi-mode" structured editing modes.
Now, when you generate code (eg. a programming language compiler), it is
perfectly normal to have parts that are generated, and functions and
stubs that are written once for all for all the programs: a run-time
library.
Your code generate would naturally bind mode commands whose name would
be prefixed by the name of the grammar (= the mode), but the run-time
library would be the same for all those generated mode, and would have a
library prefix instead.