简体   繁体   English

如何将键盘映射添加到 emulation-mode-map-alists? Emacs

[英]How can I add a keymap to the emulation-mode-map-alists? Emacs

I have made a keymap and added it to a minor mode:我制作了一个键盘映射并将其添加到次要模式:

(defvar my-keymap (make-sparse-keymap))
(progn
    (define-key my-keymap (kbd "C-c s") '(lambda() (interactive) (message "Hello World")))
)

(define-minor-mode my-keybindings-mode
    nil
    :global t
    :lighter " keys"
    :keymap my-keymap)

(add-to-list emulation-mode-map-alists '(my-keybindings-mode . my-keymap))

However, whenever I try to add it to the emulation-mode-map-alists by writing:但是,每当我尝试通过编写将其添加到emulation-mode-map-alists时:

(add-to-list emulation-mode-map-alists '(my-keybindings-mode. my-keymap))

I end up getting this error:我最终得到这个错误:

eval-region: Wrong type argument: symbolp, (evil-mode-map-alist)

However, whenever I try to add it to the emulation-mode-map-alists by writing:但是,每当我尝试通过编写将其添加到 emulation-mode-map-alists 时:

 (add-to-list emulation-mode-map-alists '(my-keybindings-mode. my-keymap))

I end up getting this error:我最终得到这个错误:

 Wrong type argument: symbolp, (evil-mode-map-alist)

That's because the first argument to add-to-list should be a symbol (quoted), like this:这是因为add-to-list的第一个参数应该是一个符号(引用),如下所示:

(add-to-list 'emulation-mode-map-alists ...)

Without that quote you're instead passing the evaluated value of the emulation-mode-map-alists variable.如果没有该引用,您将传递emulation-mode-map-alists变量的评估值。

Note that Ch f add-to-list tells you that it's a function , and in particular note that when any function is called, all of its arguments are evaluated.请注意, Ch f add-to-list告诉您它是function ,特别注意当任何 function 被调用时,它的所有 arguments 都会被评估。 This in turns tells you that in order to pass a symbol as an argument, you will need to quote it.这反过来告诉您,为了将符号作为参数传递,您需要引用它。

(Macros and special forms are trickier -- their arguments aren't evaluated automatically, but they might be choosing to evaluate some of them explicitly, so you always need to pay attention to the documentation to be sure of what you should be passing them. Functions are nice and consistent in this respect, however.) (宏和特殊的 forms 比较棘手——它们的 arguments 不会自动评估,但他们可能会选择明确评估其中的一些,因此您始终需要注意文档以确保您应该传递它们。但是,在这方面,函数很好且一致。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM