Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Add `highlight-symbol-occur' #3

merged 1 commit into from

3 participants


Add a function to run `occur' for the symbol at point.

@jturner314 jturner314 Add `highlight-symbol-occur'
This function runs `occur' for the symbol at point.

@jturner314 If you use `iedit', you get his pretty much for free and you can edit in the iedit narrowed buffer.


Thanks for mentioning `iedit'. I didn't know about it. It is an awesome tool, and I just added it to my .emacs config.

Unfortunately, `iedit' does not provide one of `occur's most important benefits: the ability to view the source and matches in two different windows simultaneously. Often, I need more than just a couple of lines of context where I am making my edit, but just a couple lines of context suffice for the other matches. Also, `occur's separate window works better with using the mouse to navigate, which I often find to be more efficient than keyboard navigation when just viewing code.

As a result, I find `occur' to be useful in some situations where `iedit' would be less useful, and I think that adding a function to easily run `occur' on the symbol at point would be useful.

Again, thanks for pointing out `iedit'! It is another great tool to have in my toolbox.

@nschum nschum merged commit 5d9f339 into nschum:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 29, 2012
  1. @jturner314

    Add `highlight-symbol-occur'

    jturner314 authored
    This function runs `occur' for the symbol at point.
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 0 deletions.
  1. +10 −0 highlight-symbol.el
10 highlight-symbol.el
@@ -248,6 +248,16 @@ element in of `highlight-symbol-faces'."
(goto-char (beginning-of-thing 'symbol))
(query-replace-regexp (highlight-symbol-get-symbol) replacement))
+(defun highlight-symbol-occur (&optional nlines)
+ "Call `occur' with the symbol at point.
+Each line is displayed with NLINES lines before and after, or -NLINES
+before if NLINES is negative."
+ (interactive "P")
+ (if (thing-at-point 'symbol)
+ (occur (highlight-symbol-get-symbol) nlines)
+ (error "No symbol at point")))
(defun highlight-symbol-get-symbol ()
"Return a regular expression dandifying the symbol at point."
(let ((symbol (thing-at-point 'symbol)))
Something went wrong with that request. Please try again.