Syntax specific highlighting with Sublime Text 2 - sublimetext

I'm wondering if there is a way to have two different tag colours ("colors" for those in the US) for different language tags in the same file.
For example, lets say I have ColdFusion code and HTML code in the same .cfm file. Could I make the ColdFusion tags red and the HTML tags Blue?
For instance, lets call the below file HelloWorld.cfm - could I colour the tags differently?
<cfset myvar = "hello, world" />
<html>
<head>
<title>This is my title</title>
</head>
<body>
<div><cfoutput>#myvar#</cfoutput></div>
</body>
</html>
Thanks!

Yes, as long as the tags can be identified as having different scopes by your installed language definitions, you can edit your colour scheme to target those scopes with specific colours and other styles.
In your packages folder, language scopes are defined in the .tmLanguage files for your installed languages, while styles are defined in the .tmTheme files in the "color scheme - default" folder.
If you position your cursor inside a tag, and press shift+ctrl+alt+p (shift-cmd-p in OSX I think) the status bar will display the current scope. You can also copy this to the clipboard via the console with this command:
sublime.set_clipboard(view.syntax_name(view.sel()[0].b))
You can use this information to create your styles, a bit like css selectors, but with XML. For example I use this Coldfusion package and I have the scope selectors shown below in my custom .tmTheme file to distinguish cf tags from HTML tags.
<dict>
<key>name</key>
<string>Tag name</string>
<key>scope</key>
<string>entity.name.tag</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#D8D0B6</string>
<key>fontStyle</key>
<string>bold</string>
<key>foreground</key>
<string>#647A4F</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>CF tag name</string>
<key>scope</key>
<string>entity.name.tag.conditional.cfml, entity.name.tag.declaration.cfml, entity.name.tag.other, entity.name.tag.cf, entity.name.tag.inline.other.cfml</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#D8D0B6</string>
<key>fontStyle</key>
<string>bold</string>
<key>foreground</key>
<string>#990033</string>
</dict>
</dict>
More info on scope selectors.

I've updated the ColdFusion.tmLanguage so that you'll only need to target entity.name.tag.cf to color all cf tags. You can also target specific tags for example entity.name.tag.cf.script or entity.name.tag.cf.query for cfscript and cfquery respectively.
HTH

Related

How to create a simple custom language colorization to VS Code

I'm trying to create a simple colorization for log files, now that it's possible include custom languages in Code (I'm on 0.9.2). I have created a simple .tmLanguage file for colorizing the letter 'q', just for starting up, but have been unsuccessful.
My new language, log, is associated correctly with the file extension and I can also select it manually from inside Code, but no coloring takes places. I have a feeling it has to do with what "scope" I associate my pattern with, but I'm not sure. Is there a list of valid scope to choose from? Initially I thought I'd use something general, such as "comment" to get some color, but it doesn't seem to work.
Here's my .tmLanguage file:
<?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>scopeName</key>
<string>text.log</string>
<key>fileTypes</key>
<array>
<string>log</string>
</array>
<key>name</key>
<string>Log file</string>
<key>patterns</key>
<array>
<dict>
<key>match</key>
<string>q</string>
<key>name</key>
<string>comment</string>
</dict>
</array>
</dict>
</plist>
I'm probably misunderstanding something here, so any help is very appreciated :-)
You need to use regular expressions instead of static strings to describe the pattern:
<key>match</key>
<string>q</string> <- This needs to be a regular expression
<key>name</key>
<string>comment</string>
I provide a more useful example for a log file highlighter. It colors numbers, hints, warnings and errors in different colors. The rules to identify these keywords and numbers are based on regular expression.
<?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>scopeName</key>
<string>text.log</string>
<key>fileTypes</key>
<array>
<string>log</string>
</array>
<key>name</key>
<string>Log file</string>
<key>patterns</key>
<array>
<dict>
<key>match</key>
<string>\b(?i:(hint|info|information))\b</string>
<key>name</key>
<string>info-token</string>
</dict>
<dict>
<key>match</key>
<string>\b(?i:(warning|warn))\b</string>
<key>name</key>
<string>warn-token</string>
</dict>
<dict>
<key>match</key>
<string>\b(?i:(Error|Failure|Fail))\b</string>
<key>name</key>
<string>error-token</string>
</dict>
<dict>
<key>match</key>
<string>\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\b</string>
<key>name</key>
<string>constant.numeric</string>
</dict>
</array>
<key>uuid</key>
<string>FF0550E0-3A29-11E3-AA6E-0800200C9A77</string>
</dict>
</plist>
The highlighter gives a result like this (using the default theme):
I didn't find an official documentation about the available tokens (like error-token, constant.numeric etc). But there is a file located in %VSCODE_INSTALLATION%\resources\app\out\vs\languages\markdown\common\tokens.css. It seems to list all available tokens etc. Use it as a reference when you create the .tmLanguage file.
But pay attention: Some themes are using only the basic tokens. And some other themes are using the same color for many different tokens. So you should test the highlighter frequently against the most common themes to see whether the result looks good or not.
You should definitely visit this page about Language Grammars to learn more.
We just released a language extension that brings colorization to the Output panel. Basically, it does the same thing as the approved answer on this thread, and adds the text/x-code-output mime type, which is used by the Output panel.
Get it free here:
https://marketplace.visualstudio.com/items?itemName=IBM.output-colorizer
Source here:
https://github.com/IBM-Bluemix/vscode-log-output-colorizer
Please help contribute! Bugs, feature requests, contributions all welcome.
Here are some screenshots of it working:
As #Woshi said, you need regular expressions.
As for the scopes that generally work with most color themes, I'll link you to this answer.
Keep in mind that for scope to be picked up, it needs to be in dictionary with key "name".

palettes of icons in Google Earth (Mac)

(Cross posted from the GE support groups - now defunct?)
Having trouble using the gs:x extensions to use palettes of icons in an icon
group.
I have loaded the appropriate xmlns:gx="http://www.google.com/kml/ext/2.2"
into the kml header but get the message "Unknown type gs:x
on my Macintosh under GE Google Earth 6.0.3.2197
I suspect this has not been implemented on the Mac version - anybody
with experience on this?
Final code was as follows and it fails on the first gx:s line.
It also fails in the same way if I use the now deprecated x (rather than gx:x)
Also, as shown it follows the kml documentation but I think all terminating terms should be of the form /gx:x rather than gx:x/
as shown in the KML reference. Making that change does not help as it never gets to that point anyway.
The header was copied from a GE placemark copied and pasted into the
editor.
Any help appreciated.
Bob J.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2"
xmlns:kml="http://www.opengis.net/kml/2.2"
xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<StyleMap id="s_Ic_SP">
<Pair><key>normal</key><styleUrl>#sn_Ic_SP</styleUrl></Pair>
<Pair><key>highlight</key><styleUrl>#sh_Ic_SP</styleUrl></Pair>
</StyleMap>
<Style id="sn_Ic_SP">
<IconStyle>
<scale>1.8</scale>
<Icon>
<href>Icons/Traps.png</href>
<gx:x>0<gx:x/><gx:y>128<gx:y/> <gx:w>64<gx:w/><gx:h>64<gx:h/>
</Icon>
<hotSpot x="32" y="1" xunits="pixels" yunits="pixels"/>
</IconStyle>
<BalloonStyle>
<displayMode>default</displayMode><bgColor>ff00d0ff</bgColor>
<text><![CDATA[<font face="Comic Sans MS" /><table
bgcolor="#ff8000" cellspacing="3" width="160">
<tr bgcolor="#ffff80"><td><b>Sponsor $[name]</b><br/><br/>$
[description]</td></tr></table>]]></text>
</BalloonStyle>
<LabelStyle>
<scale>0.9</scale><color>ff00ffff</color>
</LabelStyle>
<LineStyle><color>ff00ffff</color><width>2.0</width></LineStyle>
<ListStyle>
<ItemIcon>
<href>Icons/Traps.png</href>
<gx:x>0<gx:x/><gx:y>128<gx:y/> <gx:w>64<gx:w/><gx:h>64<gx:h/>
</ItemIcon>
</ListStyle>
</Style>
etc.
Oooops
Seems my problem was a syntax problem
The gx:x set do work correctly. However, they are not operational inside the ItemIcon group as shown in my example. In fact they are ignored in that group.
Thanks for your tolerance of my stupidity
Bob J.

How to Display UITableView from Plist Without Sorting It

I have this Plist in my project.
<?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>Medical Info</key>
<array>
<string>Date of Birth</string>
<string>Blood Type</string>
</array>
<key>Allergies</key>
<array>
<string>Drug</string>
</array>
<key>Medication</key>
<array>
<string>Drug</string>
</array>
<key>Conditions</key>
<array>
<string>Medical</string>
</array>
</dict>
</plist>
When I display it, it sorts out differently like this:
How can I display my table from my plist as what is stored on the plist and without sorting? Thanks!
NSDictionary is not ordered, so there is no guarantee that it'll be displayed as what you ordered in your plist. Unfortunately, you'll have to sort it if you're using dictionary. Change it to use array if you want it the same order as the data in your plist.

Xcode 4 NSLog Macro link in Xcode 3

In Xcode < version 4, there was a macro to quickly write NSLogstatements. I could type (I think, using my motor memory):
log control+.
And the code complete/macro would do:
NSLog(|);
| being the cursor.
Is there anything similar to accomplish this in Xcode 4?
Thanks
Ross
I really miss this macro too. Thanks to Kendall's example, I was able to recreate it.
Go to this folder or create one if doesn't exist:
~/Library/Developer/XCode/UserData/CodeSnippets
Then create a file called NSLog.codesnippet and paste in the following:
<?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>IDECodeSnippetCompletionPrefix</key>
<string>log</string>
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>All</string>
</array>
<key>IDECodeSnippetContents</key>
<string>NSLog(#"<#Comment#>");
</string>
<key>IDECodeSnippetIdentifier</key>
<string>nslog1</string>
<key>IDECodeSnippetLanguage</key>
<string>Xcode.SourceCodeLanguage.Objective-C</string>
<key>IDECodeSnippetTitle</key>
<string>NSLogComment</string>
<key>IDECodeSnippetUserSnippet</key>
<true/>
<key>IDECodeSnippetVersion</key>
<integer>2</integer>
</dict>
</plist>
Restart Xcode and type l into a file in your project. If autocomplete isn't showing, hit escape and then choose the "log - NSLog comment" option and then hit tab.
After you've used it once, you'll probably only need to use l+tab for the autocomplete.
You can create as many as you like. Just make sure the filename, the IDECodeSnippetIdentifier and the IDECodeSnippetCompletionPrefix are all unique.
More examples are available on GitHub.
Type NSL and press escape, the autocomplete will handle the rest.

local-name() support in Collective.xdv

I have a Plone 3.5 site and I am trying to embedded Simple Social's FB Like action for a content in a collective.xdv theme. The FB Like function is embedded in an XML tag
<fb:like></fb:like>
I am trying to select its XPATH via
//*[local-name()="like"]
However, I do not see any output. Is the above supported in collective.xdv? Is there another way to select the fb:like tag in XPATH?
The libxml2 HTMLParser used by lxml and thus xdv/diazo strips namespace prefixes, so you should be able to select it with "//like".
You will need to add some xslt code to fix up those tags, as they must be rendered as in order to work:
<xsl:template match="activity|add-profile-tab|bookmark|comments|friendpile|like|like-box|live-stream|login-button|pronoun|recommendations|serverFbml|profile-pic|user-status">
<xsl:element name="fb:{local-name()}" xmlns:fb="http://www.facebook.com/2008/fbml">
<xsl:apply-templates select="#*|node()"/>
</xsl:element>
</xsl:template>
While xdv/diazo could be made to work with the XMLParser you would then need to ensure that you added an xmlns:fb="..." declaration to your document and that all your input was valid xhtml, which is difficult to ensure with browser based html editors.
Laurence
aiui, that's not how local-name works. You need to match on a namespace-qualified tag, and then local-name() returns the unqualified name. I believe //* is only returning a nodeset of tags in the default namespace.
Have you tried //fb:like? [I know, that's far too easy - and I think it's wrong - but then again, it is easy :-) ]

Resources