Sublime Forum

Overriding default (LaTeX) Snippet in User folder not working

#1

I was looking to override the custom section snippet in LaTeX.
Used Package Resource Viewer to Extract the snippet and edit it to my liking.

At first I placed it in Packages/LaTeX/Snippets/section-..-(section).sublime-snippet and that worked great, the snippet gets correctly overridden.

But I want to sync it with my other computers and for that I want to place the overridden snippet in the User folder so I can add it to git and sync it.

So I moved it to: Packages/User/LaTeX/Snippets/section-..-(section).sublime-snippet and that does NOT override the default snippet. It adds the snippet in the dropdown(autocomplete) menu as an extra snippet but it does not override the default snippet.

While searching the forums I noticed that others have seen this behaviour as well:
Overwriting default snippet
Modyfing existing snippet

Now am I wondering whether this is inteded behaviour or that this is something that needs to be looked in to.
I would like to sync all my overridden snippets between all my computers so if the behaviour is intended how can I manage that?

0 Likes

#2

The thing that makes a package resource unique is the combination of it’s name and package path; that’s why if you create an override it masks the original package file but if you put it in your User package it doesn’t; as a non-override it’s just seen as another unique resource. If that wasn’t the case, packages would be able to hide similarly named files in other packages by just having the same name (either intentionally or accidentally).

The User package is just a regular package whose main difference is that it’s always loaded last to ensure that the resources that it contains that combine with other resources have the ability to override the resources of other packages. Things like key bindings and settings combine together, but snippets do not (as that would not make much sense).

You can disable a snippet by overriding it with an empty file, so one possible solution to your problem would be to keep your modified version in your User package to sync it, and then perform a one time operation on each new install to create an empty override for the original snippet to hide it.

Such an operation could be managed by a plugin that could take a configurable list of package resources and ensure on Sublime startup that the empty overrides are in place, for example. There may or may not be a package already available that does this.

1 Like

#3

Thank you for that very clear explanation! Honestly helped me understand how packages are structured!

This “workaround” works great for me! Thank you for the suggestion

I have looked around and not been able to find a plugin that can do this. I am very interested in writing one myself and will look into that!

0 Likes

#4

As a starting point, there is an example of a plugin that does this in this gist. As written it will automatically create empty snippet overrides based on the structure you mentioned above every time the plugin loads as well as when you manually run the command.

Depending on your own use, you could redact the command if the automated update at startup is enough, or you could redact the plugin_loaded function if you’d rather only doing it manually, or anything in between.

1 Like