vat等操作时看所要选的tag的开闭标签,如果两者的同一行的外侧有其他标签,行为和原版一样,否则选中头尾的整行。
;; if the open tag is the first in its line and the close tag is the last in its,
;; mark the whole lines containing the this tag pair
;; else only mark the tag pair
(evil-define-text-object jjpandari/evil-a-tag-dwim (count &optional beg end type)
"Select a tag block's whole lines."
:extend-selection nil
(let* ((point-list (evil-select-xml-tag beg end type count t))
(tag-beg (car point-list))
(tag-end (cadr point-list))
(line-beg (progn (goto-char tag-beg) (line-beginning-position))))
(if (and (looking-back "^\s*") (progn (goto-char tag-end) (looking-at "\s*$")))
(evil-range line-beg (line-end-position) 'line)
point-list)))
(define-key evil-outer-text-objects-map (kbd "t") 'jjpandari/evil-a-tag-dwim)
效果(|
表示cursor):
<div> <div>
<s|pan>text</span> =按下vat=> | <span>text</span>|
</div> </div>
<div> <div>
<s|pan>text</span></div> =按下vat=> |<span>text</span>|</div>
参考了原版evil-a-tag
和陈斌的evilmi-outer-text-object
。
还简单写了两个evil-a-attribute
,outer和inner区别只是outer多选中前面的一个空格,以下依赖web-mode:
(evil-define-text-object jjpandari/evil-a-attribute (count &optional beg end type)
"Select an attribute, including the leading space."
:extend-selection nil
(list (- (web-mode-attribute-beginning-position) 1)
(+ (web-mode-attribute-end-position) 1)))
(evil-define-text-object jjpandari/evil-inner-attribute (count &optional beg end type)
"Select an attribute."
:extend-selection nil
(list (web-mode-attribute-beginning-position)
(+ (web-mode-attribute-end-position) 1)))
(define-key evil-inner-text-objects-map (kbd "a") 'jjpandari/evil-inner-attribute)
(define-key evil-outer-text-objects-map (kbd "a") 'jjpandari/evil-a-attribute)