-
Notifications
You must be signed in to change notification settings - Fork 3
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
Feature Request: Support for calling snippet from any table, not just the currently active buffer #4
Comments
Hmmm... I don't really mind adding this but we may have to consider how to present it. Atm the format for candidates is "%(template-name)s [%(template-key)]". If we're supporting across all snippet tables then we should to include the name of the snippet table as well because otherwise there'll be a lot of overlap across languages. Do you have any suggestions for this? Cause simply prefixing the candidate with the table name doesn't seem ideal to me. |
I definitely agree. Perhaps the |
Issue with that is you can't filter on annotations :/. But I think if we just add it as hidden text before what we already show and then have annotations showing it as well it could work. Kind of a hacky solution but better than nothing. |
Closes #4 + Make consult-yasnippet read the template in the function body, instead of the interactive statement. + Change the function signature of consult-yasnippet to an optional argument that triggers the reading of snippets from all snippet tables. + Add consult-yasnippet--annotate, which suffixes each candidate with name of the snippet table it came from.
I've implemented this on the all-tables branch. Now consult-yasnippet takes an optional argument which causes snippets to be loaded from all snippet tables. You can do Please try it out and let me know whether it works and meets what you wanted from this issue. Note: If you still want a dedicated command for this instead of an option for the existing consult-yasnippet command you can simply add the following to your config: (defun consult-yasnippet-all ()
(interactive)
(consult-yasnippet 1)) |
This is fantastic, thank you! The only issue I notice is that when I try to load snippets from all tables, the new function only loads those tables whose major mode has been used before in the current emacs session. For example, if I start emacs, calling the function with a prefix arg will give me snippets from Were you planning to extend this feature to Thanks again! |
Closes #4 + Make consult-yasnippet read the template in the function body, instead of the interactive statement. + Change the function signature of consult-yasnippet to an optional argument that triggers the reading of snippets from all snippet tables. + Add consult-yasnippet--annotate, which suffixes each candidate with name of the snippet table it came from.
I actually just noticed that I cannot use your embark command when I generate the |
Looks like yas defers the loading of snippets for modes that haven't been required. Not much we can do about that, if it really bothers you you can add
I tested this yesterday and it was working, but it isn't now. I don't really know why. @oantolin could you help me understand why this is happening? For your convenience here's a minimal reproducible config. (defun foo (&optional arg)
(consult--read
(if arg
'(("e" . 5)
("f" . 6)
("g" . 7)
("h" . 8))
'(("a" . 1)
("b" . 2)
("c" . 3)
("d" . 4)))
:prompt "Foo: "
:lookup 'consult--lookup-cdr
:category 'foo))
(defun bar (it)
(interactive (list (foo)))
(message "%s" it))
(embark-define-keymap embark-foo-completion-actions
"Embark actions for `foo' and derivatives."
("d" bar))
(push '(foo . embark-foo-completion-actions)
embark-keymap-alist)
(defun baz (arg)
(interactive "P")
(when-let ((it (foo arg)))
(message "baz: %s" it)))
(global-set-key (kbd "M-'") #'baz) If you run |
In the code above, Notice that |
I'm not well aware of how embark is implemented but I'm not sure why that's an issue. Consult already has all the candidates by the time I call embark doesn't it? Does embark recall the function and regenerate the candidates or something like that? Either way how would you recommend implementing a action that can be shared across slightly different caller functions. In the case of this issue |
No command is called twice. Let me explain again with more detail what happens in the example you gave above (by the way, thanks for the small example, since reading it is much easier for me than diving into this package). When you call Now embark can use any function as an action and respects it's interactivity, that is, interactive functions are called interactively (and other functions are called via a normal function call). Since Does that make sense? Embark just runs the action interactively and inserts the target at the first minibuffer prompt created by the target. In this example, that winds up inserting the target, which was e, f, g or h, at the |
The issue wasn't really the prefix-arg but simply that This has nothing to do with Embark, actually: try running |
Maybe the cheapest way to fix this is to make (defun consult-yasnippet-visit-snippet-file (template)
"Visit the snippet file associated with TEMPLATE.
When called interactively this command previews snippet completions in
the current buffer, and then opens the selected snippets template file
using `yas--visit-snippet-file-1'."
(interactive (list (consult-yasnippet--read-template
(append (consult-yasnippet--candidates)
(consult-yasnippet--all-candidates)))))
(yas--visit-snippet-file-1 template)) It will look a little funny if called directly as a command (since the current buffer templates will be listed twice: once with an invisible prefix), but if you use it as an Embark action you never see its completion candidates! |
You know, maybe you could always use a big list of all templates from all tables, and allow consult-narrowing to the current buffer templates. You could remove |
Closes #4 + Make consult-yasnippet read the template in the function body, instead of the interactive statement. + Change the function signature of consult-yasnippet to an optional argument that triggers the reading of snippets from all snippet tables. + Add consult-yasnippet--annotate, which suffixes each candidate with name of the snippet table it came from.
Okay, your expanded example helps make things a lot easier to understand. Thank you very much. Always nice to get a better understanding of how something you use day-to-day works under the hood. 😄. I've managed to fix the issue using what you've shared. Firstly now the table-name is always included in a candidate (since even in the current-mode it may have multiple table names, meaning it should make the interface more powerful). And I've changed Could you try the current all-tables branch. I've tested and everythings working for me, I'd just like a confirmation before merging. Once again, thanks @oantolin. 😀. |
Closes #4 + Make consult-yasnippet read the template in the function body, instead of the interactive statement. + Change the function signature of consult-yasnippet to an optional argument that triggers the reading of snippets from all snippet tables. + Add consult-yasnippet--annotate, which suffixes each candidate with name of the snippet table it came from.
First of all, thank you for this package! One feature I've been after is the ability to search for a snippet in any Yasnippet table, not just those available in the current buffer. This same feature would also be helpful to visit any snippet you want to edit, regardless of the current buffer. Maybe passing a prefix argument to
consult-yasnippet
andconsult-yasnippet-visit-snippet-file
could accomplish this?The text was updated successfully, but these errors were encountered: