模式特定的或缓冲区本地的文本对象是邪恶的? [英] Mode-specific or buffer-local text objects in evil?

查看:159
本文介绍了模式特定的或缓冲区本地的文本对象是邪恶的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Emacs中的

Q:,如何在邪恶中为文本对象进行特定于模式的键绑定?



如下例所示,可以在特定模式下绑定特定状态中的密钥(正常,插入等):

 (evil-define-key'normal org-modea's​​ome-command)

但是,我不清楚如何将模式特定方式绑定到 evil-outer-text-objects-map (或其 -inner - 对应)。作为替代方案,还不清楚如何通过模式钩子以缓冲本地方式在这些映射中绑定密钥。



它看起来不像 evil-local-set-key 将会这样做,因为它期望一个状态(正常,插入等)作为其第一个参数,这与此任务无关。 p>

在这种情况下,还不清楚如何使用 local-set-key ,因为它需要一个键和一个命令作为参数,但不将地图作为参数。

解决方案

阅读邮件列表时,有人提到,最好放 eval-after-load 中的键绑定,而不是钩子,所以这里是:

 (eval-after-load< mode>
'(progn
< object-definition>))

对于定义新的文本对象,我必须从 @ gordon-gustafson推荐此功能

 (defmacro define-and-bind-text-object(key start-regex end-regex)
let((inner-name(make-symbolinner-name))
(外部名称(make-symbolouter-name))
`(progn
-define-text-object,内部名称(count&可选的结束类型)
(evil-select-paren,start-regex,end-regex beg end type count))
-define-text-object,外部名称(count&可选的结束类型)
(evil-select-paren,start-regex,end-regex beg end type count nil))
-key evil-inner-text-objects-map,key(quote,inner-name))
(define-key evil-outer-text-objects-map,key(quote,outer-name))) )

所以< object-definitions> 部分将成为:

 (define-and-bind-text-object< key>< start- regex>< end-regex>)


Q: in Emacs, how does one make mode-specific key bindings for text objects in evil?

One may bind a key in a specific state (normal, insert, etc.) in a specific mode as the following example demonstrates:

(evil-define-key 'normal org-mode "a" 'some-command)

However, it's not clear to me how to bind a key in a mode-specific way to evil-outer-text-objects-map (or its -inner- counterpart). As an alternative, it's also not clear how one might bind keys in these maps in a buffer-local way through a mode hook.

It doesn't look like evil-local-set-key will do it, because it expects a state (normal, insert, etc.) as its first argument, and that's not relevant to this task.

It's also not clear how to use local-set-key in this instance, because it expects a key and a command as arguments, but does not take a map as an argument.

解决方案

When reading the mailing list someone mentioned it is better to put keybindings in eval-after-load instead of hooks, so here it is:

(eval-after-load "<mode>"
  '(progn
     <object-definition>))

As for defining new text objects, I must recommend this function from @gordon-gustafson:

(defmacro define-and-bind-text-object (key start-regex end-regex)
  (let ((inner-name (make-symbol "inner-name"))
        (outer-name (make-symbol "outer-name")))
    `(progn
      (evil-define-text-object ,inner-name (count &optional beg end type)
        (evil-select-paren ,start-regex ,end-regex beg end type count t))
      (evil-define-text-object ,outer-name (count &optional beg end type)
        (evil-select-paren ,start-regex ,end-regex beg end type count nil))
      (define-key evil-inner-text-objects-map ,key (quote ,inner-name))
      (define-key evil-outer-text-objects-map ,key (quote ,outer-name)))))

So the <object-definitions> part would become:

(define-and-bind-text-object "<key>" "<start-regex>" "<end-regex>")

这篇关于模式特定的或缓冲区本地的文本对象是邪恶的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆