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 9180441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:03:22+00:00 2026-06-17T18:03:22+00:00

I am writing an elisp function that permanently binds a given key to a

  • 0

I am writing an elisp function that permanently binds a given key to a given command in the current major mode’s keymap. For example,

    (define-key python-mode-map [C-f1] 'python-describe-symbol)

The command and the key sequence are gathered interactively from the user. However, I am having trouble producing the name of the KEYMAP (e.g. ‘python-mode-map’) that corresponds to the current major mode.

I have tried the function (current-local-map), but this function returns the keymap object itself, rather than its name.

I understand that many major mode keymaps are named according to the convention ”major-mode-name’-mode-map’, however, this is not always the case (for example, python-shell-map), so I would rather my code not rely on this convention. (I am not even sure how to access the name of the current major mode).

The (define-key ...) is to be added to an init file, so although

(define-key (current-local-map) key command)

seems to work, it does not work as code on an initialization file.

  • 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. Editorial Team
    Editorial Team
    2026-06-17T18:03:23+00:00Added an answer on June 17, 2026 at 6:03 pm

    There is no direct way to find the name of the current local keymap—more precisely, the symbol to which its value is bound—because the keymap doesn’t even have to be bound to a symbol. However, mode keymaps typically are bound to a global symbol, and one can find which one it is by iterating through all symbols and stopping on the one whose value is eq to the keymap object.

    This has to look at all the symbols (although it does minimum work with each), but has the advantage of not relying on any particular naming convention.

    (defun keymap-symbol (keymap)
      "Return the symbol to which KEYMAP is bound, or nil if no such symbol exists."
      (catch 'gotit
        (mapatoms (lambda (sym)
                    (and (boundp sym)
                         (eq (symbol-value sym) keymap)
                         (not (eq sym 'keymap))
                         (throw 'gotit sym))))))
    
    
    ;; in *scratch*:
    (keymap-symbol (current-local-map))
    ==> lisp-interaction-mode-map
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn Lisp (elisp, actually), and I tried writing the following function
I'm writing an elisp module that requires an external text file. For the curious,
Writing a recursive function, I want one fn that executes when the list has
As part of learning ELisp, I am trying to make a function that makes
Writing a TCL script to match everything in between two key words Example: X509v3
I'm writing my own mode in Elisp. It's basically a simple crud application showing
As an Emacs beginner, I am working on writing a minor mode. My current
I'm writing an interactive function that I'd like to have remember the last argument
Writing htaccess that allows me to remove index.php from the URL can confuse search
Writing documentation in html requires some code examples. What to do with characters that

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.