Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use FS Streams to watch modifications in ~/.vim

  • Loading branch information...
commit 1b68724361097e8c4446caf01853c3fd2e0cb07d 1 parent 550e75e
@b4winckler authored
Showing with 74 additions and 0 deletions.
  1. +4 −0 src/MacVim/MMAppController.h
  2. +70 −0 src/MacVim/MMAppController.m
View
4 src/MacVim/MMAppController.h
@@ -29,6 +29,10 @@
int preloadPid;
BOOL shouldActivateWhenNextWindowOpens;
+#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
+ FSEventStreamRef fsEventStream;
+#endif
+
#ifdef MM_ENABLE_PLUGINS
NSMenuItem *plugInMenuItem;
#endif
View
70 src/MacVim/MMAppController.m
@@ -48,6 +48,7 @@
#endif
#import <unistd.h>
+#import <CoreServices/CoreServices.h>
#define MM_HANDLE_XCODE_MOD_EVENT 0
@@ -111,6 +112,9 @@ - (void)clearPreloadCacheWithCount:(int)count;
- (NSDate *)rcFilesModificationDate;
- (BOOL)openVimControllerWithArguments:(NSDictionary *)arguments;
- (void)activateWhenNextWindowOpens;
+- (void)startWatchingVimDir;
+- (void)stopWatchingVimDir;
+- (void)handleFSEvent;
#ifdef MM_ENABLE_PLUGINS
- (void)removePlugInMenu;
@@ -120,6 +124,19 @@ - (void)addPlugInMenuToMenu:(NSMenu *)mainMenu;
+#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
+ static void
+fsEventCallback(ConstFSEventStreamRef streamRef,
+ void *clientCallBackInfo,
+ size_t numEvents,
+ void *eventPaths,
+ const FSEventStreamEventFlags eventFlags[],
+ const FSEventStreamEventId eventIds[])
+{
+ [[MMAppController sharedInstance] handleFSEvent];
+}
+#endif
+
@implementation MMAppController
+ (void)initialize
@@ -296,6 +313,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification
#endif
[self scheduleVimControllerPreloadAfterDelay:2];
+ [self startWatchingVimDir];
}
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
@@ -619,6 +637,8 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:
- (void)applicationWillTerminate:(NSNotification *)notification
{
+ [self stopWatchingVimDir];
+
#ifdef MM_ENABLE_PLUGINS
[[MMPlugInManager sharedManager] unloadAllPlugIns];
#endif
@@ -1590,6 +1610,56 @@ - (void)activateWhenNextWindowOpens
shouldActivateWhenNextWindowOpens = YES;
}
+- (void)startWatchingVimDir
+{
+ NSLog(@"%s", _cmd);
+#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
+ if (fsEventStream)
+ return;
+ if (NULL == FSEventStreamStart)
+ return; // FSStream functions are weakly linked
+
+ NSString *path = [@"~/.vim" stringByExpandingTildeInPath];
+ NSArray *pathsToWatch = [NSArray arrayWithObject:path];
+
+ fsEventStream = FSEventStreamCreate(NULL, &fsEventCallback, NULL,
+ (CFArrayRef)pathsToWatch, kFSEventStreamEventIdSinceNow, 1.0,
+ kFSEventStreamCreateFlagNone);
+
+ FSEventStreamScheduleWithRunLoop(fsEventStream,
+ [[NSRunLoop currentRunLoop] getCFRunLoop],
+ kCFRunLoopDefaultMode);
+
+ FSEventStreamStart(fsEventStream);
+ NSLog(@"Started FS event stream");
+#endif
+}
+
+- (void)stopWatchingVimDir
+{
+ NSLog(@"%s", _cmd);
+#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
+ if (NULL == FSEventStreamStop)
+ return; // FSStream functions are weakly linked
+
+ if (fsEventStream) {
+ FSEventStreamStop(fsEventStream);
+ FSEventStreamInvalidate(fsEventStream);
+ FSEventStreamRelease(fsEventStream);
+ fsEventStream = NULL;
+ NSLog(@"Stopped FS event stream");
+ }
+#endif
+
+}
+
+- (void)handleFSEvent
+{
+ NSLog(@"%s", _cmd);
+ [self clearPreloadCacheWithCount:-1];
+ [self scheduleVimControllerPreloadAfterDelay:0.5];
+}
+
@end // MMAppController (Private)
Please sign in to comment.
Something went wrong with that request. Please try again.