friendly-snippets icon indicating copy to clipboard operation
friendly-snippets copied to clipboard

Example of selectively applying snippets

Open danieleavitabile opened this issue 10 months ago • 1 comments

I use LuaSnip, and have developed a number of LaTeX snippets. I am now considering adopting friendly-snippets for other languages, while keeping exclusively my own LaTeX snippets for .tex files.

Is there a clear set of instructions for doing that? It's unclear to me whether the instructions for disabling snippets in the home page will disable all tex snippets (including mine) or will only disable the friendly-snippet latex snippets.

danieleavitabile avatar Apr 04 '24 19:04 danieleavitabile

Hi! You should be able do this by adding the following to your NeoVim config. require("luasnip.loaders.from_vscode").load { exclude = { "tex", "plaintex" }, }

AidenAllredOfficial avatar Apr 12 '24 14:04 AidenAllredOfficial

I believe the above snippet should accomplish your goal.

Generally the way to handle this will differ between snippet engines, so I will always say to refer back to their docs as this repo just supplies the snippets for the engine to load.

EDIT:

I re-read the message, the above snippet will exclude both. Let me brainstorm some ideas and I will get back to this thread asap (probably later this week).

OkelleyDevelopment avatar May 28 '24 03:05 OkelleyDevelopment

Hi @danieleavitabile , I was successful in preventing the snippets from loading by using the exclude field in the loader:

local vscode_loader = require("luasnip/loaders/from_vscode")
vscode_loader.lazy_load({
    exclude = { "latex", "tex" }
})

However, due to how LuaSnip currently parses the files (here), it seems your request is not possible.

Alternatively, we CAN modify the priority of your snippets. See here for a recent explanation.

OkelleyDevelopment avatar Jun 03 '24 04:06 OkelleyDevelopment

Hi again @danieleavitabile,

I was wrong! We CAN exclude the files like you asked (it just helps for me to INCLUDE my own LaTeX snippets in the snippets directory correctly :man_facepalming: ).

local vscode_loader = require("luasnip/loaders/from_vscode")
vscode_loader.lazy_load({
    exclude = { "latex", "tex" }
})

vscode_loader.load({ paths = "/home/<$USER>/.config/nvim/snippets/"})

Let me know if this helps, then we can make an edit to the docs to provide an example with Luasnip!

OkelleyDevelopment avatar Jun 03 '24 06:06 OkelleyDevelopment

Any updates @danieleavitabile? Did this work for you too?

OkelleyDevelopment avatar Jun 17 '24 03:06 OkelleyDevelopment

I had no chance to try yet, sorry.

On 17 June 2024 at 05:41:31, OkelleyDevelopment @.@.>) wrote:

Any updates @danieleavitabilehttps://github.com/danieleavitabile? Did this work for you too?

— Reply to this email directly, view it on GitHubhttps://github.com/rafamadriz/friendly-snippets/issues/431#issuecomment-2172118510, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AE6AWZ6DMO5UPVKZB4NAWEDZHZLGPAVCNFSM6AAAAABFX36M66VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZSGEYTQNJRGA. You are receiving this because you were mentioned.Message ID: @.***>

danieleavitabile avatar Jun 17 '24 05:06 danieleavitabile

Closing issue as I believe we've provided a working solution now. If further issues do arise, feel free to re-open this issue :+1:

OkelleyDevelopment avatar Jul 15 '24 00:07 OkelleyDevelopment