How to integate anything-occur within isearch mode
I like anything.el
a lot. The anything UI is wonderful.
I also use isearch
very often, and it provides the keybinding M-s o to invoke occur
using the isearch
inpu开发者_运维知识库t string. But native occur mode is not powerful enough.
In occur-mode
you cannot filter result again. And jumping function is basic too.
I find anything-occur
is more powerful than occur
, you can filter result, jump a position in anything style.
But there is a problem , How to integrate anything-occur
? My last attempt is:
(defun occur-in-isearch ()
(interactive)
(let ((case-fold-search isearch-case-fold-search))
(occur (if isearch-regexp isearch-string (regexp-quote isearch-string)))))
I replace occur
with anything-occur
, but it is no use. anything-occur
is a defun which takes no parameters. I cannot pass the isearch string to anything-occur
.
How might I integrate anything-occur
? Or is there a better way to use anything-occur
within isearch-mode
?
I'm not a user of anything, but this code does 99% of what you want. The only caveat is that the initial input string doesn't get properly updated when you type backspace. I don't know why that is. Everything else works seems to work as expected.
(eval-after-load "isearch"
'(define-key isearch-mode-map (kbd "M-s o") 'isearch-anything-occur))
(defun isearch-anything-occur (regexp &optional nlines)
"isearch anything occur"
(interactive
;; from isearch-occur
(list
(cond
(isearch-word (concat "\\b" (replace-regexp-in-string
"\\W+" "\\W+"
(replace-regexp-in-string
"^\\W+\\|\\W+$" "" isearch-string)
nil t)
"\\b"))
(isearch-regexp isearch-string)
(t (regexp-quote isearch-string)))
(if current-prefix-arg (prefix-numeric-value current-prefix-arg))))
;; from occur-anything
(let ((anything-compile-source-functions
;; rule out anything-match-plugin because the input is one regexp.
(delq 'anything-compile-source--match-plugin
(copy-sequence anything-compile-source-functions))))
(anything :sources 'anything-c-source-occur
:input regexp
:buffer "*Anything Occur*")))
Very similar --
In Icicles, during Isearch hit S-TAB
. Hit RET
to accept the same search pattern, or edit it first and then hit RET
.
That opens Icicles search with all matches as the search contexts. To narrow/filter those contexts with a further pattern, just type more text.
To filter progressively with multiple patterns, hit M-SPC
between patterns. Cycle among the matches using C-down
(etc.) or complete to any of them or click C-mouse-2
on any of them in *Completions
.
http://www.emacswiki.org/emacs/Icicles_-_Isearch_Enhancements#IciclesSearchFromIsearch
精彩评论