evil-anzu的简单替代(evil-ex-search only)

(defvar-local evil-ex-match-counter "")

(defun evil-ex-match-counter (&rest _)
  (let ((search-upper-case (null (evil-ex-pattern-ignore-case evil-ex-search-pattern))))
    (when-let* ((regexp (evil-ex-pattern-regex evil-ex-search-pattern))
                (total (how-many regexp (point-min) (point-max)))
                (current (how-many regexp (point-min) (point))))
      (setq evil-ex-match-counter (propertize (format "(%d/%d)" (1+ current) total) 'face 'shadow)))))

(advice-add 'evil-ex-start-search :after-until 'evil-ex-match-counter)
(advice-add 'evil-ex-search :after-while 'evil-ex-match-counter)

然后把 (evil-mode (:eval evil-ex-match-counter)) 放到 mode-line-format 里面合适的位置就行了。

顺便问下有人知道isearch-lazy-count实现的原理吗?本来是想把isearch-lazy-count移植到evil的,结果根本看不懂isearch的实现 :sweat_smile:

1 个赞