From 523e945a3ae2347bae556ec4fe367d03ffddf8f0 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 17 Jul 2020 01:08:30 -0400 Subject: [PATCH] Fix #3215: ripgrep reporting error code 2 on Windows Closes #3512 --- core/core-projects.el | 85 +++++++++++++++----------------- modules/completion/ivy/config.el | 10 ++-- modules/emacs/dired/config.el | 2 +- 3 files changed, 46 insertions(+), 51 deletions(-) diff --git a/core/core-projects.el b/core/core-projects.el index 9ec73353f..c6f20d391 100644 --- a/core/core-projects.el +++ b/core/core-projects.el @@ -11,9 +11,9 @@ Emacs.") "If non-nil, non-projects are purged from the cache on `kill-emacs-hook'.") (defvar doom-projectile-fd-binary - (or (cl-find-if #'executable-find '("fdfind" "fd")) - "fd") - "name of `fd-find' executable binary") + (cl-find-if #'executable-find (list "fdfind" "fd")) + "The filename of the `fd' executable. On some distros it's 'fdfind' (ubuntu, +debian, and derivatives). On most it's 'fd'.") ;; @@ -131,6 +131,11 @@ c) are not valid projectile projects." projectile-project-root-files) projectile-project-root-files-bottom-up nil))) + ;; Some utilities have issues with windows-style paths in MSYS, so emit + ;; unix-style paths instead. + (when IS-WINDOWS + (setenv "MSYS_NO_PATHCONV" "1")) + ;; HACK Don't rely on VCS-specific commands to generate our file lists. That's ;; 7 commands to maintain, versus the more generic, reliable and ;; performant `fd' or `ripgrep'. @@ -142,48 +147,38 @@ And if it's a function, evaluate it." (funcall projectile-generic-command vcs) projectile-generic-command)) - (cond - ;; If fd exists, use it for git and generic projects. fd is a rust program - ;; that is significantly faster than git ls-files or find, and it respects - ;; .gitignore. This is recommended in the projectile docs. - ((executable-find doom-projectile-fd-binary) - (setq projectile-generic-command - ;; `projectile-generic-command' doesn't typically support a function. - ;; My `doom--only-use-generic-command-a' advice allows this. I do it - ;; this way so that future changes to - ;; `projectile-globally-ignored-directories' are respected. - (lambda (_) - (concat (format "%s . -0 -H -E .git --color=never --type file --type symlink --follow" - (or (cl-find-if (if EMACS27+ - (doom-rpartial #'executable-find t) - #'executable-find) - '("fdfind" "fd")) - "fd")) - (cl-loop for dir in projectile-globally-ignored-directories - concat " -E " - concat (shell-quote-argument dir)) - (if IS-WINDOWS " --path-separator=//"))) - projectile-git-submodule-command nil - ;; ensure Windows users get fd's benefits - projectile-indexing-method 'alien)) - - ;; Otherwise, resort to ripgrep, which is also faster than find - ((executable-find "rg") - (setq projectile-generic-command - (lambda (_) - (concat "rg -0 --files --follow --color=never --hidden" - (cl-loop for dir in projectile-globally-ignored-directories - concat " --glob " - concat (shell-quote-argument (concat "!" dir))) - (if IS-WINDOWS " --path-separator //"))) - projectile-git-submodule-command nil - ;; ensure Windows users get rg's benefits - projectile-indexing-method 'alien)) - - ;; Fix breakage on windows in git projects with submodules, since Windows - ;; doesn't have tr - (IS-WINDOWS - (setq projectile-git-submodule-command nil))) + ;; `projectile-generic-command' doesn't typically support a function, but my + ;; `doom--only-use-generic-command-a' advice allows this. I do it this way so + ;; that projectile can adapt to remote systems (over TRAMP), rather then look + ;; for fd/ripgrep on the remote system simply because it exists on the host. + ;; It's faster too. + (setq projectile-git-submodule-command nil + projectile-indexing-method 'hybrid + projectile-generic-command + (lambda (_) + (let ((find-exe-fn + (if EMACS27+ + (doom-rpartial #'executable-find t) + #'executable-find))) + ;; If fd exists, use it for git and generic projects. fd is a rust + ;; program that is significantly faster than git ls-files or find, and + ;; it respects .gitignore. This is recommended in the projectile docs. + (cond + ((when-let + (bin (if (file-remote-p buffer-file-name nil t) + (cl-find-if find-exe-fn (list "fdfind" "fd")) + doom-projectile-fd-binary)) + (concat (format "%s . -0 -H -E .git --color=never --type file --type symlink --follow" + bin) + (if IS-WINDOWS " --path-separator=/")))) + ;; Otherwise, resort to ripgrep, which is also faster than find + ((funcall find-exe-fn "rg") + (concat "rg -0 --files --follow --color=never --hidden" + (cl-loop for dir in projectile-globally-ignored-directories + concat " --glob " + concat (shell-quote-argument (concat "!" dir))) + (if IS-WINDOWS " --path-separator /"))) + ("find . -type f -print0"))))) (defadvice! doom--projectile-default-generic-command-a (orig-fn &rest args) "If projectile can't tell what kind of project you're in, it issues an error diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index 4fdb082d2..378b335d7 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -278,11 +278,11 @@ evil-ex-specific constructs, so we disable it solely in evil-ex." "Change `counsel-file-jump' to use fd or ripgrep, if they are available." :override #'counsel--find-return-list (cl-destructuring-bind (find-program . args) - (cond ((executable-find doom-projectile-fd-binary) - (append (list doom-projectile-fd-binary - "--color=never" "-E" ".git" - "--type" "file" "--type" "symlink" "--follow") - (if IS-WINDOWS '("--path-separator=/")))) + (cond ((when-let (fd (executable-find (or doom-projectile-fd-binary "fd"))) + (append (list fd + "--color=never" "-E" ".git" + "--type" "file" "--type" "symlink" "--follow") + (if IS-WINDOWS '("--path-separator=/"))))) ((executable-find "rg") (append (list "rg" "--files" "--follow" "--color=never" "--hidden" "--no-messages") (cl-loop for dir in projectile-globally-ignored-directories diff --git a/modules/emacs/dired/config.el b/modules/emacs/dired/config.el index 0c4688b44..039898a83 100644 --- a/modules/emacs/dired/config.el +++ b/modules/emacs/dired/config.el @@ -162,7 +162,7 @@ we have to clean it up ourselves." (use-package! fd-dired - :when (executable-find doom-projectile-fd-binary) + :when doom-projectile-fd-binary :defer t :init (global-set-key [remap find-dired] #'fd-dired)