1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-01 01:32:04 +03:00

GH-339 Migrate dirty status

This commit is contained in:
Tae Won Ha 2017-01-06 08:51:01 +01:00
parent e0ede2a02c
commit 08283e2081
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
4 changed files with 39 additions and 34 deletions

View File

@ -97,6 +97,8 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
case NeoVimAgentMsgIdGetEscapeFileNames: return data_sync(data, outputCondition, neovim_escaped_filenames);
case NeoVimAgentMsgIdGetDirtyDocs: return data_sync(data, outputCondition, neovim_has_dirty_docs);
default: break;
}
@ -280,11 +282,6 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
[self performSelector:@selector(quit) onThread:_localServerThread withObject:nil waitUntilDone:NO];
return nil;
case NeoVimAgentMsgIdGetDirtyDocs: {
bool dirty = server_has_dirty_docs();
return [NSData dataWithBytes:&dirty length:sizeof(bool)];
}
default:
return nil;
}

View File

@ -16,7 +16,6 @@ extern void server_vim_input(NSString *input);
extern void server_delete(NSInteger count);
extern void server_resize(int width, int height);
extern void server_vim_input_marked_text(NSString *markedText);
extern bool server_has_dirty_docs();
extern void server_quit();
extern void neovim_select_window(void **argv);
@ -26,3 +25,4 @@ extern void neovim_vim_command_output(void **argv);
extern void neovim_set_bool_option(void **argv);
extern void neovim_get_bool_option(void **argv);
extern void neovim_escaped_filenames(void **argv);
extern void neovim_has_dirty_docs(void **argv);

View File

@ -445,8 +445,22 @@ static void neovim_input(void **argv) {
}
}
static bool has_dirty_docs() {
FOR_ALL_BUFFERS(buffer) {
if (buffer->b_p_bl == 0) {
continue;
}
if (bufIsChanged(buffer)) {
return true;
}
}
return false;
}
static void send_dirty_status() {
bool new_dirty_status = server_has_dirty_docs();
bool new_dirty_status = has_dirty_docs();
DLOG("dirty status: %d vs. %d", _dirty, new_dirty_status);
if (_dirty == new_dirty_status) {
return;
@ -671,21 +685,6 @@ void server_vim_input_marked_text(NSString *markedText) {
});
}
bool server_has_dirty_docs() {
FOR_ALL_BUFFERS(buffer) {
if (buffer->b_p_bl == 0) {
continue;
}
if (bufIsChanged(buffer)) {
return true;
}
}
return false;
}
static NeoVimBuffer *buffer_for(buf_T *buf) {
// To be sure...
if (buf == NULL) {
@ -772,6 +771,19 @@ static void work_and_write_data_sync(void **argv, work_block block) {
[outputCondition unlock];
}
#pragma mark Functions for neovim's main loop
// already in an autorelease pool and in neovim's main loop
static NSString *escaped_filename(NSString *filename) {
const char *file_system_rep = filename.fileSystemRepresentation;
char_u *escaped_filename = vim_strsave_fnameescape((char_u *) file_system_rep, 0);
NSString *result = [NSString stringWithCString:(const char *) escaped_filename encoding:NSUTF8StringEncoding];
xfree(escaped_filename);
return result;
}
static void work_async(void **argv, work_block block) {
NSData *data = argv[0];
block(data);
@ -941,16 +953,6 @@ void neovim_get_bool_option(void **argv) {
});
}
static NSString *escaped_filename(NSString *filename) {
const char *file_system_rep = filename.fileSystemRepresentation;
char_u *escaped_filename = vim_strsave_fnameescape((char_u *) file_system_rep, 0);
NSString *result = [NSString stringWithCString:(const char *) escaped_filename encoding:NSUTF8StringEncoding];
xfree(escaped_filename);
return result;
}
void neovim_escaped_filenames(void **argv) {
work_and_write_data_sync(argv, ^NSData *(NSData *data) {
NSArray *fileNames = [NSKeyedUnarchiver unarchiveObjectWithData:data];
@ -963,3 +965,9 @@ void neovim_escaped_filenames(void **argv) {
return [NSKeyedArchiver archivedDataWithRootObject:result];
});
}
void neovim_has_dirty_docs(void **argv) {
work_and_write_data_sync(argv, ^NSData *(NSData *data) {
return [NSKeyedArchiver archivedDataWithRootObject:@(has_dirty_docs())];
});
}

View File

@ -271,8 +271,8 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
return YES;
}
bool *values = data_to_bool_array(response, 1);
return values[0];
NSNumber *value = [NSKeyedUnarchiver unarchiveObjectWithData:response];
return (bool) value.boolValue;
}
- (NSString *)escapedFileName:(NSString *)fileName {