Sublime Forum

Position of item in context menu

#1

I have a small custom plugin that opens windows terminal in the current folder. I’ve had it for years now (was cmd before, now it’s wt). It always appeared in the context menu at the first position in the second group and my muscle memory has built up for that.
However, I recently started using LSP and it has hijacked my position in the context menu :sweat_smile: (picture attached)

image

Is there a way to specify where my plugin appears in the menu?

I’ve tried to mess around with id and group but unsuccessfully. I also tried looking into LSP’s Context.sublime-menu file and a few others but didn’t find any indication of why it was on the top.

0 Likes

#2

I think it is just the package load order for those menu items which don’t specify any id (like LSP). So if your package has the name AAAMyPackage, then its menu item(s) will be shown at the top (unless they use an id), and if it is named ZZZMyPackage it will end up below of the LSP item. The User package is loaded last, so it will be even below the ZZZ... package.

0 Likes

#3

Thanks!
I really need to change that though😅

Can I give LSP an id? Or move it to another group? (currently it does not have any id in the context menu file)

0 Likes

#4

The easiest way would be to put your custom plugin into a package with a name that gets alphabetically sorted before LSP. A package is just a folder in the Packages directory (Preferences: Browse Packages from the command palette).

If you don’t want to do that, for example if your custom plugin is a package that you added to Package Control, then you could still create an override for the LSP/Context.sublime-menu file to add an id there, provided that you have installed LSP via Package Control. But there is a non-zero chance that LSP’s context menu will be updated in the future and your override might become outdated.

0 Likes

#5

My package’s name is “Cmd” so it already comes before “LSP”, and it’s in the Packages directory, not the User one.
Weirdly, in the package loading stage at startup, it is reloaded after LSP (after W…), and its not alone there. A few packages are also loaded after that, in alphabetical order, but in a second pass.
image
(My package is highlighted)

I don’t have a problem with the first option, its not added to package control.
Is there a difference in which user-made packages are checked, even if they are not in the User directory? (its not like the packages in the second pass are all mine, they are all installed from package control except DebugInputHandler)

0 Likes

#6

Hm, that seems strange. So your Context.sublime-menu file with the corresponding item is also in the Cmd folder, right? Actually it should be only this file which matters for the menu items ordering. But if you have combined all your menu items into a single file Context.sublime-menu in the User folder, then you would need to split them up and put the item into a file in the Cmd folder.

I think the only differences between the User package and any other package manually put into the Packages folder is that User is loaded last, and that it automatically runs Python plugins in the Python 3.8 environment.

1 Like

#7

Wait, it might be that all loose packages from the Packages folder are loaded after those installed via Package Control (Installed Packages folder). That would explain why your item comes after LSP…

0 Likes

#8

The context menu file is inside the package
Also, it looks like all py3.8 packages are loaded before any of the 3.3 ones (I have one I made in that also)

(2nd)
How does it distinguish between packages installed via package control though? (when they are all in the same folder) Edit: I found the Installed Packages folder

0 Likes

#9

I changed the python version for that package to 3.8, and even though it still loads before LSP, the position is the same

I dont know what to do at this point

0 Likes

#10

A thing you could try is to zip the contents of your Cmd package, rename the file from Cmd.zip to Cmd.sublime-package and put that into the Installed Packages folder. If my assumption from above was correct, then I guess it should work. But the drawback would be that you can’t easily edit the files from your zipped package anymore (need to unzip -> edit -> zip then).

Edit: I haven’t tried it, but maybe Package Control might automatically remove that package on the next start when it can’t find it in the "installed_packages" setting. So better backup your files before you would try that.

0 Likes

#11

Packages load in the order: Shipped, Installed, Unpacked, and within that order, each package is loaded Lexically Sorted, with the sole exception that Default is always loaded first and User is always loaded last.

So indeed, packages that are installed as sublime-package files load before loose files in Packages (unless the folder in Packages has the same name as a sublime-package file, in which case those files are loaded as a part of it.

Package Control will only remove packages that it thinks it installed, and such packages have a metadata file within them that it puts there during the installation process.

So, in this case it should be safe to turn the package into a sublime-package file and put it in place directly.

2 Likes