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.
Related
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".
(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.
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.
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
I am trying to add a trivial AppleScript support to a Cocoa application. The application performs a check periodically and I just want to be able to tell it to perform it on demand.
I am trying to follow the SimpleScriptingVerbs Apple example.
I have subclassed NSScriptCommand as follows:
Header:
#import <Cocoa/Cocoa.h>
#interface rdrNotifierUpdateCommand : NSScriptCommand {
}
-(id)performDefaultImplementation;
#end
Implementation:
#import "rdrNotifierUpdateCommand.h"
#import "rdrNotifierAppDelegate.h"
#implementation rdrNotifierUpdateCommand
-(id)performDefaultImplementation {
NSLog(#"Works at last");
[((rdrNotifierAppDelegate *)[[NSApplication sharedApplication] delegate])
checkForNewItems]; // This just fires the timer
return nil;
}
#end
My .sdef file goes as follows (and the problem seems to be there, but I cannot find it):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="Dictionary" xmlns:xi="http://www.w3.org/2003/XInclude">
<xi:include href="file:///System/Library/ScriptingDefinitions/CocoaStandard.sdef" xpointer="xpointer(/dictionary/suite)"/>
<suite name="rdrNotifier Suite" code="rdrN" description="rdrNotifier application specific scripting facilities.">
<command name="do update" code="rdrNUpdt" description="Check for new items">
<cocoa class="rdrNotifierUpdateCommand"/>
</command>
</suite>
</dictionary>
The Info.plist is set up appropriately.
But, when I try to run the following script in AppleScript editor:
tell application "rdrNotifier"
do update
end tell
I receive an error about variable "update" not being defined.
I can open the dictionary for my application from AppleScript Editor (i.e. it is successfully registered).
Edit: Found a solution
The problem was indeed in the sdef file: I was not specifying that the application can reply to the command. My final definition goes as follows (Obj-C code unchanged):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="Dictionary" xmlns:xi="http://www.w3.org/2003/XInclude">
<!-- I have removed the standard suite as the application does not open, print... -->
<suite name="rdrNotifier Suite" code="rdrN" description="rdrNotifier application specific scripting facilities.">
<command name="do update" code="rdrNUpdt" description="Check for new items">
<cocoa class="rdrNotifierUpdateCommand"/>
</command>
<class name="application" code="Capp">
<cocoa class="NSApplication"/>
<responds-to name="do update">
<!-- Note you need to specify a method here,
although it is blank -->
<cocoa method=""/>
</responds-to>
</class>
</suite>
</dictionary>
Any improvements/tips/criticisms are still welcome.
Thanks for making the effort of adding applescript support to your app! Just a quick observation / criticism: When constructing terminology, by all means include spaces, but if that terminology takes the form of 'verb noun' (like 'do update') appleScripters will be irritated if the noun 'update' is not a properly modelled object, and if 'do' is not a proper command.
I would argue that 'do' is a poor choice for a command name, because it is very vague. What's wrong with just using 'update' as the command? (i.e. treat it as a verb).
This issue is treated in some detail by Apple's own technote 2106 (currently here), which you definitely should read and digest if you hope to please your AppleScripting user community.
Apple themselves are not beyond stupid terminology choices such as updatePodcast and updateAllPodcasts (in iTunes). These are stupid choices because (according to tn2106) they contain no spaces, and because the better choice would be to have a proper podcast class and then have an update command which could be used on an individual podcast, all podcasts, or a particular chosen set of podcasts.