Normalize filenames to NFKC before opening

Vim does not cope very well with Unicode decomposed form NFD (i.e. it
does not normalize to composed form before rendering) which causes
problems since HFS+ stores filenames in NFD.  To work around this issue
normalize to compatibility form C before passing filenames to Vim.

(This is not a solution to the problem with NFD since files stored in
NFD will still be problematic but at least a user can work around this
issue by making sure files are in composed form before opening them.)
This commit is contained in:
Bjorn Winckler
2009-06-23 20:38:39 +02:00
parent 5433ca7d4c
commit edbdca29e1
4 changed files with 35 additions and 0 deletions
+4
View File
@@ -819,6 +819,10 @@ fsEventCallback(ConstFSEventStreamRef streamRef,
NSMutableDictionary *arguments = (args ? [[args mutableCopy] autorelease]
: [NSMutableDictionary dictionary]);
// Filenames on HFS+ are in NFD but Vim does not handle this form very well
// so normalize to NFKC first.
filenames = normalizeFilenames(filenames);
//
// a) Filter out any already open files
//
+4
View File
@@ -263,6 +263,10 @@ static BOOL isUnsafeMessage(int msgid);
if (splitVert && MMLayoutHorizontalSplit == layout)
layout = MMLayoutVerticalSplit;
// Filenames on HFS+ are in NFD but Vim does not handle this form very well
// so normalize to NFKC first.
filenames = normalizeFilenames(filenames);
NSDictionary *args = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:layout], @"layout",
filenames, @"filenames",
+7
View File
@@ -135,3 +135,10 @@ enum {
// release it.
NSView *showHiddenFilesView();
// Convert filenames (which are in decomposed form, NFD, on HFS+) to
// normalization form combatibility C (NFKC). (This is necessary because Vim
// does not automatically compose NFD. We choose NFKC instead of NFC for the
// somewhat random reason that this is what is used on Windows and hence
// hopefully Vim is better prepared for it.)
NSArray *normalizeFilenames(NSArray *filenames);
+20
View File
@@ -290,3 +290,23 @@ showHiddenFilesView()
return button;
}
NSArray *
normalizeFilenames(NSArray *filenames)
{
NSMutableArray *outnames = [NSMutableArray array];
if (!filenames)
return outnames;
unsigned i, count = [filenames count];
for (i = 0; i < count; ++i) {
NSString *nfkc = [filenames objectAtIndex:i];
nfkc = [nfkc precomposedStringWithCompatibilityMapping];
[outnames addObject:nfkc];
}
return outnames;
}