在阅读邮件列表时,有人提到最好使用键绑定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-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)))))
所以这部<object-definitions>
分会变成:
(define-and-bind-text-object "<key>" "<start-regex>" "<end-regex>")