4

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.

  • 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
5

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').

4

A common workflow is:

  • 1
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.