dajva / rg.el

Emacs search tool based on ripgrep
https://rgel.readthedocs.io
GNU General Public License v3.0
465 stars 38 forks source link

Feature request: Support `rg-rerun-change-project` in rg-mode #165

Open sukiida opened 3 months ago

sukiida commented 3 months ago

Maybe the feature is already there and I'm not aware of it.

I'm working on a super project consists of many sub-projects. Usually I need to search through sub projects to trace a variable or something. It would be great if I can do it with rg-dwim, change project and rerun search. (I love the search and refine procedure.)

It is like rg-rerun-change-dir, but doesn't need so many keystrokes to navigate to the dest directory. Actually I have a piece of demo code work with projectile locally, still I would be happy to complete it and support other packages such as project.el etc. if you appove. Thnaks.

;; extend rg.el
;; add a rg-mode command to switch project and rerun search
(defun rg-rerun-change-project()
  "Rerun last search but prompt for new project."
  (interactive)
  (setf (rg-search-dir rg-cur-search)
           (let ((projects (projectile-relevant-open-projects)))
             (if projects
                 (projectile-completing-read
                  "Switch to open project: " projects)
               (rg-search-dir rg-cur-search))))
  (rg-rerun))

;; add to rg-mode key map
(define-key rg-mode-map "P" 'rg-rerun-change-project)