Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom command to embark-consult-search-map #663

Closed
manuel-uberti opened this issue Sep 18, 2023 · 9 comments
Closed

Add custom command to embark-consult-search-map #663

manuel-uberti opened this issue Sep 18, 2023 · 9 comments

Comments

@manuel-uberti
Copy link

Hi,

first of all thanks for Embark, such an awesome package. I have recently wrote a custom command, mu-consult-ugrep[1], which I'd like to add to embark-consult-search-map. I tried this:

(with-eval-after-load 'embark-consult
  (keymap-set embark-consult-search-map "u" #'mu-consult-ugrep))

However, when I hit C-. (embark-act) on a symbol and then hit C u nothing happens. There is no message in the minibuffer, no error, and I cannot act on that symbol any more.

I sure am missing something basic here, but I can't figure it out. :)


[1] https://manueluberti.eu/2023/09/16/consult-ugrep.html

@oantolin oantolin reopened this Sep 18, 2023
@manuel-uberti
Copy link
Author

Sorry, what?

@oantolin
Copy link
Owner

Sorry, weird clipboard bug. I will answer coherently soon.

@oantolin
Copy link
Owner

I wrote an answer in Emacs to paste here, but occasionally clipboard-sharing between the Linux vm in which Emacs runs and the main OS just stops working. So instead of getting that highly relevant answer you got some gobbledygook about the thing I was writing about before this issue.

@oantolin
Copy link
Owner

While the Linux VM restarts let me just say that 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. The particular problem of nothing seeming to happen is because Embark is pressing RET for you immediately.

@oantolin
Copy link
Owner

OK, here's the configuration you need:

(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))

In particular, the embark--allow-edit keeps Embark from automatically pressing RET.

@oantolin
Copy link
Owner

Check out the docstring of those functions used as hooks to see what each does, and feel free to ask me any questions.

@manuel-uberti
Copy link
Author

Fantastic, thank you for the quick reply and all the pointers.

@oantolin
Copy link
Owner

I must confess I didn't immediately remember the reasons I added all those hooks for consult async search commands. Rereading the code, the thing I didn't remember is that you can use consult-grep, etc. as an action on a directory and it will run in that directory with empty initial input. Same goes for a file or buffer, and it uses the directory containing the file or the default-directory of the buffer. Since I had forgotten this, I don't use this feature enough!

@manuel-uberti
Copy link
Author

manuel-uberti commented Sep 18, 2023

To be honest, I bound mu-consult-ugrep to M-s u so usually I can just do M-s u M-n M-n. But I have been using consult+embark more and more recently, so I thought I gave this a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants