Extending Emacs rgrep for Org Mode Only Search


I recently wanted to extend emacs rgrep to search within org files only. Here is what I came up with:

(defun jc/rgrep-org (regexp dir)
  "rgrep for org files only"
     (let* ((regexp (grep-read-regexp))
            (dir (read-directory-name "Base directory: "
                                      nil default-directory t)))
       (list regexp dir))))
  (rgrep regexp "*.org" dir nil))

Note that in order to get this jc/rgrep-org function to work, I had to study and borrow from the internals of rgrep. In particular, the interactive form was most inspired from studying grep.el.gz.
M-x find-function rgrep for more details.