Skip to content

Commit

Permalink
Allow running rg from Dired on root directory
Browse files Browse the repository at this point in the history
Previously if you opened a Dired buffer to the root directory of your
filesystem and attempted to use rg, rg-project-root would get a nil
value for FILE. All of the backends would fail to provide a project
root, so rg-project-root would fall back on asking for the directory
that contains FILE. Unfortunately, in this case FILE is unset. The
problem is solved by handling the cases where FILE is nil (or doesn't
have a directory component), and defaulting to default-directory.
  • Loading branch information
raxod502 authored and dajva committed Dec 30, 2019
1 parent 0a7f4d6 commit 2b01b8b
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions rg.el
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,10 @@ If LITERAL is non nil prompt for literal string. DEFAULT is the default pattern
(let ((project (project-current)))
(when project
(car (project-roots project)))))
(condition-case nil
(let* ((file (or file default-directory))
(backend (vc-responsible-backend file)))
(vc-call-backend backend 'root file))
(error (progn
(file-name-directory file))))))
(let ((file (expand-file-name (or file default-directory))))
(condition-case nil
(vc-call-backend (vc-responsible-backend file) 'root file)
(error (file-name-directory file))))))

(defun rg-run (pattern files dir &optional literal confirm flags)
"Execute rg command with supplied PATTERN, FILES and DIR.
Expand Down

0 comments on commit 2b01b8b

Please sign in to comment.