-
Notifications
You must be signed in to change notification settings - Fork 310
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
expand with no trigger key #998
Comments
Is there a way to expand snippets without pressing tab or any trigger key at all? |
I guess you could try something like (defun my-yas-try-expanding ()
(when yas-minor-mode (yas-expand)))
(add-hook 'post-command-hook #'my-yas-try-expanding) |
I'm coming from vim and UltiSnips where you can specify in the snippet definition whether a particular snippet should be auto-expanded. Would it be feasible to add such a feature here? I like auto-expansion, but making it global would either limit one's ability to write "normal" text or it would demand some really complex snippet keys lest it is accidentally typed (e.g. auto-expanding the latex figure snippet "fig" would make it hard to write plain text). |
@korsbo You can use the condition system for this. Something along the lines of (defun my-yas-try-expanding-auto-snippets ()
(when yas-minor-mode
(let ((yas-buffer-local-condition ''(require-snippet-condition . auto)))
(yas-expand))))
(add-hook 'post-command-hook #'my-yas-try-expanding-auto-snippets) Then put |
Nice one, thanks! |
I am trying this and getting EDIT: |
Sorry, I made a mistake, it should be
If this works, it's only by accident. |
Aaah that fixes everything.
Yes, it was working but still displaying the error in logs, but working. |
Just in case anyone else may find it useful: I had trouble using this in spacemacs since (defun my-yas-try-expanding-auto-snippets ()
(when (and (boundp 'yas-minor-mode) yas-minor-mode)
(let ((yas-buffer-local-condition ''(require-snippet-condition . auto)))
(yas-expand))))
(add-hook 'post-command-hook #'my-yas-try-expanding-auto-snippets) |
I'm finding this very useful. Could this be added to the main codebase rather than as a user configuration? |
Pending in #1048. I'll probably make a minor bug fix release in a month or so, before merging that. |
Thanks for this super useful function. Just a question. How do you could expand snippet only in certain modes? (e.g. issue #990 ) In the mentioned issue, the example is having something like this
and expand this text
into this
However, the idea is to do it typing no other character apart from (). Thanks for your help. |
@maikol-solis here's what I use. I think it's what you're looking for.
I have this filed under snippets/latex-mode so that it's expanded in latex mode only when editing a math environment. Note that you can also get this to work in other modes selectively. For instance, I have a .yas-parents file for org-mode so that this also works when I'm editing latex math in an org buffer. This an example of using the condition system. Also, a small nitpick. In the issue you reference you ask about only expanding inside a math environment. However, your recent question asks about only expanding within certain modes. To say mode is a bit misleading here. I don't believe there is any mode associated with being inside a tex math environment (though correct me if I'm wrong), |
Brilliant! This is exactly what I want it.
You are completely right. The idea is auto expand the triggers only when there is a math environment (inline or displayed) inside a latex document. Your solution is exactly what I intend to do. Thanks for the help. |
I found a minor glitch with this feature. |
Hello. This little function is very interesting. Whereas if i force the evaluation once it is fully started, I get no error. Do I have to add something, like waiting for something to be loaded before evaluating the function ? Thanks for the help ! |
No description provided.
The text was updated successfully, but these errors were encountered: