70 lines
6.4 KiB
Plaintext
70 lines
6.4 KiB
Plaintext
<p>Look around this blog and you will find nice words about
|
||
<a href="https://github.com/BurntSushi/ripgrep">ripgrep</a>. I especially enjoy how I can
|
||
plug it into Emacs, like the time when I devised my own <a href="https://www.manueluberti.eu/emacs/2020/02/22/ripgrepping-with-helm/">Helm
|
||
commands</a>
|
||
for it.</p>
|
||
|
||
<p>However, roughly <a href="https://www.manueluberti.eu/emacs/2020/09/18/project/">a year
|
||
ago</a> I started my journey
|
||
to a more vanilla Emacs experience. During this time I have been slowly moving
|
||
away from the niceties of <code class="language-plaintext highlighter-rouge">ripgrep</code> in order to stick to a couple of built-in
|
||
tools: <code class="language-plaintext highlighter-rouge">rgrep</code> and <code class="language-plaintext highlighter-rouge">vc-git-grep</code>. Now, technically speaking, both this commands
|
||
rely on external tools, <code class="language-plaintext highlighter-rouge">grep</code> and <code class="language-plaintext highlighter-rouge">git grep</code>. Why should I use these instead of
|
||
<code class="language-plaintext highlighter-rouge">ripgrep</code>? Personal preferences, of course: <code class="language-plaintext highlighter-rouge">grep</code> is readily available on
|
||
Ubuntu and <code class="language-plaintext highlighter-rouge">git</code> is the first tool I install when upgrading to a new LTS
|
||
from Canonical<sup id="fnref:1"><a class="footnote" href="https://www.manueluberti.eu/feed#fn:1" rel="footnote">1</a></sup>.</p>
|
||
|
||
<p>Furthermore, I rarely need the power of <code class="language-plaintext highlighter-rouge">ripgrep</code>. Your experience may be
|
||
different on this, but the size of my projects does not scare neither <code class="language-plaintext highlighter-rouge">grep</code> nor
|
||
<code class="language-plaintext highlighter-rouge">git grep</code>. For instance, I regularly use <code class="language-plaintext highlighter-rouge">vc-git-grep</code> on Emacs sources, which
|
||
amounts to something like 2,755,361 lines of code<sup id="fnref:2"><a class="footnote" href="https://www.manueluberti.eu/feed#fn:2" rel="footnote">2</a></sup>, and the performances are
|
||
just fine for me.</p>
|
||
|
||
<p>The only thing I usually do not need from these commands is the prompt for the
|
||
file types to look into.</p>
|
||
|
||
<div class="language-emacs-lisp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="nb">defun</span> <span class="nv">mu-recursive-grep</span> <span class="p">(</span><span class="nv">search-term</span> <span class="nv">search-path</span><span class="p">)</span>
|
||
<span class="s">"Recursively search for SEARCH-TERM in SEARCH-PATH."</span>
|
||
<span class="p">(</span><span class="nv">interactive</span>
|
||
<span class="p">(</span><span class="k">progn</span>
|
||
<span class="p">(</span><span class="nb">unless</span> <span class="nv">grep-command</span>
|
||
<span class="p">(</span><span class="nv">grep-compute-defaults</span><span class="p">))</span>
|
||
<span class="p">(</span><span class="k">let</span> <span class="p">((</span><span class="nv">search-term</span> <span class="p">(</span><span class="nv">grep-read-regexp</span><span class="p">))</span>
|
||
<span class="p">(</span><span class="nv">search-path</span> <span class="p">(</span><span class="nv">expand-file-name</span>
|
||
<span class="p">(</span><span class="nv">read-directory-name</span>
|
||
<span class="s">"Directory: "</span> <span class="no">nil</span> <span class="nv">default-directory</span> <span class="no">t</span><span class="p">))))</span>
|
||
<span class="p">(</span><span class="nb">list</span> <span class="nv">search-term</span> <span class="nv">search-path</span><span class="p">))))</span>
|
||
<span class="p">(</span><span class="k">if</span> <span class="p">(</span><span class="nv">vc-root-dir</span><span class="p">)</span>
|
||
<span class="p">(</span><span class="nv">vc-git-grep</span> <span class="nv">search-term</span> <span class="s">"*"</span> <span class="nv">search-path</span><span class="p">)</span>
|
||
<span class="p">(</span><span class="nv">rgrep</span> <span class="nv">search-term</span> <span class="s">"*"</span> <span class="nv">search-path</span><span class="p">)))</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>I combined the two commands to make it simpler. When I am in a Git-versioned
|
||
project (i.e., <code class="language-plaintext highlighter-rouge">vc-root-dir</code> is not <code class="language-plaintext highlighter-rouge">nil</code>) <code class="language-plaintext highlighter-rouge">mu-recursive-grep</code> runs
|
||
<code class="language-plaintext highlighter-rouge">vc-git-grep</code>; otherwise, it’s time for <code class="language-plaintext highlighter-rouge">rgrep</code> to shine. As trivial as it might
|
||
look, the fact that the last two lines of <code class="language-plaintext highlighter-rouge">mu-recursive-grep</code> look similar is
|
||
what made it easier for me to devise a common wrapper. Emacs <code class="language-plaintext highlighter-rouge">describe</code> system
|
||
is always invaluable for discoveries such as this.</p>
|
||
|
||
<p>One last thing. When in a project, if I want to find where the thing at point is
|
||
used I do not need <code class="language-plaintext highlighter-rouge">mu-recursive-grep</code>. For this task <code class="language-plaintext highlighter-rouge">project-find-regexp</code>
|
||
(<kbd>C-x p g</kbd>) is enough<sup id="fnref:3"><a class="footnote" href="https://www.manueluberti.eu/feed#fn:3" rel="footnote">3</a></sup>, but <code class="language-plaintext highlighter-rouge">mu-recursive-grep</code> is still helpful
|
||
when I want to narrow the search down to a specific path.</p>
|
||
|
||
<h2 id="notes">Notes</h2>
|
||
|
||
<div class="footnotes">
|
||
<ol>
|
||
<li id="fn:1">
|
||
<p>I do it manually and I use Ansible Playbooks to set up the new system. <a class="reversefootnote" href="https://www.manueluberti.eu/feed#fnref:1">↩</a></p>
|
||
</li>
|
||
<li id="fn:2">
|
||
<p>That’s what <code class="language-plaintext highlighter-rouge">scc</code> tells me today, anyway. <a class="reversefootnote" href="https://www.manueluberti.eu/feed#fnref:2">↩</a></p>
|
||
</li>
|
||
<li id="fn:3">
|
||
<p><kbd>C-h v xref-search-program</kbd> shows that <code class="language-plaintext highlighter-rouge">ripgrep</code> can be used
|
||
instead of the default <code class="language-plaintext highlighter-rouge">grep</code>. Hence you can keep ripgrepping if that’s what
|
||
you prefer. <a class="reversefootnote" href="https://www.manueluberti.eu/feed#fnref:3">↩</a></p>
|
||
</li>
|
||
</ol>
|
||
</div> |