occur与isearch-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*"))






试用了一下,感觉和anything-regexp功能一样啊。请问有什么区别呢?
anything-regexp不能跳到相应的行,只是看一下正则表达式能够匹配上什么,这是我的理解。