Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Add `highlight-symbol-occur' #3

merged 1 commit into from over 1 year ago

3 participants

Jim Turner Le Wang Nikolaj Schumacher
Jim Turner

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

Jim Turner jturner314 Add `highlight-symbol-occur'
This function runs `occur' for the symbol at point.
Le Wang
lewang commented

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

Jim Turner

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.

Nikolaj Schumacher nschum merged commit 5d9f339 into from
Nikolaj Schumacher nschum closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jun 29, 2012
Jim Turner jturner314 Add `highlight-symbol-occur'
This function runs `occur' for the symbol at point.
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 10 additions and 0 deletions. Show diff stats Hide diff stats

  1. +10 0 highlight-symbol.el
10 highlight-symbol.el
@@ -248,6 +248,16 @@ element in of `highlight-symbol-faces'."
248 248 (goto-char (beginning-of-thing 'symbol))
249 249 (query-replace-regexp (highlight-symbol-get-symbol) replacement))
250 250
  251 +;;;###autoload
  252 +(defun highlight-symbol-occur (&optional nlines)
  253 + "Call `occur' with the symbol at point.
  254 +Each line is displayed with NLINES lines before and after, or -NLINES
  255 +before if NLINES is negative."
  256 + (interactive "P")
  257 + (if (thing-at-point 'symbol)
  258 + (occur (highlight-symbol-get-symbol) nlines)
  259 + (error "No symbol at point")))
  260 +
251 261 (defun highlight-symbol-get-symbol ()
252 262 "Return a regular expression dandifying the symbol at point."
253 263 (let ((symbol (thing-at-point 'symbol)))

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.