« Return to Thread: MacVim file encoding and Quicklook

MacVim file encoding and Quicklook

by Nico Weber :: Rate this Message:

Reply to Author | View in Thread


Hi all,

Here's a little experiment. Take the following text and copy it to the  
clipboard:

<text>
|♜|♞|♝|♛|♚|♝|♞|♜|
|♟|♟|♟|♟|♟|♟|♟|♟|
|♙|♙|♙|♙|♙|♙|♙|♙|
|♙|♙|♙|♙|♙|♙|♙|♙|
|♙|♙|♙|♙|♙|♙|♙|♙|
|♙|♙|♙|♙|♙|♙|♙|♙|
|♙|♙|♙|♙|♙|♙|♙|♙|
|♙|♙|♙|♙|♙|♙|♙|♙|
</text>

Now paste it (1) into TextEdit and save it  and (2) paste it into  
MacVim and save it. (Other text with non-ascii characters will do, too)

For the Leopard users out there, take a look at the resulting files  
with Quicklook.

Results: The file written by TextEdit looks ok in QL, the file written  
by MacVim does not. If you compare the two files, you'll see that they  
both use UTF-8 encoding, so that's not what confuses Quicklook. So,  
what's the cause? /Developer/Examples/AppKit/TextEdit/README.rtf hints  
at some extended file attributes that TextEdit stores in Leopard and  
refers to http://developer.apple.com/releasenotes/Cocoa/ 
Foundation.html for more information. If you search the latter page  
for "com.apple.TextEncoding", you'll see that `-[NSString  
writeToFile:atomically:encoding:error]` and friends write the encoding  
to an extended attribute. There's also a description of the format of  
the extended attribute ("this is not some undocumented stuff").

  Indeed, if you check the two files with `ls -l`, you'll see that the  
file written by TextEdit has an "@" (that means it has an extended  
attribute). Now, if you do `ls -l@` or `xattr -l filename`, you'll see  
that the TextEdit file has the com.apple.TextEncoding attribute set:

     Macintosh-2:b nico$ xattr -l texteditfile.txt
     com.apple.TextEncoding: UTF-8;134217984

The file written by MacVim does not have this attribute. If you add it  
(`xattr -w com.apple.TextEncoding 'UTF-8;134217984' macvimfile.txt`),  
the file shows up correctly in Quicklook (and in TextEdit too; it  
didn't do that before).

Obvious suggestion: MacVim should have an option 'encodingxattr` that  
can have the values 'read' and 'write' (default 'read,write'). If  
'write' is set, the com.apple.TextEncoding xattr is written when  
saving a file. When 'read' is set, the xattr is checked when reading a  
file.

According to http://arstechnica.com/reviews/os/macosx-10-4.ars/7 , the  
xattr api is already present in Tiger, so the option could be  
supported in both Tiger and Leopard (TextEdit and Quicklook only seem  
to honor the xattr on Leopard, though).

Comments?

Thanks,
Nico
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

 « Return to Thread: MacVim file encoding and Quicklook