Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

titaniumdecoy

macrumors member
Original poster
Oct 13, 2005
86
0
Hi all,

I am writing a text editor in Cocoa. I plan to implement code folding and line bookmarking. However, I cannot figure out how to store this information so that it will be available the next time the text file is opened. When using TextMate, for instance, your code folding and line bookmarks are restored when you reopen a text file even if it has been moved or renamed. How is this possible?

Thanks.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Without seeing the TextMate source code I couldn't say for sure but I'd suggest they use HFS+ Extended Attributes to store the data...
 

titaniumdecoy

macrumors member
Original poster
Oct 13, 2005
86
0
Using HFS+ attributes is a possibility, I suppose, but I have been hearing a lot about ZFS and I would rather use a more portable approach, if possible. Even so, can anyone point me to example code for manipulating HFS+ attributes? I can't seem to find anything.

Someone suggested storing aliases as data in a file. (As I understand it, aliases can only be used with Carbon code; perhaps this has changed in 10.5?) However, this is once again beyond me and I would appreciate any pointers on how to go about implementing this. On the other hand, if I used this approach I assume I would have to iterate through each alias and compare it to the file being opened, which could take a long time.

What is my best option?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
There is no built in Cocoa API for this. I you end up in Carbon or worse to do it. I was trying to find the API last night but gave up.

I can, however, confirm that text mates uses Extended Attributes for something:

MacBook-Pro:java robbie$ xattr -l PairMatcher.java
com.macromates.caret: {column = 49; line = 8; }

PairMatcher.java has been edited by TextMate and as you can see has an extended attribute which matches their domain. This only appears to hold the caret position, not the folding status.

I can't find any API other than the BSD level setxattr and getxattr.

Note there is no issue in using these from Cocoa.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.