dajva / rg.el

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

Doesn't find project root when invoking rg-project in dired #50

Closed tom-bowles closed 5 years ago

tom-bowles commented 5 years ago

If you use rg-project when you're in dired, it searches the current directory rather than the project root. I was able to fix this locally by changing:

  ;; dir binding
  (unless (eq dir-opt 'ask)
    (let ((dirs (cond ((eq dir-opt 'project) '(rg-project-root
                                               buffer-file-name))
                      ((eq dir-opt 'current) 'default-directory)
                      (t dir-opt))))
      (setq binding-list (append binding-list `((dir ,dirs))))))

to:

  ;; dir binding
  (unless (eq dir-opt 'ask)
    (let ((dirs (cond ((eq dir-opt 'project) '(rg-project-root
                                               (or buffer-file-name default-directory)))
                      ((eq dir-opt 'current) 'default-directory)
                      (t dir-opt))))
      (setq binding-list (append binding-list `((dir ,dirs))))))

Great package, BTW - very handy indeed!

dajva commented 5 years ago

Thanks for the report. Seems as the problem is that we get a buffer-file-name that is nil in dired buffers which make rg-project-root fallback to default-directory. I don't think your solution will work for all project-root backends though. Which one are you using of find-file-in-project, projectile or vc-backend?

dajva commented 5 years ago

vc-backend should be the problematic backend here, the others doesn't use the file parameter at all. A bit strange organization of the function actually. Should be easy to fix for the other backends.

dajva commented 5 years ago

Should be fixed by 0ee0e385f5cef96e06cf0f0d1cebfe925aa2c075. Please try it out.

tom-bowles commented 5 years ago

Awesome, yes that fixes it! I'm using projectile, btw.