new get buffer api
This commit is contained in:
parent
a77861ccfd
commit
9a59958006
|
@ -5,6 +5,12 @@
|
|||
#define FCPP_STRING_IMPLEMENTATION
|
||||
#include "4coder_string.h"
|
||||
|
||||
// NOTE(allen): See exec_command and surrounding code in 4coder_helper.h
|
||||
// to decide whether you want macro translations, without them you will
|
||||
// have to manipulate the command and parameter stack through
|
||||
// "app->" which may be more or less clear depending on your use.
|
||||
#define DisableMacroTranslations 0
|
||||
|
||||
#include "4coder_custom.h"
|
||||
#include "4coder_helper.h"
|
||||
|
||||
|
|
|
@ -220,6 +220,7 @@ struct Buffer_Summary{
|
|||
// NOTE(allen): None of these members nor any of the data pointed to
|
||||
// by these members should be modified, I would have made them const...
|
||||
// but that actually causes problems for C++ reasons.
|
||||
int found_buffer;
|
||||
int file_id;
|
||||
|
||||
int size;
|
||||
|
@ -259,31 +260,47 @@ extern "C"{
|
|||
#define PUSH_MEMORY_SIG(name) char* name(void *cmd_context, int len)
|
||||
#define EXECUTE_COMMAND_SIG(name) void name(void *cmd_context, int command_id)
|
||||
#define CLEAR_PARAMETERS_SIG(name) void name(void *cmd_context)
|
||||
#define GET_ACTIVE_BUFFER_SIG(name) Buffer_Summary name(void *cmd_context)
|
||||
#define DIRECTORY_GET_HOT_SIG(name) int name(void *cmd_context, char *buffer, int max)
|
||||
#define DIRECTORY_HAS_FILE_SIG(name) int name(String dir, char *filename)
|
||||
#define DIRECTORY_CD_SIG(name) int name(String *dir, char *rel_path)
|
||||
|
||||
#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)
|
||||
#define GET_BUFFER_BY_NAME(name) Buffer_Summary name(void *cmd_context, String filename)
|
||||
|
||||
extern "C"{
|
||||
typedef EXECUTE_COMMAND_SIG(Exec_Command_Function);
|
||||
typedef PUSH_PARAMETER_SIG(Push_Parameter_Function);
|
||||
typedef PUSH_MEMORY_SIG(Push_Memory_Function);
|
||||
typedef CLEAR_PARAMETERS_SIG(Clear_Parameters_Function);
|
||||
typedef GET_ACTIVE_BUFFER_SIG(Get_Active_Buffer_Function);
|
||||
typedef DIRECTORY_GET_HOT_SIG(Directory_Get_Hot);
|
||||
typedef DIRECTORY_HAS_FILE_SIG(Directory_Has_File);
|
||||
typedef DIRECTORY_CD_SIG(Directory_CD);
|
||||
|
||||
typedef GET_BUFFER_MAX_INDEX_SIG(Get_Buffer_Max_Index_Function);
|
||||
typedef GET_BUFFER_SIG(Get_Buffer_Function);
|
||||
typedef GET_ACTIVE_BUFFER_SIG(Get_Active_Buffer_Function);
|
||||
typedef GET_BUFFER_BY_NAME(Get_Buffer_By_Name_Function);
|
||||
}
|
||||
|
||||
struct Application_Links{
|
||||
// Command exectuion
|
||||
Exec_Command_Function *exec_command_keep_stack;
|
||||
Push_Parameter_Function *push_parameter;
|
||||
Push_Memory_Function *push_memory;
|
||||
Clear_Parameters_Function *clear_parameters;
|
||||
Get_Active_Buffer_Function *get_active_buffer;
|
||||
|
||||
// File system navigation
|
||||
Directory_Get_Hot *directory_get_hot;
|
||||
Directory_Has_File *directory_has_file;
|
||||
Directory_CD *directory_cd;
|
||||
|
||||
// Buffer manipulation
|
||||
Get_Buffer_Max_Index_Function *get_buffer_max_index;
|
||||
Get_Buffer_Function *get_buffer;
|
||||
Get_Active_Buffer_Function *get_active_buffer;
|
||||
Get_Buffer_By_Name_Function *get_buffer_by_name;
|
||||
};
|
||||
|
||||
struct Custom_API{
|
||||
|
|
|
@ -242,6 +242,8 @@ push_directory(Application_Links *app, void *cmd_context){
|
|||
|
||||
#define dir_string(d) ((d).str), ((d).size)
|
||||
|
||||
#if DisableMacroTranslations == 0
|
||||
|
||||
inline void
|
||||
exec_command_(Application_Links *app, void *cmd_context, Command_ID id){
|
||||
app->exec_command_keep_stack(cmd_context, id);
|
||||
|
@ -260,4 +262,5 @@ exec_command_(Application_Links *app, void *cmd_context, Custom_Command_Function
|
|||
|
||||
#define exec_command(cmd_context, cmd) exec_command_(app, cmd_context, cmd)
|
||||
|
||||
#endif
|
||||
|
||||
|
|
129
4ed.cpp
129
4ed.cpp
|
@ -238,18 +238,17 @@ COMMAND_DECL(write_character){
|
|||
USE_LAYOUT(layout);
|
||||
USE_MEM(mem);
|
||||
|
||||
u8 character = (u8)command->key.character;
|
||||
char str_space[2];
|
||||
String string = make_string(str_space, 2);
|
||||
str_space[0] = character;
|
||||
string.size = 1;
|
||||
|
||||
i32 pos;
|
||||
pos = view->cursor.pos;
|
||||
i32 next_cursor_pos = view->cursor.pos + string.size;
|
||||
view_replace_range(system, mem, view, layout, pos, pos, string.str, string.size, next_cursor_pos);
|
||||
view_cursor_move(view, next_cursor_pos);
|
||||
file->state.cursor_pos = view->cursor.pos;
|
||||
char character;
|
||||
i32 pos, next_cursor_pos;
|
||||
|
||||
character = command->key.character;
|
||||
if (character != 0){
|
||||
pos = view->cursor.pos;
|
||||
next_cursor_pos = view->cursor.pos + 1;
|
||||
view_replace_range(system, mem, view, layout, pos, pos, &character, 1, next_cursor_pos);
|
||||
view_cursor_move(view, next_cursor_pos);
|
||||
file->state.cursor_pos = view->cursor.pos;
|
||||
}
|
||||
}
|
||||
|
||||
COMMAND_DECL(seek_whitespace_right){
|
||||
|
@ -1681,7 +1680,7 @@ COMMAND_DECL(cursor_mark_swap){
|
|||
REQ_FILE_VIEW(view);
|
||||
|
||||
i32 pos = view->cursor.pos;
|
||||
view->cursor = view_compute_cursor_from_pos(view, view->mark);
|
||||
view_cursor_move(view, view->mark);
|
||||
view->mark = pos;
|
||||
}
|
||||
|
||||
|
@ -2010,6 +2009,22 @@ COMPOSE_DECL(compose_write_auto_tab_line){
|
|||
|
||||
globalvar Command_Function command_table[cmdid_count];
|
||||
|
||||
internal void
|
||||
fill_buffer_summary(Buffer_Summary *buffer, Editing_File *file, Working_Set *working_set){
|
||||
buffer->found_buffer = 1;
|
||||
buffer->file_id = (int)(file - working_set->files);
|
||||
buffer->size = file->state.buffer.size;
|
||||
buffer->file_cursor_pos = file->state.cursor_pos;
|
||||
|
||||
buffer->file_name_len = file->name.source_path.size;
|
||||
buffer->buffer_name_len = file->name.live_name.size;
|
||||
buffer->file_name = file->name.source_path.str;
|
||||
buffer->buffer_name = file->name.live_name.str;
|
||||
|
||||
buffer->is_lexed = file->settings.tokens_exist;
|
||||
buffer->map_id = file->settings.base_map_id;
|
||||
}
|
||||
|
||||
extern "C"{
|
||||
EXECUTE_COMMAND_SIG(external_exec_command_keep_stack){
|
||||
Command_Data *cmd = (Command_Data*)cmd_context;
|
||||
|
@ -2049,34 +2064,79 @@ extern "C"{
|
|||
cmd->part.pos = 0;
|
||||
}
|
||||
|
||||
GET_ACTIVE_BUFFER_SIG(external_get_active_buffer){
|
||||
GET_BUFFER_MAX_INDEX_SIG(external_get_buffer_max_index){
|
||||
Command_Data *cmd = (Command_Data*)cmd_context;
|
||||
Working_Set *working_set;
|
||||
int max;
|
||||
working_set = cmd->working_set;
|
||||
max = working_set->file_index_count;
|
||||
return(max);
|
||||
}
|
||||
|
||||
GET_BUFFER_SIG(external_get_buffer){
|
||||
Command_Data *cmd = (Command_Data*)cmd_context;
|
||||
Editing_File *file;
|
||||
Working_Set *working_set;
|
||||
int max;
|
||||
Buffer_Summary buffer = {};
|
||||
|
||||
File_View *view = view_to_file_view(cmd->view);
|
||||
if (view){
|
||||
Editing_File *file = view->file;
|
||||
if (file && !file->state.is_dummy){
|
||||
working_set = cmd->working_set;
|
||||
max = working_set->file_index_count;
|
||||
|
||||
if (index >= 0 && index < max){
|
||||
file = working_set->files + index;
|
||||
if (!file->state.is_dummy && file_is_ready(file)){
|
||||
#if BUFFER_EXPERIMENT_SCALPEL <= 0
|
||||
Working_Set *working_set = cmd->working_set;
|
||||
buffer.file_id = (int)(file - working_set->files);
|
||||
buffer.size = file->state.buffer.size;
|
||||
buffer.file_cursor_pos = file->state.cursor_pos;
|
||||
|
||||
buffer.file_name_len = file->name.source_path.size;
|
||||
buffer.buffer_name_len = file->name.live_name.size;
|
||||
buffer.file_name = file->name.source_path.str;
|
||||
buffer.buffer_name = file->name.live_name.str;
|
||||
|
||||
buffer.is_lexed = file->settings.tokens_exist;
|
||||
buffer.map_id = file->settings.base_map_id;
|
||||
fill_buffer_summary(&buffer, file, working_set);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return(buffer);
|
||||
}
|
||||
|
||||
|
||||
GET_ACTIVE_BUFFER_SIG(external_get_active_buffer){
|
||||
Command_Data *cmd = (Command_Data*)cmd_context;
|
||||
File_View *view;
|
||||
Editing_File *file;
|
||||
Working_Set *working_set;
|
||||
Buffer_Summary buffer = {};
|
||||
|
||||
view = view_to_file_view(cmd->view);
|
||||
if (view){
|
||||
file = view->file;
|
||||
working_set = cmd->working_set;
|
||||
|
||||
if (file && !file->state.is_dummy && file_is_ready(file)){
|
||||
#if BUFFER_EXPERIMENT_SCALPEL <= 0
|
||||
fill_buffer_summary(&buffer, file, working_set);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return(buffer);
|
||||
}
|
||||
|
||||
GET_BUFFER_BY_NAME(external_get_buffer_by_name){
|
||||
Command_Data *cmd = (Command_Data*)cmd_context;
|
||||
Editing_File *file;
|
||||
Working_Set *working_set;
|
||||
i32 index;
|
||||
Buffer_Summary buffer = {};
|
||||
|
||||
working_set = cmd->working_set;
|
||||
if (table_find(&working_set->table, filename, &index)){
|
||||
file = working_set->files + index;
|
||||
if (!file->state.is_dummy && file_is_ready(file)){
|
||||
#if BUFFER_EXPERIMENT_SCALPEL <= 0
|
||||
fill_buffer_summary(&buffer, file, working_set);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return(buffer);
|
||||
}
|
||||
|
||||
DIRECTORY_GET_HOT_SIG(external_directory_get_hot){
|
||||
Command_Data *cmd = (Command_Data*)cmd_context;
|
||||
Hot_Directory *hot = &cmd->vars->hot_directory;
|
||||
|
@ -2096,10 +2156,15 @@ app_links_init(System_Functions *system){
|
|||
app_links.push_parameter = external_push_parameter;
|
||||
app_links.push_memory = external_push_memory;
|
||||
app_links.clear_parameters = external_clear_parameters;
|
||||
app_links.get_active_buffer = external_get_active_buffer;
|
||||
|
||||
app_links.directory_get_hot = external_directory_get_hot;
|
||||
app_links.directory_has_file = system->directory_has_file;
|
||||
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_active_buffer = external_get_active_buffer;
|
||||
app_links.get_buffer_by_name = external_get_buffer_by_name;
|
||||
}
|
||||
|
||||
#if FRED_INTERNAL
|
||||
|
|
|
@ -197,7 +197,7 @@ table_add(File_Table *table, String name, i32 id){
|
|||
return 0;
|
||||
}
|
||||
|
||||
internal bool32
|
||||
internal b32
|
||||
table_find_pos(File_Table *table, String name, i32 *index){
|
||||
File_Table_Entry e;
|
||||
i32 i;
|
||||
|
|
Loading…
Reference in New Issue