When I wrote about using Ugrep with Consult I hinted at the chance of having my custom command available in Embark as well.
Building on top of Consult is great. Much like
consult-git-grep
andconsult-ripgrep
, the integration with Embark is around the corner.
As Omar Antolín
Camarena
explained to me, though, it is not immediately obvious how to combine
mu-consult-ugrep
with Embark.
Consult async search commands are tricky to use as Embark actions, which is why there is an entire, nontrivial embark-consult package to set up the integration.
However, he kindly suggested the solution to my problem as well. I just had to add it to my setup:
(with-eval-after-load 'embark-consult
(setf (alist-get 'mu-consult-ugrep embark-target-injection-hooks)
'(embark-consult--prep-async embark--allow-edit))
(setf (alist-get 'mu-consult-ugrep embark-pre-action-hooks)
'(embark--unmark-target))
(setf (alist-get 'mu-consult-ugrep embark-around-action-hooks)
'(embark-consult--projectless embark--cd))
(keymap-set embark-consult-search-map "u" #'mu-consult-ugrep))
The above code lets me call mu-consult-ugrep
on the candidate at point with
C-. C u
, where C-.
corresponds to embark-act
while C
gives me access to embark-consult-search-map
. This approach complements my
regular usage of mu-consult-ugrep
via M-s u
, which I generally use
when what I am looking for is not the thing at point.
Note that C-. C u
can be just as easily replaced by M-s u M-n M-n
to leverage Emacs’ future history1 or even by a basic wrapper around mu-consult-ugrep
that would grab the
thing at point. This is Emacs, of course, so the user is in charge of their
preferences.
-
Type C-h i g
(emacs) Minibuffer History
RET to know more. ↩︎