Extend Sublime Text's GotoAnything functionality - textmate

I would like to extend Sublime Text's GotoAnything for a custom source format. I've created a .tmPreferences file and from the behaviour I can tell it's being recognized. However, I have some trouble with the correct RegEx string.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Symbol List Function</string>
<key>scope</key>
<string>source.nsis</string>
<key>settings</key>
<dict>
<key>symbolIndexTransformation</key>
<string>s/Function $1/</string>
</dict>
<key>uuid</key>
<string>9b3c04e2-e02a-4c55-85e9-de83ac7eedaf</string>
</dict>
</plist>
So yes, I want to match functions using in the scheme Function myFunctionName (for Goto #myFunctionName). This seems very trivial, yet I'm not sure why I don't get it to work.

Can you post the entire tmPreferences file. What you have posted here simply transforms an identified token. It does not identify them. Tokens are added based on scopes. Take a look at my answer here for how to add entries to the symbol list.

Related

How to interpret/export large plist data

I have plist files that have around 60K lines of code (per BBEdit), and I'm trying to decode some data points saved in these files. The database company I purchased the software through will not convert my data out to another format (CSV or otherwise) that I can use with a competitor's product, and they will not convert it internally and send me the exported data. I've started to go through and change one value and then look at the plist and see where the change was made, and I'm trying to figure out if there is a way to find out what the integers are referencing? I've searched for information on how Plists work, and it seems as though the integer value is referencing some place earlier in the plist document, but as I did not write this program, nor do I have access to source or any help from the company, I'm going to have to reverse engineer this so that I can export the data points I'm interested in, as there are around 100K values I'd like to save. A royal PITA, but there you have it. CF$UID appears to be a Core Foundation unique identifier, but that's all I've got. Any suggestions would be most helpful.
<dict>
<key>$archiver</key>
<string>NSKeyedArchiver</string>
<key>$objects</key>
<array>
...some 30-40K lines later
<dict>
<key>$class</key>
<dict>
<key>CF$UID</key>
<integer>153</integer>
</dict>
<key>stringValue</key>
<dict>
<key>CF$UID</key>
<integer>24</integer> <--- this is the value that's changing for my particular data point I'm interested in.
</dict>
... so on and so forth, then at the end, something like this.
</array>
<key>$top</key>
<dict>
<key>root</key>
<dict>
<key>CF$UID</key>
<integer>1</integer>
</dict>
</dict>
<key>$version</key>
<integer>100000</integer>
</dict>
</plist>
It looks like what was done is that NSKeyedArchiver was used to serialize an Objective-C object graph to an XML formatted property list. Without the source code (or at least header files) for this code, this is going to be a very painful process. The reason they won't provide this to you as a CSV is that'd make no sense - this is a deeply nested structure which is serializing the in-memory state of the application.
My suggestion is either give up or pour yourself a stiff drink. This is not intended to be directly used by a human.

Customising info.plist file for an AppleScript applet

So basically I have this application made from AppleScript. Now I'd like to customise some information (e.g. bundle identifier, version number, etc.) However, it seems as if even the slightest changes to the info.plist will cause the script to… not work.
Any idea how to change the info.plist of the AppleScript application without breaking it?
There are only three requirements for editing a plist file:
Don't change anything on the first four lines. They should always look like:
<?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>
Don't use anything except plain-text characters (no curly quotes, rich text, strange characters, etc). I recommend using the free version of BBEdit, which will keep things nice.
Don't break the hierarchical key-value structure. Plist entries have the form:
<key>KeyWord</key>
<value-type>whatever data</value-type>
where the value-type can be 'string', 'real', 'integer', 'date', 'data', 'array', 'dict', of one of the booleans 'true' or 'false'. It's standard XML style, with opening and closing tags (distinguished by a slash) and singleton tags for true and false (where the slash is at the end of the word rather than the beginning). Dictionaries can have key-value pairs within them, arrays have lists of values without keys, you can nest as deeply as you like, but you must always open and close tags in the proper order.
Common errors are:
accidentally deleting an opening or closing angle-bracket
overlapping opening and closing tags for nested elements (e.g., open tag for a dict, open tag for an array, close tag for the dict, close tag for the array)
separating keys from their values (value elements must come immediately after key elements
An additional concern in modern days is that applets are now codesigned by default. This means if you modify any part of the applet (including Info.plist) outside of Script Editor, after creating it, it will now have an invalid code-signature.
For some purposes, that won't matter, or be noticeable — but, especially if you control "System Events" or use accessibility features, you'll get obscure, confusing failures until you fix this.
Luckily, it's easy enough to re-sign the application-bundle after you've modified the Info.plist — simply run the following in the Terminal:
codesign -fs - --preserve-metadata=entitlements /Applications/YourApplet.app
The -f overwrites the existing (now incorrect) code-signature; the -s - allows it to be an ad-hoc signature (same as what was already present); and the --preserve-metadata=entitlements is the important part that maintains the Script Editor configuration of your script's permissions.

How to read multiple values at once from plist files using "defaults" in MAC OSX

I have a plist file which contains keys like
Area
Name
City
Country
As per defaults man page one can read a key from plist like this
defaults read plist-file key
E.g.
defaults read abc.plist Area
However I want to read more than one key using defaults.
defaults read abc.plist Area City Country
The above produces output only of Area, not of City and Country.
Can anyone please suggest how can I read multiple keys from plist in one go using defaults only?
You can use
defaults read path/to/your plist
Can anyone please suggest how can I read multiple keys from plist in one go using defaults only?
You can use a for loop:
for key in Area City Country; do defaults read abc.plist $key; done

How do I Pass a filename from finder into my OS X Application

I want to be able to open a file with my application from finder
click on the file and and select open with then select my application.
I am not using NSDocumentController and I have put this in my applicationdelegate
-(BOOL) application:(NSApplication *)sender openFile:(NSString *)filename;
as I am more or less guessing my way through this can any one tell me if I am on the right track
also is there something I need to do in order to tell the os what king of files I can except
Regards Christian
You have to register with the file types your program is associated with , you can do this by adding "LSItemContentTypes" key to your plist and specifying the file types.
Something similar to described in this post.
How do I associate file types with an iPhone application?
When a user opens the file the delegate method will get called .
-(BOOL) application:(NSApplication *)sender openFile:(NSString *)filename;
File name parameter will be with the path , then you can work with the file using that.
You also need to specify Launch Services keys in Your Info.plist file.
from: Launch Services Programming
The CFBundleTypeName key specifies the document type’s kind string, a user-visible description used to characterize documents of this type on the screen (such as in the Finder’s Get Info window or in the Kind column of the Finder’s list view). This key can be localized by including it in the InfoPlist.strings file of the appropriate .lproj subdirectory. CFBundleTypeIconFile identifies the file containing the icon image to be used for displaying documents of this type on the screen. LSTypeIsPackage specifies whether the document is a packaged bundle (true) or a single file (false).
Files belonging to a given document type may be characterized by their file types, filename extensions, or MIME types. The CFBundleTypeOSTypes key in the type-definition dictionary specifies an array of four-character file type codes that characterize documents of this type; similarly, CFBundleTypeExtensions specifies an array of filename extensions and CFBundleTypeMIMETypes an array of MIME types. Any of these individual keys can be omitted if the corresponding file characteristic is not relevant, but at least one of them must be present for the file type to be nonempty. To allow an application to accept files of unrestricted file type or extension during drag-and-drop operations, you can use the special wild-card values '**' or '*' for CFBundleOSTypes or CFBundleTypeExtensions, respectively. (These are honored only in drag-and-drop operations and not when the user opens a document by double-clicking.) Finally, the CFBundleTypeRole key specifies the role that the application claims with respect to documents of the given type, as described under “Application Roles.”
Here's example from TextEdit.app for rtf files:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFile</key>
<string>rtf.icns</string>
<key>CFBundleTypeName</key>
<string>NSRTFPboardType</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSIsAppleDefaultForType</key>
<true/>
<key>LSItemContentTypes</key>
<array>
<string>public.rtf</string>
</array>
<key>NSDocumentClass</key>
<string>Document</string>
<key>NSIsRelatedItemType</key>
<true/>
</dict>
</array>
Thanks all one more thing I found open file is callecalled before applicationdidfinishlaunching
And is where I am creating my view controller which contains my file open method
Cheers christian andersen

Sublime text: Adding symbols to a new language definition (syntax highlighting)

I have written syntax highlighting for a slightly unfamiliar language (Cadence SKILL) in sublime text 2.
Its working like a charm, however I miss the feature of CTRL + R , which locates all the symbols (functions) in the present file in an easily accessible way.
Can anyone please suggest how to tell Sublime Text where to look for a pattern of function (procedure) declaration?
Thanks!
Take a look at Default/Symbol List.tmPreferences. You can create this preference file and specify scopes to include in the symbol list. You may also want to look at Java/Symbol List <some specifier>.tmPreferences for examples of a language specific symbol list. Alternatively, you can ensure the things that you want to include have the scope entity.name.function or entity.name.type.
edit
You will need to look at your color scheme file. These files are Plist, so you may want to use something like PlistJsonConverter to make it a little more readable (though this is more of a personal preference). In this file, you will see a number of dictionary entries. One of the keys to these entries is scope. When a matching scope is found as defined by your language definition. You will also see a "settings" key that defines details about color, font style, etc. Since you want different colors, you will need to apply different scopes. You will need to define a custom Symbol List preference file so everything gets included properly. The following is from the Java package.
<?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>name</key>
<string>Symbol List: Classes</string>
<key>scope</key>
<string>source.java meta.class meta.class.identifier</string>
<key>settings</key>
<dict>
<key>showInSymbolList</key>
<integer>1</integer>
</dict>
<key>uuid</key>
<string>22E489AE-989E-4A76-9C18-89944CF5013D</string>
</dict>
</plist>
You will define whatever scopes are being applied to the entries you want to appear in the list.
I too made one myself for Cadence Skill. You can try it out here
https://github.com/noisyass2/SublimeCadenceSkill

Resources