8

I wrote an elisp function for myself at the weekend:

(defun rr-occur ()                                                                                                                                                                                                                                                                        
  "Run occur using the `word-at-point'."
  (interactive)                                                                                                                                                                                                                                                                           
  (let ((term (thing-at-point 'word t)))                                                                                                                                                                                                                                                  
    (occur term))) 

This seems such an obvious use-case, I am now wondering if this duplicates a "standard" function.

Drew
  • 75,699
  • 9
  • 109
  • 225
Realraptor
  • 1,253
  • 6
  • 17
  • Simplify it: (defun rr-occur () (occur (thing-at-point 'word t))). BTW, This has been requested of the emacs developers in the past; maybe try again, maybe this time they'll do it, eg. `C-u M-s o` – user1404316 Jun 28 '18 at 21:52

2 Answers2

10

There are a number of Emacs commands for which M-n at the input prompt (next-history-element) will insert a reasonable default if there is no next history element available. For occur that happens to be the symbol at point.

So this might do what you want: M-s o M-n

(You might have to hit M-n twice if you have a recent occur search provided as the first 'default').

glucas
  • 20,175
  • 1
  • 51
  • 83
6

A common workflow is:

sds
  • 5,928
  • 20
  • 39
  • 3
    You can also use `isearch-forward-symbol-at-point` for the first two steps, so the whole sequence would be: `M-s-. M-s-o`. – glucas Jun 26 '18 at 17:24