Emacs name of current local keymap?

后端 未结 3 419
无人共我
无人共我 2020-12-31 14:50

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 pytho         


        
相关标签:
3条回答
  • 2020-12-31 15:27

    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 讨论(0)
  • 2020-12-31 15:38

    Maybe you could try:

    (define-key (concat (symbol-name major-mode) "-map") [C-f1] 'python-describe-symbol)

    edit: Though this would yield the correct STRING, it should still be converted back to a symbol.

    0 讨论(0)
  • 2020-12-31 15:48

    The function local-set-key exists for the purpose of binding keys in the current local keymap.

    0 讨论(0)
提交回复
热议问题