When I wrote about using Ugrep with Consult1 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 and consult-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.2

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.3 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)

  (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 history4 or even by a basic wrapper around mu-consult-ugrep that would grab the thing at point.5 This is Emacs, of course, so the user is in charge of their preferences.