syntax highlight (.tmLanguage) in Sublime Text 3 for packages
Asked Answered
M

3

5

I work on this plugin

Syntax highlight does not work with Sublime Text 3 when plugin is installed using package control.

Error loading syntax file "Sublime Text 3/Installed Packages/robot.tmLanguage": Unable to open Sublime Text 3/Installed Packages/robot.tmLanguage

The plugin is under Installed Packcages/Robot Framework Assistant.sublime-package, the file 'robot.tmLanguage' in inside Robot Framework Assistant.sublime-package archive.

Here is how I set paths https://github.com/andriyko/sublime-robot-framework-assistant/blob/master/rfassistant/init.py

My question is similar to this thread, but in my case the plugin is installed as archive(.sublime-package) not folder with with files.

  1. I am not sure that my path settings mentioned above are correct in python3.

  2. How can I refer to tmLanguage file that is inside .sublime-package file?

  3. Where should I put that file? It is totally confusing why does it work on Sublime Text 2 and Sublime Text 3(when installed into dir from github) but does not work when installed via Package Control.

So, how do I set path to tmLanguage file and where should I store it. Just want to clarify, that it works fine when plugin is installed from github zip file(because I put it's content into RobotFrameworkAssistant folder under Packages directory). It does not work when plugin is installed via Package Control.

Mckenzie answered 4/12, 2013 at 20:46 Comment(3)
Shouldn't this be a SuperUser question?Gauche
Not sure. Why SuperUser? 1. I am not sure that my path settings mentioned above are correct in python3. 2. Sublime forum is down for several days(or weeks?) sublimetext.com/forum. 3. 4. How can I refer to tmLanguage file that is inside .sublime-package file? 5. Where should I put that file? It is totally confusing why does it work on Sublime Text 2 and Sublime Text 3(when installed into dir from github) but does not work when installed via Package Control.Mckenzie
You should put that in the question now.Gauche
M
2

The issue seems to be solved. Please refer to this fix.

Why I had problems with syntax settings(.tmLanguage) in ST3?

Because it is totally confusing and not clear from ST3 docs where that file should be located. (Even if it says that files lookup is continued in Packages directory if file was not found in Installed Packages).

There are two 'main' folders under Sublime Text 3 directory: Installed Packages and Packages.

When the plugin is installed using Package Control it goes into Installed Packages directory packed into archive file called like Robot Framework Assistant.sublime-package (which is actually ZIP file). The robot.tmLanguage file (syntax file) is inside Robot Framework Assistant.sublime-package.

So, in few words, my question was: how to refer to that file (what path should be provided to view.set_syntax_file method)?

Unintuitive, but I should refer to non-existent path Packages/Robot Framework Assistant/robot.tmLanguage. Actually, in my case the Packages directory contains only Users folder. The only thing, that I can guess is that folder name should be the same as package name(Robot Framework Assistant in my case).

Mckenzie answered 5/12, 2013 at 19:58 Comment(2)
Yes it is a "nonexistent path", but that was done (in my opinion) to maintain some compatibility between ST2 and ST3. The docs do give sample paths. From the API docs Changes the syntax used by the view. syntax_file should be a name along the lines of Packages/Python/Python.tmLanguage. It also shows how you can find the syntax of the current file. If you had done that, you would have also seen the same type of path, even though the file is not located in the Packages folder. Well glad you got something working. The default packages are not located in the Installed Packages or Packages folderRoofer
@Roofer Do you know where the default packages are located in ST3?Phenformin
L
5

Quick summary of my manual solution of adding custom .tmLanguage files based on others' suggestions:

  1. Put the myLang.tmLanguage file into a folder with your desired syntax name.
  2. Zip the folder so that it's named myLang.zip
  3. Rename the zip archive to myLang.sublime-package
  4. Put the myLang.sublime-package into the Sublime 3 packages folder. It will now appear in the sublime syntax highlighting menu.

Based on ST3 docs, I can't seem to find an alternative to this manual method right now, but it will work.

Package control will likely do everything you need behind the scene

Lightfingered answered 10/4, 2015 at 17:5 Comment(1)
+1; thanks, the only solution that worked for me - ridiculous out of all the docs and various links to tmLanguage projects (claiming compatibility with sublime3) not a single one made it obvious how to get them picked up by sublime nor was a .sublime-package file distributed. Sublime scattering package directories all over the place didn't help. All this to test out an editor I didn't know if I wanted to use yet, let alone get past my firewall!Cariotta
R
3

Do you need the content of the tmLanguage file? If so, you shouldn't be accessing it directly. Instead, you should be using sublime.load_resource(name), where name is something like Packages/Robot Framework Assistant/robot.tmLanguage. If you are just trying to set the file syntax, you should be using view.set_syntax_file(syntax_file), where syntax_file is like name for the resource. I did not look at your plugin in detail, so please clarify what you are trying to do if both of those answers are incorrect.

As a side note, based on that error, you would probably see issues in ST2 also. You are only looking at the root packages folder, not in your package.

In ST3, jps decided to make plugins runnable from .sublime-package files, rather than needing to be extracted. These files are simply renamed .zip files. Updates do need to be made if you are accessing resources within your plugin, but the API has been extended to support it.

This isn't a great list, but it covers some of the changes in ST3 from ST2.

http://www.sublimetext.com/docs/3/porting_guide.html

Roofer answered 5/12, 2013 at 2:13 Comment(2)
It does not work only in ST3 when plugin is packed into archive. Works as expected on ST2, works on ST3 when installed manually. Please take a look at this file. What path should I use for ST3? How can I put it inside Packages/Robot Framework Assistant/robot.tmLanguage if robot.tmLanguage file is inside the package archive and I can't refer to it to read it?Mckenzie
Can you clarify what you are trying to do? Since it's a tmLanguage file, I assume you are trying to set the syntax for some view. I've included instructions on how to do that already. You do not need the entire path to set the syntax (in fact, you didn't need it in ST2 either).Roofer
M
2

The issue seems to be solved. Please refer to this fix.

Why I had problems with syntax settings(.tmLanguage) in ST3?

Because it is totally confusing and not clear from ST3 docs where that file should be located. (Even if it says that files lookup is continued in Packages directory if file was not found in Installed Packages).

There are two 'main' folders under Sublime Text 3 directory: Installed Packages and Packages.

When the plugin is installed using Package Control it goes into Installed Packages directory packed into archive file called like Robot Framework Assistant.sublime-package (which is actually ZIP file). The robot.tmLanguage file (syntax file) is inside Robot Framework Assistant.sublime-package.

So, in few words, my question was: how to refer to that file (what path should be provided to view.set_syntax_file method)?

Unintuitive, but I should refer to non-existent path Packages/Robot Framework Assistant/robot.tmLanguage. Actually, in my case the Packages directory contains only Users folder. The only thing, that I can guess is that folder name should be the same as package name(Robot Framework Assistant in my case).

Mckenzie answered 5/12, 2013 at 19:58 Comment(2)
Yes it is a "nonexistent path", but that was done (in my opinion) to maintain some compatibility between ST2 and ST3. The docs do give sample paths. From the API docs Changes the syntax used by the view. syntax_file should be a name along the lines of Packages/Python/Python.tmLanguage. It also shows how you can find the syntax of the current file. If you had done that, you would have also seen the same type of path, even though the file is not located in the Packages folder. Well glad you got something working. The default packages are not located in the Installed Packages or Packages folderRoofer
@Roofer Do you know where the default packages are located in ST3?Phenformin

© 2022 - 2024 — McMap. All rights reserved.