Most emacs modes include some sort of prefix to activate their features. For example, when using GUD ‘next’ is ‘C-c C-n’. Of these modes, many provide special buffers where one can use a single key to activate some functionality (just ‘n’ or ‘p’ to read next/previous mail in GNUS for example).
Not all modes provide such a buffer, however, and repeatedly typing the prefix can be tiresome. Is there a well-known bit of elisp that will allow for ad-hoc specification of prefix keys to be perpended to all input for some time? (Until hitting ESC or some other sanctioned key, for example)
I agree with Joe Casadonte’s answer that the way to go is to define your own minor (or major) mode.
That being said, your question is interesting.
Here’s a solution that prompts you for a key sequence and it takes the prefix keystrokes and promotes that keymap to the top level.
e.g. Assume the following keymap:
When you run
M-x semi-modal-minor-mode, it will prompt you for some keystrokes. If you enterM-g n, then the following keybindings are set:So now
ndoesn’t self-insert, but jumps to the next error. See the code below.Note: when this minor mode is enabled,
<f12>is bound to a command which disables the minor mode. This is because the keybindings might very well disable your Emacs (for instance, what if there was a new keybinding forM-x).Edited to add these thoughts: the minor mode variable was originally made buffer local, but that doesn’t work unless you also make the minor-mode-alist variable buffer local (duh). But, you also (probably) don’t want these bindings in the minibuffer… So, I’m not going to test it b/c it really depends on what you want, but I’ve added a comment to the code reflecting this thought.
Without further ado: