我发现有两种方法可以在emacs中设置密钥:global-set-key和define-key。 它们是一样的吗?或者这两种方法之间是否有任何利弊?
(global-set-key (kbd "C-c C-f") 'my-find-file)
(define-key global-map
"\C-ck" 'hello)
答案 0 :(得分:6)
如果你看一下global-set-key
你会看到的定义,实际上没有区别:
(define-key (current-global-map) key command)
(current-global-map)
可能会返回与global-key-map
不同的键盘映射,但不常见。
现在,由于define-key
采用了键映射的参数,因此它显然比简单global-set-key
更灵活。有关键盘映射的详细信息,请查看info pages。
答案 1 :(得分:2)
区别在于(global-set-key)
或(local-set-key)
为您找到全局/本地地图(在致电(define-key)
之前)。
修改您可以将M-x describe-function
用于(global-set-key)
(global-set-key key command)
Give key a global binding as command.
command is the command definition to use; usually it is
a symbol naming an interactively-callable function.
key is a key sequence; noninteractively, it is a string or vector
of characters or event types, and non-ASCII characters with codes
above 127 (such as ISO Latin-1) can be included if you use a vector.
适用于(define-key)
(define-key keymap key def)
In keymap, define key sequence key as def.
keymap is a keymap.
key is a string or a vector of symbols and characters meaning a
sequence of keystrokes and events. Non-ASCII characters with codes
above 127 (such as ISO Latin-1) can be included if you use a vector.
Using [t] for key creates a default definition, which applies to any
event type that has no other definition in this keymap.