rafamadriz / friendly-snippets

Set of preconfigured snippets for different languages.
MIT License
1.82k stars 411 forks source link

Example of selectively applying snippets #431

Open danieleavitabile opened 3 months ago

danieleavitabile commented 3 months ago

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.

AidenAllredOfficial commented 2 months ago

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

OkelleyDevelopment commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 3 weeks ago

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

danieleavitabile commented 3 weeks ago

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: @.***>