Emacs .dir-locals.el - 设置键绑定 [英] Emacs .dir-locals.el - setting key bindings
问题描述
我不知道这是可能的,但是我想使用 .dir-locals.el
$ b
当然 .dir-locals.el
必须包含一个特殊的设置列表,所以我不能做:
(global-set-key [24 down]'move-text-down)
/ pre>
有没有办法我可以注入一个lambda来运行任意代码或其他方式来设置密钥绑定在
.dir-locals中。 el
?解决方案
eval
- 变量使您能够使用本地变量指定用于评估的任意elisp。
eg https://stackoverflow.com/a/7340962/324105
请参阅 EmacsWiki 了解更多详情。
请注意,这不是设置密钥绑定的特别有用的机制,因为使用所讨论的键盘映射的每个缓冲区都将受到影响。您可能会使用dir-local配置来启用具有该项目的特定键盘映射的次模式。或者,您可能会此方法适用于文件本地绑定(但是较小的模式会更好)。
这就是说...
相对最小的形式是
((nil。 (progn BODY))))))
与BODY
是要评估的表达式。当然,如果BODY
只是一个表达式,则不需要progn
。
因此,当您访问任何文件(有问题的目录)时,以下内容将显示一条消息:
((n。((eval。(messagehello)))))
dir-locals表单中的每个列表通常是主要模式符号,或
nil
(如上例所示),在这种情况下,设置适用于任何主要模式。
汽车还可以指定一个子目录字符串,在这种情况下,cdr是另一个具有适用于该子目录的设置的目录表单。
I'm not sure this is possible, but I'd like to setup some project specific key bindings by using
.dir-locals.el
Of course
.dir-locals.el
has to contain a special list of settings, so I can't do:(global-set-key [24 down] 'move-text-down)
Is there any way I can inject a lambda to run arbitrary code or some other way to set key bindings in
.dir-locals.el
?解决方案The
eval
pseudo-variable enables you to specify arbitrary elisp for evaluation with your local variables.e.g. https://stackoverflow.com/a/7340962/324105
See EmacsWiki for more details.
Note that this is not a particularly useful mechanism for setting key bindings, as every buffer using the keymap in question will be affected. You would probably be better off using the dir-local config to enable a minor mode with the specific keymap for that project. Alternatively, you might adapt this approach to file-local bindings (but a minor mode would be nicer).
That being said...
A fairly minimal form is
((nil . ((eval . (progn BODY)))))
withBODY
being the expressions to be evaluated. Of course ifBODY
is only a single expression, you do not needprogn
.The following therefore displays a message when you visit any file (under the directory in question):
((nil . ((eval . (message "hello")))))
The car of each list in the dir-locals form is generally a major mode symbol, or
nil
(as in the above example) in which case the settings apply in any major mode.The car can also specify a sub-directory string, in which case the cdr is another dir-locals form with settings applicable to that sub-dir.
这篇关于Emacs .dir-locals.el - 设置键绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!