Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 133837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:30:17+00:00 2026-05-11T06:30:17+00:00

Most emacs modes include some sort of prefix to activate their features. For example,

  • 0

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)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:30:18+00:00Added an answer on May 11, 2026 at 6:30 am

    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:

    M-g ESC         Prefix Command M-g g           goto-line M-g n           next-error M-g p           previous-error 

    When you run M-x semi-modal-minor-mode, it will prompt you for some keystrokes. If you enter M-g n, then the following keybindings are set:

    ESC         Prefix Command   (same as M-g ESC) g           goto-line n           next-error p           previous-error 

    So now n doesn’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 for M-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:

    (defvar semi-modal-minor-mode-keymap (make-sparse-keymap)   'keymap holding the prefix key's keymapping, not really used') (defvar semi-modal-minor-mode-disable-key (kbd '<f12>')   'key to disable the minor mode') (defun semi-modal-minor-mode-disable ()   'disable the minor mode'   (interactive)   (semi-modal-minor-mode 0))  (define-minor-mode semi-modal-minor-mode   'local minor mode that prompts for a prefix key and promotes that keymap to the toplevel e.g. If there are bindings like the following:  M-g ESC         Prefix Command M-g g           goto-line M-g n           next-error M-g p           previous-error  And you enter 'M-g n' when prompted, then the minor mode keymap has the bindings   g   ->   goto-line   n   ->   next-error   p   ->   previous-error   ESC ->   Prefix Command (same as M-g ESC)  The variable semi-modal-minor-mode-disable-key is bound to disable the minor mode map. This is provided because often the mappings make the keyboard unusable. Use at your own risk.'   nil ' Semi' semi-modal-minor-mode-keymap   (make-local-variable 'semi-modal-minor-mode)   (make-local-variable 'minor-mode-map-alist)   (let ((pair-holding-keymap-to-modify (assq 'semi-modal-minor-mode minor-mode-map-alist)))     (setcdr pair-holding-keymap-to-modify (make-sparse-keymap))     (if semi-modal-minor-mode         (let (key               keymap)           ;; all but last (b/c we want a prefix           (setq key (substring (read-key-sequence 'Enter a full key combination, the prefix will be used: ') 0 -1))           (if (and (not (equal '' key))                    (not (equal (kbd 'C-g') key))                    (let ((semi-modal-minor-mode nil))                      (keymapp (setq keymap (key-binding key)))))               (progn                 (setcdr pair-holding-keymap-to-modify (copy-keymap keymap))                 (when semi-modal-minor-mode-disable-key                   (define-key (cdr pair-holding-keymap-to-modify)                     semi-modal-minor-mode-disable-key 'semi-modal-minor-mode-disable)))             (semi-modal-minor-mode 0)))))) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is your single most useful example of using dired mode in Emacs? Any
I'm using js2-mode for working with javascript in emacs and for the most part
I love using GDB withing emacs. And I most like the configuration that I
I'm using emacs in TTY mode ( -nw ), and I can use most
I'm using the actionscript-mode-connors.el for indenting Actionscript 3 code in emacs. I have most
I've recently started using emacs and I'm enjoying using it for the most part.
Most program languages have some kind of exception handling; some languages have return codes,
Most of my users have email addresses associated with their profile in /etc/passwd .
How can I set Emacs gdb so that it shows the most recent command
I have just started using Emacs for the specific purpose of editing latex documents.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.