Zenspider gives us an excellent tip for extending incremental search. Add this to your emacs initialization:
1 2 3 4 5 6 | (define-key isearch-mode-map (kbd "C-o") (lambda () (interactive) (let ((case-fold-search isearch-case-fold-search)) (occur (if isearch-regexp isearch-string (regexp-quote isearch-string)))))) |
This adds an extra keybinding to interactive search (
C-s) that runsoccuron the current search string/regexp, immediately showing all hits in the entire buffer. I use it all the time now.
Seeing as how I run incremental searches subconsciously before even thinking about running occur, I can see myself using this shortcut constantly. I tried it on the emacs tutorial (C-h t):
C-s foo C-o

9 responses so far ↓
seems to be turned on by default in debian? I have this behaviour without turning it on…
For this tip’s likely original (uncredited) source — http://www.emacswiki.org/cgi-bin/wiki/OccurFromIsearch — and many other tips, check out the Emacs Wiki at http://www.emacswiki.org/ .
Sean, Thanks for the (likely) original source. I tried a quick google search to see if there were any other prior credits to be given, but I obviously didn’t spend enough time on that.
Nah, I probably would not have found it if I hadn’t picked it up off the wiki a long time ago, stuck it in my .emacs, and used it more-or-less constantly ever since.
That is a great tip that is new to me. Thanks!
The following maybe well-known tips (they are definately standard features on Emacs 22.0.90 “pretest”):
I also like pressing M-% to drop into query-replace. (I think creating this feature for Emacs 19 was a topic in Bob Glickstein’s Writing Gnu Emacs Extensions.)
I also like pressing M-e to edit the current isearch string non-incrementally.
I rebind C-s from isearch-forward to isearch-forward-regexp. (C-r is similar.) If I really need a non-regexp isearch, I either press C-u before C-s, or press M-r during the isearch.
The Emacs manual has some good information about these special bindings: (info “(emacs)Special Isearch”). I also recommend looking at (describe-function ‘isearch-mode) since it is not possible to get the mode map using the usual Ctrl-h key.
What other modes would be interesting to “drop into”? Regexp-builder to isearch and/or vice versa?
Have you seen this? It’s very similar only more sophisticated:
http://www.emacswiki.org/cgi-bin/emacs-en/Icicles_-_Search_Enhancements
Yes, I’ve seen the Icicles commands. If you can get used to them, more power to you.
[...] For a full listing of available isearch modifier keys, review the help for isearch (C-h f isearch-forward). It is also possible to add your own functions to the isearch-mode-map. Last month, we referenced a way to add occur to isearch. [...]
Thank You
Leave a Comment