buffer api up and running
This commit is contained in:
parent
e16ab8c1c4
commit
c7a6225fe2
|
@ -57,8 +57,8 @@ bool str_match(const char *a, int len_a, const char *b, int len_b){
|
||||||
HOOK_SIG(my_file_settings){
|
HOOK_SIG(my_file_settings){
|
||||||
Buffer_Summary buffer = app->get_active_buffer(cmd_context);
|
Buffer_Summary buffer = app->get_active_buffer(cmd_context);
|
||||||
|
|
||||||
// NOTE(allen|a3.4.2): Whenever you ask for a buffer, you should check that the
|
// NOTE(allen|a3.4.2): Whenever you ask for a buffer, you should first check that
|
||||||
// exists flag is set to true before using it. Reasons why the buffer might not exist:
|
// the exists field is set to true. Reasons why the buffer might not exist:
|
||||||
// -The active panel does not contain a buffer and get_active_buffer was used
|
// -The active panel does not contain a buffer and get_active_buffer was used
|
||||||
// -The index provided to get_buffer was out of range [0,max) or that index is associated to a dummy buffer
|
// -The index provided to get_buffer was out of range [0,max) or that index is associated to a dummy buffer
|
||||||
// -The name provided to get_buffer_by_name did not match any of the existing buffers
|
// -The name provided to get_buffer_by_name did not match any of the existing buffers
|
||||||
|
@ -81,6 +81,19 @@ HOOK_SIG(my_file_settings){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CUSTOM_COMMAND_SIG(write_increment){
|
||||||
|
Buffer_Summary buffer = app->get_active_buffer(cmd_context);
|
||||||
|
|
||||||
|
// NOTE(allen|a3.4.2): In addition to checking whether the buffer exists after a query,
|
||||||
|
// if you're going to read from or write to the buffer, you should check ready. A buffer
|
||||||
|
// is usually ready, but when a buffer has just been opened it is possible that the contents
|
||||||
|
// haven't been filled yet. If the buffer is not ready trying to read or write it is invalid.
|
||||||
|
// (See my_file_settings for comments on the exists field).
|
||||||
|
if (buffer.exists && buffer.ready){
|
||||||
|
app->buffer_replace_range(cmd_context, &buffer, buffer.file_cursor_pos, buffer.file_cursor_pos, "++", 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CUSTOM_COMMAND_SIG(open_in_other){
|
CUSTOM_COMMAND_SIG(open_in_other){
|
||||||
exec_command(cmd_context, cmdid_change_active_panel);
|
exec_command(cmd_context, cmdid_change_active_panel);
|
||||||
exec_command(cmd_context, cmdid_interactive_open);
|
exec_command(cmd_context, cmdid_interactive_open);
|
||||||
|
@ -264,6 +277,8 @@ extern "C" GET_BINDING_DATA(get_bindings){
|
||||||
bind(context, '\n', MDFR_SHIFT, write_and_auto_tab);
|
bind(context, '\n', MDFR_SHIFT, write_and_auto_tab);
|
||||||
bind(context, ' ', MDFR_SHIFT, cmdid_write_character);
|
bind(context, ' ', MDFR_SHIFT, cmdid_write_character);
|
||||||
|
|
||||||
|
bind(context, '=', MDFR_CTRL, write_increment);
|
||||||
|
|
||||||
end_map(context);
|
end_map(context);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -276,7 +276,6 @@ extern "C"{
|
||||||
|
|
||||||
#define BUFFER_SEEK_DELIMITER_SIG(name) int name(void *cmd_context, Buffer_Summary *buffer, int start, char delim, int *out)
|
#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_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)
|
#define BUFFER_REPLACE_RANGE_SIG(name) int name(void *cmd_context, Buffer_Summary *buffer, int start, int end, char *str, int len)
|
||||||
|
|
||||||
extern "C"{
|
extern "C"{
|
||||||
|
@ -299,7 +298,6 @@ extern "C"{
|
||||||
|
|
||||||
typedef BUFFER_SEEK_DELIMITER_SIG(Buffer_Seek_Delimiter_Function);
|
typedef BUFFER_SEEK_DELIMITER_SIG(Buffer_Seek_Delimiter_Function);
|
||||||
typedef BUFFER_READ_RANGE_SIG(Buffer_Read_Range_Function);
|
typedef BUFFER_READ_RANGE_SIG(Buffer_Read_Range_Function);
|
||||||
|
|
||||||
typedef BUFFER_REPLACE_RANGE_SIG(Buffer_Replace_Range_Function);
|
typedef BUFFER_REPLACE_RANGE_SIG(Buffer_Replace_Range_Function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +321,6 @@ struct Application_Links{
|
||||||
|
|
||||||
Buffer_Seek_Delimiter_Function *buffer_seek_delimiter;
|
Buffer_Seek_Delimiter_Function *buffer_seek_delimiter;
|
||||||
Buffer_Read_Range_Function *buffer_read_range;
|
Buffer_Read_Range_Function *buffer_read_range;
|
||||||
|
|
||||||
Buffer_Replace_Range_Function *buffer_replace_range;
|
Buffer_Replace_Range_Function *buffer_replace_range;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
12
4ed.cpp
12
4ed.cpp
|
@ -2012,7 +2012,8 @@ globalvar Command_Function command_table[cmdid_count];
|
||||||
internal void
|
internal void
|
||||||
fill_buffer_summary(Buffer_Summary *buffer, Editing_File *file, Working_Set *working_set){
|
fill_buffer_summary(Buffer_Summary *buffer, Editing_File *file, Working_Set *working_set){
|
||||||
buffer->exists = 1;
|
buffer->exists = 1;
|
||||||
buffer->exists = file_is_ready(file);
|
buffer->ready = file_is_ready(file);
|
||||||
|
buffer->is_lexed = file->settings.tokens_exist;
|
||||||
buffer->file_id = (int)(file - working_set->files);
|
buffer->file_id = (int)(file - working_set->files);
|
||||||
buffer->size = file->state.buffer.size;
|
buffer->size = file->state.buffer.size;
|
||||||
buffer->file_cursor_pos = file->state.cursor_pos;
|
buffer->file_cursor_pos = file->state.cursor_pos;
|
||||||
|
@ -2022,7 +2023,6 @@ fill_buffer_summary(Buffer_Summary *buffer, Editing_File *file, Working_Set *wor
|
||||||
buffer->file_name = file->name.source_path.str;
|
buffer->file_name = file->name.source_path.str;
|
||||||
buffer->buffer_name = file->name.live_name.str;
|
buffer->buffer_name = file->name.live_name.str;
|
||||||
|
|
||||||
buffer->is_lexed = file->settings.tokens_exist;
|
|
||||||
buffer->map_id = file->settings.base_map_id;
|
buffer->map_id = file->settings.base_map_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2250,10 +2250,18 @@ app_links_init(System_Functions *system){
|
||||||
app_links.directory_has_file = system->directory_has_file;
|
app_links.directory_has_file = system->directory_has_file;
|
||||||
app_links.directory_cd = system->directory_cd;
|
app_links.directory_cd = system->directory_cd;
|
||||||
|
|
||||||
|
app_links.get_buffer_max_index = external_get_buffer_max_index;
|
||||||
|
app_links.get_buffer = external_get_buffer;
|
||||||
|
app_links.get_buffer_by_name = external_get_buffer_by_name;
|
||||||
|
|
||||||
app_links.get_buffer_max_index = external_get_buffer_max_index;
|
app_links.get_buffer_max_index = external_get_buffer_max_index;
|
||||||
app_links.get_buffer = external_get_buffer;
|
app_links.get_buffer = external_get_buffer;
|
||||||
app_links.get_active_buffer = external_get_active_buffer;
|
app_links.get_active_buffer = external_get_active_buffer;
|
||||||
app_links.get_buffer_by_name = external_get_buffer_by_name;
|
app_links.get_buffer_by_name = external_get_buffer_by_name;
|
||||||
|
|
||||||
|
app_links.buffer_seek_delimiter = external_buffer_seek_delimiter;
|
||||||
|
app_links.buffer_read_range = external_buffer_read_range;
|
||||||
|
app_links.buffer_replace_range = external_buffer_replace_range;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FRED_INTERNAL
|
#if FRED_INTERNAL
|
||||||
|
|
Loading…
Reference in New Issue