Search code examples
functionemacsgrepelispfind-grep

EMACS find-grep command switching windows


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.


Solution

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