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

Improve documentation for embark integration #12

Closed
magthe opened this issue Mar 6, 2023 · 5 comments
Closed

Improve documentation for embark integration #12

magthe opened this issue Mar 6, 2023 · 5 comments

Comments

@magthe
Copy link

magthe commented Mar 6, 2023

The description for integrating with embark that I found in a ticket on consult doesn't seem to work, using embark-define-keymap results in an error and I'm told to use defvar-keymap. I made a naive attempt to use defvar-keymap, but it doesn't make any change to the list of embark actions.

(use-package consult-yasnippet
  :config
  (defvar-keymap embark-yasnippet-completion-actions
     :doc "Keymap for actions for yasnippets."
     :parent embark-general-map
     "y" #'consult-yasnippet-visit-snippet-file)
  (add-to-list 'embark-keymap-alist '(yasnippet . embark-yasnippet-completion-actions)))

I think it'd be a good idea to put a (working) snippet for embark integration into the README. (I think the same goes for the marginalia integration too, actually.)

@mohkale
Copy link
Owner

mohkale commented Mar 6, 2023

@magthe

Since that ticket was created embark went through a few refactorings and as you mentioned the snippet from their no longer works. For reference this is what I have in my config for embark:

(use-package consult-yasnippet
  :straight t
  :config
  (with-eval-after-load 'embark
    ;; Embark actions for `consult-yasnippet' and derivatives.
    (general-define-key
     :keymaps 'embark-yasnippet-completion-actions
     "d" 'consult-yasnippet-visit-snippet-file                                  ; NOTE: Binding differs from `ivy-yasnippet' which uses "v".
     "g" 'consult-yasnippet-visit-snippet-file                                  ; NOTE: Binding differs from `ivy-yasnippet' which uses "v".
     )

    (push '(yasnippet . embark-yasnippet-completion-actions)
          embark-keymap-alist))

  :general
  (:states '(insert normal)
   "C-M-i" 'consult-yasnippet))

I'd be more than happy to accept a PR adding more info to the README about embark integration.

marginalia integration too

There isn't anything in this project that's marginalia specific. We use consult and set an annotation function. If marginalia is installed it should integrate with whatever completion UI you're using. If not then it won't. I'd be happy to accept a PR describing this to the README as well, but am unsure what other integration you could be referring to 🤔.

@magthe
Copy link
Author

magthe commented Mar 6, 2023

I'll be happy to provide a PR as soon as I get something working. Unfortunately the snippet above doesn't work for me either, It seems that general-define-key doesn't create the keymap embark-yasnippet-completion-actions and nothing appears when I run embark-act.

I did try adding it to the keymap embark-consult-search-map and then it does show up (the code below makes it appear under "C y"), but neither consult-yasnippet nor consult-snippet-visit-snippet-file does anything when invoked on a partial or complete yasnippet key. ¯_(ツ)_/¯

(use-package consult-yasnippet
  :straight t
  :config
  (with-eval-after-load 'embark
    (general-def embark-consult-search-map
      "y" 'consult-yasnippet)))

@magthe
Copy link
Author

magthe commented Mar 6, 2023

marginalia integration too

There isn't anything in this project that's marginalia specific. We use consult and set an annotation function. If marginalia is installed it should integrate with whatever completion UI you're using. If not then it won't. I'd be happy to accept a PR describing this to the README as well, but am unsure what other integration you could be referring to thinking.

The ticket I linked to contains the following snippet under a heading "Marginalia".

(require 'marginalia)

(defun marginalia-annotate-yasnippet (cand)
  ;; NOTE: Maybe there's a less indirect way to do this :/.
  (when-let* ((cand (marginalia--full-candidate cand))
              (template (alist-get cand consult-yasnippet--snippets nil nil #'string-equal))
              (key (yas--template-key template)))
    (concat " " (propertize (concat "[" key "]")
                            ;; TODO: custom face
                            'face 'font-lock-type-face))))

(push '(yasnippet . marginalia-annotate-yasnippet) marginalia-annotators-light)
(push '(yasnippet . marginalia-annotate-yasnippet) marginalia-annotators-heavy)

All I meant was that it probably would be nice to also have this in the README of consult-yasnippet, assuming it still works, instead of hidden away in a closed ticket in the repo for consult.

@mohkale
Copy link
Owner

mohkale commented Mar 6, 2023

@magthe

All I meant was that it probably would be nice to also have this in the README of consult-yasnippet, assuming it still works

That shouldn't be necessary. All that does is suffix the snippet candidate with the short-string that expands to it. All candidates in consult-yasnippet do that now automatically (it was changed because otherwise you couldn't filter on the snippet key, only the snippet name).

@magthe
Copy link
Author

magthe commented Mar 9, 2023

As I'm not succeeding in hooking consult-yasnippet into embark I'm removing it from my configuration. I'll keep an eye on the project to see how it progresses, but as it is now I don't really have much use for it.

@magthe magthe closed this as completed Mar 9, 2023
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