2

I have the following in my .emacs

(defun find-in-workspace(term)
  (interactive "sSearchInWorkspace: \n")
  (grep-find (concat "grep -rnH --include=\*.{c,cpp,h} --include=-e '" term "' /home/workspaces/*")))

which is just a wrapper around grep-find so that it can search all the files in my workspace.

My problem is with the grep buffer. I would like to keep my cursor in the grep buffer's window when I select items from it so that I can quickly browse through the code, but selecting a line will automatically moves my cursor to the other window, which adds up in keystrokes when I have a list of over 5 items. Is there anyway I can build this functionality into this function, or change a setting for grep-find? I've been searching but haven't found a solution.

Mike DeRoy
  • 133
  • 7
  • What if you used `find-grep-dired` and from Dired `C-o` (this displays the file in another buffer, without moving the point to that buffer). –  Aug 06 '13 at 21:19

3 Answers3

1

There might be some options of grep behavior, that you might find if you dig in the lisp/progmodes/grep.el from the source, but I really think it might be better and easier to have a look of GrepPlus library which bring many enhancement of emacs grep.

Otherwise you could also use occur and see how you could customize it. In occur, when you are in the match buffer, you can it C-o instead of Ret, which will show in the other buffer the match you selected, keeping your cursor in the match buffer. Difference with grep, is that it only works with opened buffer. I'm rather sure grep+ might have the equivalent. You should have a look

AdrieanKhisbe
  • 3,899
  • 8
  • 37
  • 45
1

There are two functions for doing exactly what you want: previous-error-no-select and next-error-no-select.

Also, you may find useful next-error-follow-minor-mode.

juanleon
  • 9,220
  • 30
  • 41
1

See the functions next-error and previous-error. They leave the grep buffer, but they work from anywhere, so, for example, if you bind next-error to a convenient a key then you can keep pressing it and it will iterate over the grep buffer.

Tom
  • 7,515
  • 7
  • 38
  • 54
  • This is exactly what I was looking for, thank you so much! :) I have them binded to ctrl-tab and backtab for now. – Mike DeRoy Aug 07 '13 at 13:28
  • I tried to do that early but couldn't figure that out haha, been lurking on stackoverflow for years, but never noticed the checkmark. Thanks again! – Mike DeRoy Aug 07 '13 at 17:49