Reputation: 143
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.
Upvotes: 2
Views: 387
Reputation: 7586
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.
Upvotes: 1
Reputation: 9380
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
.
Upvotes: 1
Reputation: 4058
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
Upvotes: 1