On Jan 4, 2005, at 10:04 PM, Allan Odgaard wrote:
On Jan 4, 2005, at 21:39, Xavier Noria wrote:
Which language do you want to write it in?
In Perl or Python preferably. The XML solution via plutil looks like the easiest, but for curiosity how would you deal with the structure in memory without an intermediate XML file? If there was something in Cocoa to deal directly with that format maybe I could play a bit with PyObjC maybe.
There is, NSDictionary (which is a hash/associative array) can load its values using the dictionaryWithContentsOfFile: selector/method.
So in Objective-C that would be: id dict = [NSDictionary dictionaryWithContentsOfFile:syntaxFile];
And now dict is an associative array representing the contents of the syntaxFile. E.g. you'd access patterns, which is an array and each element is again a dictionary (which may have patterns again)...
Magnific, with that class this is far easier than I expected.
I have not generalised the script yet, but since it is gonna be something very targeted to what I want to be useful to others anyway, here it goes the starting point which is really simple if you know just a bit of Python. After installing PyObjC[*] this properly modifies a property list (I did the trials with the one for Perl):
<mockup>
#!/usr/bin/python
from Foundation import NSMutableDictionary
fg = "foregroundColor"
perl = u"/path/to/your/Perl.tmbundle/Syntaxes/Perl.plist" plist = NSMutableDictionary.dictionaryWithContentsOfFile_(perl) for p in plist['patterns']: name = p['name'] if name == "Control Structures": del p['fontStyle'] p[fg] = "#881950" if name == "Reserved Words": del p['fontStyle'] p[fg] = "#000000" # ...
plist.writeToFile_atomically_(perl, 1)
</mockup>
Really, that's all.
That needs you to inspect the .plist for the names you are interested in. Just printing the plist variable after its creation works like a charm and formats the structure for easy reading:
print plist
In fact, as you see, you have there a clean interface to redefine the entire .plist as you wish.
For Perl there's CamelBones[**], which I have not tried yet but looks like the task would be as easy.
Great!
-- fxn
[*] http://pyobjc.sourceforge.net/ [**] http://camelbones.sourceforge.net/index.php