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

`M-x rg` never finds matches using Emacs 28.1 on Mac #141

Closed slinkp closed 2 years ago

slinkp commented 2 years ago

I can repro this only on Mac. Works fine on Ubuntu.

When I use M-x rg with current master (c46c5167ac03f68fd6fee07972017282c62bc942) I always get rg finished with no matches found regardless of regexp, default directory, or file types.

When I copy/paste the exact command that was run into a terminal, I do get matches.

When I use M-x rg to do the same search in emacs running on ubuntu, I do get matches.

Steps to set up and repro :

Mac setup (not working)

MacOS 12.3.1, M1 macbook pro Emacs installed via homebrew:

brew tap d12frosted/emacs-plus
brew install emacs-plus@28 --with-native-comp --with-modern-papirus-icon

Ripgrep installed via homebrew: brew reinstall ripgrep

rg --version says

ripgrep 13.0.0
-SIMD -AVX (compiled)

Install rg.el in emacs. I use M-x straight-use-package rg

Ubuntu 21.10 setup (working)

Install emacs and ripgrep via apt-get.
emacs --version says GNU Emacs 27.1 rg --version says:

ripgrep 12.1.1
-SIMD -AVX (compiled)
+SIMD +AVX (runtime)

Install rg.el. I use M-x straight-use-package rg

To repro on both systems

mkdir -p ~/tmp
cat > ~/tmp/test.txt <<EOF
cats
dogs
hello world
birds
EOF

Open emacs Type M-x rg Enter birds for regex Accept default file type (everything) For directory enter ~/tmp

Result on Mac

Screen Shot 2022-05-19 at 11 16 15 AM

If I copy/paste that exact command from emacs into a terminal on mac, I do get results:

Pauls-MBP-2 :$ cd ~/tmp/
Pauls-MBP-2 tmp:$ /opt/homebrew/bin/rg --color=always --colors=match:fg:red --colors=path:fg:magenta --colors=line:fg:green --colors=column:none -n --column --type-add=gyp\:\*.gyp --type-add=gyp\:\*.gypi -i --heading --no-config -e birds
test.txt
4:1:birds
Pauls-MBP-2 tmp:$ echo $?
0

Result on Ubuntu (expected)

Screen Shot 2022-05-19 at 11 15 17 AM

slinkp commented 2 years ago

I wondered if it might be a difference between rg 13.0.0 and rg 12.1.1 but the output looks the same given the same input.

dajva commented 2 years ago

Thanks for the detailed report. I have no official support for Mac and no way to test so can't help much here, more than give some pointers for you to start debugging yourself. Ripgrep 13 should not be a problem in general since that is what is currently running in CI. Would be interesting if it reproduces on 12.1.1 on Mac and/or on emacs 27 on Mac for instance. That may give some leads.

I would also test if other compilation-mode derived modes work, like grep.el, or running the same ripgrep command via M-x compile. grep.el should support ripgrep these days, not sure if that made it into emacs 28 but if so, there should be some setting for it. So that would also be interesting to try since grep.el and rg.el are fairly similar in the architecture.

slinkp commented 2 years ago

Thanks for the troubleshooting tip! It appears that compile never finishes. It stays like this indefinitely:

Screen Shot 2022-05-20 at 1 51 47 PM

Interestingly, M-x grep seems to work. Given the same test directory & files, I can type M-x grep birds * <ENTER> with these results: Screen Shot 2022-05-20 at 1 56 38 PM

I'm going to see what else I can find out.

slinkp commented 2 years ago

I was able to install 27.1 on mac via homebrew, also disabling the native compilation to remove one more difference between platforms. Same behavior as reported.

ALso tried removing that and downloading the 28.1-4 binary from https://emacsformacosx.com/ Same behavior

slinkp commented 2 years ago

Here's a minimal repro:

M-x compile <ENTER> rg -e hello That hangs in the "Compiling" state, never shows any output. But only on my mac.

With any file or directory arg, it completes (either with matches or without, but it completes): M-x compile <ENTER> rg -e hello .

Any tips on debugging why compile gets stuck?

Is it possible it's waiting for EOF on stdin? M-x compile <ENTER> grep -e hello similarly hangs, but that's expected because it looks at stdin if no files are specified.

man ripgrep says this:

       ripgrep will automatically detect if stdin exists and search stdin for a regex
       pattern, e.g. ls | rg foo. In some environments, stdin may exist when it shouldn’t. To
       turn off stdin detection explicitly specify the directory to search, e.g. rg foo ./.

Similarly, if I copy the exact command line that's run by M-x rg, add a directory to the end, and pass that to M-x compile then it gets results.

dajva commented 2 years ago

Ah, great debugging. There is a fix for this on windows, maybe the same is needed for os X unless there is something specific with your system that is causing this behavior. Anyway, try changing 'windows-nt to 'darwin in this line and see how it works. A bit peculiar that no one else has reported this on for Mac but I think we could try this as a general solution if it works for you and handle any potential regressions if they show up.

slinkp commented 2 years ago

That works!! Thanks for the quick responses! I can ask around if I know anybody else willing to test it. So far the other mac emacs users I know are using other search packages.

slinkp commented 2 years ago

I reverted my local change and pulled latest master and it's working great now! THank you!!