new replace range api

This commit is contained in:
Allen Webster 2016-02-23 15:41:11 -05:00
parent a883787f55
commit e16ab8c1c4
4 changed files with 97 additions and 13 deletions

View File

@ -268,7 +268,7 @@ extern "C"{
#define DIRECTORY_HAS_FILE_SIG(name) int name(String dir, char *filename)
#define DIRECTORY_CD_SIG(name) int name(String *dir, char *rel_path)
// Buffer manipulation
// Direct buffer manipulation
#define GET_BUFFER_MAX_INDEX_SIG(name) int name(void *cmd_context)
#define GET_BUFFER_SIG(name) Buffer_Summary name(void *cmd_context, int index)
#define GET_ACTIVE_BUFFER_SIG(name) Buffer_Summary name(void *cmd_context)
@ -277,6 +277,8 @@ extern "C"{
#define BUFFER_SEEK_DELIMITER_SIG(name) int name(void *cmd_context, Buffer_Summary *buffer, int start, char delim, int *out)
#define BUFFER_READ_RANGE_SIG(name) int name(void *cmd_context, Buffer_Summary *buffer, int start, int end, char *out)
#define BUFFER_REPLACE_RANGE_SIG(name) int name(void *cmd_context, Buffer_Summary *buffer, int start, int end, char *str, int len)
extern "C"{
// Command exectuion
typedef EXECUTE_COMMAND_SIG(Exec_Command_Function);
@ -297,6 +299,8 @@ extern "C"{
typedef BUFFER_SEEK_DELIMITER_SIG(Buffer_Seek_Delimiter_Function);
typedef BUFFER_READ_RANGE_SIG(Buffer_Read_Range_Function);
typedef BUFFER_REPLACE_RANGE_SIG(Buffer_Replace_Range_Function);
}
struct Application_Links{
@ -319,6 +323,8 @@ struct Application_Links{
Buffer_Seek_Delimiter_Function *buffer_seek_delimiter;
Buffer_Read_Range_Function *buffer_read_range;
Buffer_Replace_Range_Function *buffer_replace_range;
};
struct Custom_API{

85
4ed.cpp
View File

@ -178,12 +178,12 @@ struct Command_Data{
Delay *delay;
App_Vars *vars;
Exchange *exchange;
System_Functions *system;
i32 screen_width, screen_height;
Key_Event_Data key;
Partition part;
System_Functions *system;
};
struct Command_Parameter{
@ -2065,6 +2065,18 @@ extern "C"{
cmd->part.pos = 0;
}
DIRECTORY_GET_HOT_SIG(external_directory_get_hot){
Command_Data *cmd = (Command_Data*)cmd_context;
Hot_Directory *hot = &cmd->vars->hot_directory;
i32 copy_max = max - 1;
hot_directory_clean_end(hot);
if (copy_max > hot->string.size)
copy_max = hot->string.size;
memcpy(buffer, hot->string.str, copy_max);
buffer[copy_max] = 0;
return(copy_max);
}
GET_BUFFER_MAX_INDEX_SIG(external_get_buffer_max_index){
Command_Data *cmd = (Command_Data*)cmd_context;
Working_Set *working_set;
@ -2150,8 +2162,8 @@ extern "C"{
file = working_set->files + buffer->file_id;
if (!file->state.is_dummy && file_is_ready(file)){
size = buffer_size(&file->state.buffer);
result = 1;
if (start < size){
result = 1;
*out = buffer_seek_delimiter(&file->state.buffer, start, delim);
if (*out < 0) *out = 0;
if (*out > size) *out = size;
@ -2163,16 +2175,67 @@ extern "C"{
return(result);
}
DIRECTORY_GET_HOT_SIG(external_directory_get_hot){
BUFFER_READ_RANGE_SIG(external_buffer_read_range){
Command_Data *cmd = (Command_Data*)cmd_context;
Hot_Directory *hot = &cmd->vars->hot_directory;
i32 copy_max = max - 1;
hot_directory_clean_end(hot);
if (copy_max > hot->string.size)
copy_max = hot->string.size;
memcpy(buffer, hot->string.str, copy_max);
buffer[copy_max] = 0;
return(copy_max);
Editing_File *file;
Working_Set *working_set;
int result = 0;
int size;
if (buffer->exists){
working_set = cmd->working_set;
file = working_set->files + buffer->file_id;
if (!file->state.is_dummy && file_is_ready(file)){
size = buffer_size(&file->state.buffer);
if (0 <= start && start <= end && end <= size){
result = 1;
buffer_stringify(&file->state.buffer, start, end, out);
}
fill_buffer_summary(buffer, file, working_set);
}
}
return(result);
}
BUFFER_REPLACE_RANGE_SIG(external_buffer_replace_range){
Command_Data *cmd = (Command_Data*)cmd_context;
Editing_File *file;
Working_Set *working_set;
System_Functions *system;
Mem_Options *mem;
Editing_Layout *layout;
int result = 0;
int size;
int next_cursor, pos;
if (buffer->exists){
working_set = cmd->working_set;
file = working_set->files + buffer->file_id;
if (!file->state.is_dummy && file_is_ready(file)){
size = buffer_size(&file->state.buffer);
if (0 <= start && start <= end && end <= size){
result = 1;
system = cmd->system;
mem = cmd->mem;
layout = cmd->layout;
pos = file->state.cursor_pos;
if (pos < start) next_cursor = pos;
else if (pos < end) next_cursor = start + len;
else next_cursor = pos + end - start + len;
file_replace_range(system, mem, file, layout,
start, end, str, len, next_cursor);
}
fill_buffer_summary(buffer, file, working_set);
}
}
return(result);
}
}

View File

@ -1978,6 +1978,21 @@ view_do_white_batch_edit(System_Functions *system, Mem_Options *mem, File_View *
#endif
}
inline void
file_replace_range(System_Functions *system,
Mem_Options *mem, Editing_File *file, Editing_Layout *layout,
i32 start, i32 end, char *str, i32 len, i32 next_cursor){
Edit_Spec spec = {};
spec.step.type = ED_NORMAL;
spec.step.edit.start = start;
spec.step.edit.end = end;
spec.step.edit.len = len;
spec.step.pre_pos = file->state.cursor_pos;
spec.step.post_pos = next_cursor;
spec.str = (u8*)str;
file_do_single_edit(system, mem, file, layout, spec, hist_normal);
}
inline void
view_replace_range(System_Functions *system,
Mem_Options *mem, File_View *view, Editing_Layout *layout,

BIN
vc120.pdb

Binary file not shown.