“1 of n” result for Emacs search

前端 未结 4 1600
梦毁少年i
梦毁少年i 2021-01-02 22:16

When I use incremental search in emacs I can\'t know where I am in whole matches. In Chrome browser it says location using \"2 of 30\". How can I do that in Emacs?

4条回答
  •  春和景丽
    2021-01-02 22:43

    Add the following to your emacs init file. Despite the use of count-matches, it works very fast on my laptop. I have not tried it with very large files.

    (defun my-isearch-update-post-hook()
      (let (suffix num-before num-after num-total)
        (setq num-before (count-matches isearch-string (point-min) (point)))
        (setq num-after (count-matches isearch-string (point) (point-max)))
        (setq num-total (+ num-before num-after))
        (setq suffix (if (= num-total 0)
                         ""
                       (format " [%d of %d]" num-before num-total)))
        (setq isearch-message-suffix-add suffix)
        (isearch-message)))
    
    (add-hook 'isearch-update-post-hook 'my-isearch-update-post-hook)
    

提交回复
热议问题