Delayed incremental occur with anything

occurisearch-forward-regexp相比的优势是能够看到所有的匹配结果,不足是不能随着输入动态更新匹配结果。配合使用anything.el,就可以两全其美。

(defun wl-anything-delayed-occur-candidates ()
  (setq anything-occur-buf (get-buffer-create "*Anything Occur*"))
  (with-current-buffer anything-occur-buf
    (erase-buffer)
    (let ((count (occur-engine anything-pattern
                               (list anything-c-source-occur-current-buffer)
                               anything-occur-buf
                               list-matching-lines-default-context-lines
                               (if (and case-fold-search search-upper-case)
                                   (isearch-no-upper-case-p anything-pattern t)
                                 case-fold-search)
                               list-matching-lines-buffer-name-face
                               nil list-matching-lines-face
                               (not (eq occur-excluded-properties t)))))
      (when (> count 0)
        (let ((lines (split-string (buffer-string) "n" t)))
          (cdr lines))))))

(defvar wl-anything-c-source-delayed-occur
  '((name . "Occur")
    (init . (lambda ()
              (setq anything-c-source-occur-current-buffer
                    (current-buffer))))
    (candidates . wl-anything-delayed-occur-candidates)
    (action . (("Goto line" .
                (lambda (candidate)
                  (goto-line (string-to-number candidate)
                             anything-c-source-occur-current-buffer)))))
    (requires-pattern . 3)
    (volatile)
    (delayed)))

(defun wl-search ()
  (interactive)
  (anything 'wl-anything-c-source-delayed-occur nil nil nil nil "*Anything Occur*"))

2 thoughts on “Delayed incremental occur with anything

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据