Sublime Forum

Editing a syntax coloring

#11

Thank you @atomi. Is this a document fragment, with the matches included within … , or do I need all the other trimmings - like the DOCTYPE and a UUID?

0 Likes

#12

That’s a fragment. You’ll need at least the following to make it useful:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>fileTypes</key>
	<array>
		<string>FILETYPE</string>
	</array>

	<key>name</key>
	<string>NAME</string>

	<key>scopeName</key>
	<string>SCOPENAME</string>

	<key>patterns</key>
	<array>
		...]
	</array>

</dict>
</plist>
0 Likes

#13

Thank you @nick.

I found a jQuery.tmLanguage file, which just needs to be updated with more recent jQuery methods :smile:

[BTW I couldn’t have taken this approach with my additions to the Python language, as it’s tmLanguage file is… a minefield :laughing:]

0 Likes

#14

[quote=“agibsonsw”]Thank you @nick.

I found a jQuery.tmLanguage file, which just needs to be updated with more recent jQuery methods :smile:

[BTW I couldn’t have taken this approach with my additions to the Python language, as it’s tmLanguage file is… a minefield :laughing:][/quote]

Seems that a lot of the language files are very dense, and many are not up to date. I’m working through Perl from scratch (see signature), and have plans to continue through other languages. Feel free to push/pull from my repo; maybe we can get such a repo added to the Sublime organization on github?

0 Likes

#15

@nick. I’ve managed to create a repo and update it, but I haven’t yet discovered what pulling/ forking, etc. mean :laughing: (grokking and borking also sound unpleasant…)

I’ve (eventually) managed to persuade Python.tmLanguage to behave as I’d like; in particular, I’m able to colour-match brackets - which is kinda cool :smiley:. But I’m still tempted to delete the whole of the repository, remove, temporarily, all includes and delete any reference to dotted or generic names! This file is 2000+ lines, whereas JS is 700+ - and they are not *that *different…

0 Likes

#16

I’ve found it helpful to immediately fold at level 3 when working with language files. Even my Perl from scratch is approaching 3000 lines, that seems to be a byproduct of XML and the many different ways to do things in Perl. Python may be of similar syntactic complexity. I think my file is better simply for the whitespace and comments, and because I’m making better use of the repository.

I could be wrong, but I believe a pull means you’re downloading someone’s repo to your own system. If you then make changes and submit them (to your repo) that’s a push. Then the original repo can pull from your changes. It’s described better here.

Edit: I decided to learn it a bit more in depth. This page has more information about the process.

0 Likes

#17

Thank you @nick. I shall read through those links.

0 Likes

#18

@agibsonsw Sorry for the tmLanguage fragment. I had just guessed you were more familiar with the basic tmLanguage format.
Regardless, I should have definitely posted the complete file.

Also based on your posts, I figured the jquery repo you decided to contribute to is on GitHub, but I wasn’t able to find it.
I’d love to check out your work on this too.

@nick I saw your Perl.tmlanguage file. It is really nice work and nicely (really nicely) documented too. :smiley:

I decided to develop the ColdFusion.tmLanugage, ColdFusionComponent.tmLanguage and CFscript.tmLanguage files in somewhat of an unorthodox manner.
One which I feel may make nesting scopes, in this particular case, superfluous.

For example ColdFusioComponent.tmLanuage defaults to source.cfscript defined in the CFScript.tmLanguage file but includes cfml scope defined in the ColdFusion.tmLanguage when a cfcomponent tag is encountered. If you could comment on this particular strategy I would really love to hear your thoughts.

github.com/SublimeText/ColdFusion

0 Likes

#19

@atomi

Here’s the jQuery bundle I found, although I haven’t attempted to update it yet.

I’m still wrestling with tmLanguage :wink:. I’ve managed to hack the Python language syntax so that it behaves for me. In particular, I achieved colour-coordinated brackets :smiley:. But it is, I believe, unnecessarily complicated. (There are 600+ lines to handle single-quoted strings, and this is repeated for double-quoted strings.)

I wish you well with your ColdFusion endeavours. Andy.

0 Likes

#20

@agibsonsw Thanks.

Oh okay I asked because I see another jquery bundle.
This one is available through package control github.com/SublimeText/jQuery and it’s actively maintained.

0 Likes

#21

[quote=“atomi”]@agibsonsw Thanks.

Oh okay I asked because I see another jquery bundle.
This one is available through package control github.com/SublimeText/jQuery and it’s actively maintained.[/quote]

Thank you @atomi

0 Likes

#22

[quote=“atomi”]@agibsonsw Thanks.

Oh okay I asked because I see another jquery bundle.
This one is available through package control github.com/SublimeText/jQuery and it’s actively maintained.[/quote]

Except this one is all snippets; there is no syntax coloring or autocompletes.

0 Likes

#23

Syntax tmLanguage is here:

github.com/SublimeText/jQuery/b … tmLanguage

0 Likes

#24

Thank you, I had been using the JQuery Snippets package, didn’t see the other one at first.

0 Likes

#25

Does anyone know if there is a repo/git/whatever for tmLanguage files? I know there are various packages/bundles out there in the wild, but I mean gathered in one place; esp. with documentation.

I am rather idly fiddling/struggling with the Markdown syntax (yeah, I know it’s not a real language :smile: ) without getting it do to much of what I wanted to do (better syntax highlighting and extending it for Pandoc). Although I’ve found that writting syntaxes in JSON is easier than the evil XML/PLIST that’s the default.

I’ll probably keep at this, but so far I’ve been cutting corners based on my own usage. I think the end result would be better if I knew:

a) that someone hasn’t done this already
b) of some in-depth documentation; or at least some recent, well-commented (I haven’t looked at the Perl syntax described above, yet, because I don’t speak the language)
b) what the best practices are (as far as I can tell the available documention consists of 1 & [2])
c) that I someone else could pick up and proceed with the work (or just bugfix, etc.)

[2]: docs.sublimetext.info/en/latest/ … xdefs.html

0 Likes

#26

[quote=“quodlibet”]Does anyone know if there is a repo/git/whatever for tmLanguage files? I know there are various packages/bundles out there in the wild, but I mean gathered in one place; esp. with documentation.

I am rather idly fiddling/struggling with the Markdown syntax (yeah, I know it’s not a real language :smile: ) without getting it do to much of what I wanted to do (better syntax highlighting and extending it for Pandoc). Although I’ve found that writting syntaxes in JSON is easier than the evil XML/PLIST that’s the default.

I’ll probably keep at this, but so far I’ve been cutting corners based on my own usage. I think the end result would be better if I knew:

a) that someone hasn’t done this already
b) of some in-depth documentation; or at least some recent, well-commented (I haven’t looked at the Perl syntax described above, yet, because I don’t speak the language)
b) what the best practices are (as far as I can tell the available documention consists of 1 & [2])
c) that I someone else could pick up and proceed with the work (or just bugfix, etc.)

[2]: docs.sublimetext.info/en/latest/ … xdefs.html[/quote]

I keep mine here.
github.com/facelessuser/sublime-languages

I add more when I modify more languages. Markdown is not included right now. But I am not aware of an official repo.

0 Likes

#27

@quodlibet
First place you should look for updated Syntax packages is wbond.net/sublime_packages/community
Earlier on there were divergent strategies to managing packages but it appears now that Package Control is the de facto package manager.

If you don’t find your syntax package in Package Control, I would recommend you search GitHub for the most actively maintained syntax package and PM me or another memeber at github.com/SublimeText and ask to have that package forked there and perhaps commit rights if possible as well. The reason for this is that all packages on SublimeText GitHub organization are available on Package Control. And SublimeText at GitHub also has a large amount of developers watching the repositories. All of which means there will be more eyes on the package and package is more likely to reach a critical mass of users and developers enabling more updates and merges.

If you decide to create a new syntax package, you’re going to need to be responsible for advocating it’s use and inclusion in Package Control (via @wbond). Or, again, just throw it on SublimeText at GitHub which seems to me like the more reasonable thing to do.

As for your other concerns, I think you should already have all of what you need to fully understand the tmLanguage file syntax. There isn’t a resource that I know of that will hold your hand on developing one of these. You’re just going to have to learn from whats already out there. I can only suggest you deconstruct some of the default tmLanguage files that highlight the languages you are most familiar with. And if you have a specific question on how something works just reach out here or PM.

0 Likes

#28

I made the mistake of working with the Python language file as a first one. I notice the MarkDown one is quite large as well. It might be worth examining one of the smaller (but, hopefully, similar) language files, to give an overview of what’s essential, and a basic structure.

Little bit of advice (about modifying an existing language file) - although my understanding is still limited at this stage, and you may have discovered some of the following already:

Look for an existing word, function or method that behaves similar to the word(s) that you want to include.
That is, is it always/only coloured if it is preceded by a delimiter such as a dot? Is it coloured only if followed by a bracket? Is it coloured if it appears in the middle of a chain.of.words.
Once you’ve found such a similar word, search for it in the language file. Study the expression/regex around it.
Note the scope-name for the found word and search for this also. Try to understand why it’s included/mentioned in several locations.
Follow this pattern for the words/ functions that you want to include. But first:
Read about the scope-naming conventions - you want your additions to fit neatly into the structure. But it can also be significant that the scope include certain specific words.
Although you should invent your own name for **part **of the scope, don’t put this first (or early) in the scope name - this takes it completely out of the existing structure.
Don’t invent more than, say, two or three names as part of the scope - it will quickly become messy.
Where you insert your new content is also important - if it’s too far down then it might be caught by an earlier scope rule. (Pressing Ctrl-Shift-Alt-P displays the scope for the current word/phrase in the status bar, although there is a very useful add-in to display scope mentioned elsewhere/ recently in this forum.)
And… copy the language file outside of your Packages folder :wink:

I apologise if you’ve already discovered these points, and I “disclaim”, as I’m still wrestling with it myself. Good luck, Andy.

0 Likes

#29

[quote=“facelessuser”]

[quote=“quodlibet”]Does anyone know if there is a repo/git/whatever for tmLanguage files? I know there are various packages/bundles out there in the wild, but I mean gathered in one place; esp. with documentation.

I am rather idly fiddling/struggling with the Markdown syntax (yeah, I know it’s not a real language :smile: ) without getting it do to much of what I wanted to do (better syntax highlighting and extending it for Pandoc). Although I’ve found that writting syntaxes in JSON is easier than the evil XML/PLIST that’s the default.

I’ll probably keep at this, but so far I’ve been cutting corners based on my own usage. I think the end result would be better if I knew:

a) that someone hasn’t done this already
b) of some in-depth documentation; or at least some recent, well-commented (I haven’t looked at the Perl syntax described above, yet, because I don’t speak the language)
b) what the best practices are (as far as I can tell the available documention consists of 1 & [2])
c) that I someone else could pick up and proceed with the work (or just bugfix, etc.)

[2]: docs.sublimetext.info/en/latest/ … xdefs.html[/quote]

I keep mine here.
github.com/facelessuser/sublime-languages

I add more when I modify more languages. Markdown is not included right now. But I am not aware of an official repo.[/quote]

mhhh good XD
sadly the $_SERVER $_GET etc snippets doesn’t work…

0 Likes

#30

@facelessuser Thanks the pointer. I will look into your Better CSS & HTML syntaxes. I also found the suggestion in your github to disable the default syntax very useful. It had not occurred to me.

@atomi Thank you describing a sane workflow to go about this. I really have to sit down and figure out how to work with git (after an April deadline goes by, one way or the other :smile: )

@agibsonsw I have, unfortunately, worked out most of what you describe in the manner I imagine you have: trial and error, punctuated by banging my head on the table. Hopefully, future souls will stumble across your post, which might minimize their allotment of head-banging.

I think I’ve gone astray by looking into Markdown first, and not only because it’s very long. I (stupidly) thought that because it’s such a simple markup, the syntax would be simple as well, which of course it isn’t – the regex for inline styles, such as the bold, are monstrous. (Or so they seem to me, I just started learning regular expressions last month.)

Alex

0 Likes