enable_output_wrapping config option

This commit is contained in:
Allen Webster 2020-05-01 14:04:57 -07:00
parent 1e6ec53a30
commit 8b0e54c89b
14 changed files with 167 additions and 31 deletions

17
4ed.cpp
View File

@ -281,6 +281,9 @@ App_Init_Sig(app_init){
{ string_u8_litinit("*keyboard*"), &models->keyboard_buffer, true , },
};
Buffer_Hook_Function *begin_buffer_func = models->begin_buffer;
models->begin_buffer = 0;
Heap *heap = &models->heap;
for (i32 i = 0; i < ArrayCount(init_files); ++i){
Editing_File *file = working_set_allocate_file(&models->working_set, &models->lifetime_allocator);
@ -301,6 +304,8 @@ App_Init_Sig(app_init){
file_set_unimportant(file, true);
}
models->begin_buffer = begin_buffer_func;
// NOTE(allen): setup first panel
{
Panel *panel = layout_initialize(arena, &models->layout);
@ -501,6 +506,18 @@ App_Step_Sig(app_step){
event.core.flag_strings = flags;
event.core.file_names = file_names;
co_send_event(tctx, models, &event);
// NOTE(allen): Actually do the buffer settings for the built ins now.
Buffer_Hook_Function *begin_buffer_func = models->begin_buffer;
if (begin_buffer_func != 0){
Application_Links app = {};
app.tctx = tctx;
app.cmd_context = models;
begin_buffer_func(&app, models->message_buffer->id);
begin_buffer_func(&app, models->scratch_buffer->id);
begin_buffer_func(&app, models->log_buffer->id);
begin_buffer_func(&app, models->keyboard_buffer->id);
}
}
// NOTE(allen): consume event stream

View File

@ -2221,6 +2221,71 @@ set_custom_hook(Application_Links *app, Hook_ID hook_id, Void_Func *func_ptr){
}
}
api(custom) function Void_Func*
get_custom_hook(Application_Links *app, Hook_ID hook_id){
Void_Func *result = 0;
Models *models = (Models*)app->cmd_context;
switch (hook_id){
case HookID_BufferViewerUpdate:
{
result = (Void_Func*)models->buffer_viewer_update;
}break;
case HookID_DeltaRule:
{
result = (Void_Func*)models->delta_rule;
}break;
case HookID_ViewEventHandler:
{
result = (Void_Func*)models->view_event_handler;
}break;
case HookID_Tick:
{
result = (Void_Func*)models->tick;
}break;
case HookID_RenderCaller:
{
result = (Void_Func*)models->render_caller;
}break;
case HookID_WholeScreenRenderCaller:
{
result = (Void_Func*)models->whole_screen_render_caller;
}break;
case HookID_BufferNameResolver:
{
result = (Void_Func*)models->buffer_name_resolver;
}break;
case HookID_BeginBuffer:
{
result = (Void_Func*)models->begin_buffer;
}break;
case HookID_EndBuffer:
{
result = (Void_Func*)models->end_buffer;
}break;
case HookID_NewFile:
{
result = (Void_Func*)models->new_file;
}break;
case HookID_SaveFile:
{
result = (Void_Func*)models->save_file;
}break;
case HookID_BufferEditRange:
{
result = (Void_Func*)models->buffer_edit_range;
}break;
case HookID_BufferRegion:
{
result = (Void_Func*)models->buffer_region;
}break;
case HookID_Layout:
{
result = (Void_Func*)models->layout_func;
}break;
}
return(result);
}
api(custom) function b32
set_custom_hook_memory_size(Application_Links *app, Hook_ID hook_id, u64 size){
Models *models = (Models*)app->cmd_context;

View File

@ -1235,6 +1235,7 @@ config_init_default(Config_Data *config){
config->use_comment_keyword = true;
config->lister_whole_word_backspace_when_modified = false;
config->show_line_number_margins = false;
config->enable_output_wrapping = false;
config->enable_virtual_whitespace = true;
config->enable_code_wrapping = true;
@ -1301,6 +1302,7 @@ config_parse__data(Application_Links *app, Arena *arena, String_Const_u8 file_na
config_bool_var(parsed, "use_comment_keyword", 0, &config->use_comment_keyword);
config_bool_var(parsed, "lister_whole_word_backspace_when_modified", 0, &config->lister_whole_word_backspace_when_modified);
config_bool_var(parsed, "show_line_number_margins", 0, &config->show_line_number_margins);
config_bool_var(parsed, "enable_output_wrapping", 0, &config->enable_output_wrapping);
config_bool_var(parsed, "enable_virtual_whitespace", 0, &config->enable_virtual_whitespace);
@ -1552,6 +1554,7 @@ load_config_and_apply(Application_Links *app, Arena *out_arena, Config_Data *con
config_feedback_bool(scratch, &list, "use_comment_keyword", config->use_comment_keyword);
config_feedback_bool(scratch, &list, "lister_whole_word_backspace_when_modified", config->lister_whole_word_backspace_when_modified);
config_feedback_bool(scratch, &list, "show_line_number_margins", config->show_line_number_margins);
config_feedback_bool(scratch, &list, "enable_output_wrapping", config->enable_output_wrapping);
config_feedback_bool(scratch, &list, "enable_virtual_whitespace", config->enable_virtual_whitespace);
config_feedback_int(scratch, &list, "virtual_whitespace_regular_indent", config->virtual_whitespace_regular_indent);

View File

@ -201,6 +201,7 @@ struct Config_Data{
b8 use_comment_keyword;
b8 lister_whole_word_backspace_when_modified;
b8 show_line_number_margins;
b8 enable_output_wrapping;
b8 enable_virtual_whitespace;
b8 enable_code_wrapping;

View File

@ -802,8 +802,8 @@ BUFFER_HOOK_SIG(default_begin_buffer){
}
String_Const_u8 buffer_name = push_buffer_base_name(app, scratch, buffer_id);
if (string_match(buffer_name, string_u8_litexpr("*compilation*"))){
wrap_lines = false;
if (buffer_name.size > 0 && buffer_name.str[0] == '*' && buffer_name.str[buffer_name.size - 1] == '*'){
wrap_lines = global_config.enable_output_wrapping;
}
if (use_lexer){

View File

@ -2442,6 +2442,11 @@ set_buffer_system_command(Application_Links *app, Child_Process_ID process, Buff
clear_buffer(app, buffer);
if (HasFlag(flags, CLI_SendEndSignal)){
buffer_send_end_signal(app, buffer);
Buffer_Hook_Function *begin_buffer = (Buffer_Hook_Function*)get_custom_hook(app, HookID_BeginBuffer);
if (begin_buffer != 0){
begin_buffer(app, buffer);
}
}
result = true;
}

View File

@ -65,14 +65,17 @@ table_lookup(Table_u64_u64 *table, u64 key){
break;
}
if (table_empty_key == keys[index]){
result.index = index;
result.found_empty_slot = true;
result.found_erased_slot = false;
if (!result.found_erased_slot){
result.index = index;
result.found_empty_slot = true;
}
break;
}
if (table_erased_key == keys[index] && !result.found_erased_slot){
result.index = index;
result.found_erased_slot = true;
if (table_erased_key == keys[index]){
if (!result.found_erased_slot){
result.index = index;
result.found_erased_slot = true;
}
}
index += 1;
if (index >= slot_count){
@ -229,14 +232,17 @@ table_lookup(Table_u32_u16 *table, u32 key){
break;
}
if (table_empty_u32_key == keys[index]){
result.index = index;
result.found_empty_slot = true;
result.found_erased_slot = false;
if (!result.found_erased_slot){
result.index = index;
result.found_empty_slot = true;
}
break;
}
if (table_erased_u32_key == keys[index] && !result.found_erased_slot){
result.index = index;
result.found_erased_slot = true;
if (table_erased_u32_key == keys[index]){
if (!result.found_erased_slot){
result.index = index;
result.found_erased_slot = true;
}
}
index += 1;
if (index >= slot_count){
@ -392,14 +398,17 @@ table_lookup(Table_Data_u64 *table, Data key){
}
}
if (table_empty_slot == hashes[index]){
result.index = index;
result.found_empty_slot = true;
result.found_erased_slot = false;
if (!result.found_erased_slot){
result.index = index;
result.found_empty_slot = true;
}
break;
}
if (table_erased_slot == hashes[index] && !result.found_erased_slot){
result.index = index;
result.found_erased_slot = true;
if (table_erased_slot == hashes[index]){
if (!result.found_erased_slot){
result.index = index;
result.found_erased_slot = true;
}
}
index += 1;
if (index >= slot_count){
@ -565,14 +574,17 @@ table_lookup(Table_u64_Data *table, u64 key){
break;
}
if (table_empty_key == keys[index]){
result.index = index;
result.found_empty_slot = true;
result.found_erased_slot = false;
if (!result.found_erased_slot){
result.index = index;
result.found_empty_slot = true;
}
break;
}
if (table_erased_key == keys[index] && !result.found_erased_slot){
result.index = index;
result.found_erased_slot = true;
if (table_erased_key == keys[index]){
if (!result.found_erased_slot){
result.index = index;
result.found_erased_slot = true;
}
}
index += 1;
if (index >= slot_count){
@ -734,9 +746,10 @@ table_lookup(Table_Data_Data *table, Data key){
}
}
if (table_empty_slot == hashes[index]){
result.index = index;
result.found_empty_slot = true;
result.found_erased_slot = false;
if (!result.found_erased_slot){
result.index = index;
result.found_empty_slot = true;
}
break;
}
if (table_erased_slot == hashes[index] && !result.found_erased_slot){

View File

@ -363,7 +363,7 @@ static Command_Metadata fcoder_metacmd_table[244] = {
{ PROC_LINKS(list_all_substring_locations, 0), false, "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "w:\\4ed\\code\\custom\\4coder_search.cpp", 36, 171 },
{ PROC_LINKS(list_all_substring_locations_case_insensitive, 0), false, "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "w:\\4ed\\code\\custom\\4coder_search.cpp", 36, 183 },
{ PROC_LINKS(load_project, 0), false, "load_project", 12, "Looks for a project.4coder file in the current directory and tries to load it. Looks in parent directories until a project file is found or there are no more parents.", 167, "w:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 864 },
{ PROC_LINKS(load_theme_current_buffer, 0), false, "load_theme_current_buffer", 25, "Parse the current buffer as a theme file and add the theme to the theme list. If the buffer has a .4coder postfix in it's name, it is removed when the name is saved.", 165, "w:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1627 },
{ PROC_LINKS(load_theme_current_buffer, 0), false, "load_theme_current_buffer", 25, "Parse the current buffer as a theme file and add the theme to the theme list. If the buffer has a .4coder postfix in it's name, it is removed when the name is saved.", 165, "w:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1630 },
{ PROC_LINKS(load_themes_default_folder, 0), false, "load_themes_default_folder", 26, "Loads all the theme files in the default theme folder.", 54, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 457 },
{ PROC_LINKS(load_themes_hot_directory, 0), false, "load_themes_hot_directory", 25, "Loads all the theme files in the current hot directory.", 55, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 469 },
{ PROC_LINKS(make_directory_query, 0), false, "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1451 },

View File

@ -122,6 +122,7 @@ vtable->get_current_input = get_current_input;
vtable->set_current_input = set_current_input;
vtable->leave_current_input_unhandled = leave_current_input_unhandled;
vtable->set_custom_hook = set_custom_hook;
vtable->get_custom_hook = get_custom_hook;
vtable->set_custom_hook_memory_size = set_custom_hook_memory_size;
vtable->get_mouse_state = get_mouse_state;
vtable->get_active_query_bars = get_active_query_bars;
@ -302,6 +303,7 @@ get_current_input = vtable->get_current_input;
set_current_input = vtable->set_current_input;
leave_current_input_unhandled = vtable->leave_current_input_unhandled;
set_custom_hook = vtable->set_custom_hook;
get_custom_hook = vtable->get_custom_hook;
set_custom_hook_memory_size = vtable->set_custom_hook_memory_size;
get_mouse_state = vtable->get_mouse_state;
get_active_query_bars = vtable->get_active_query_bars;

View File

@ -120,6 +120,7 @@
#define custom_set_current_input_sig() void custom_set_current_input(Application_Links* app, User_Input* input)
#define custom_leave_current_input_unhandled_sig() void custom_leave_current_input_unhandled(Application_Links* app)
#define custom_set_custom_hook_sig() void custom_set_custom_hook(Application_Links* app, Hook_ID hook_id, Void_Func* func_ptr)
#define custom_get_custom_hook_sig() Void_Func* custom_get_custom_hook(Application_Links* app, Hook_ID hook_id)
#define custom_set_custom_hook_memory_size_sig() b32 custom_set_custom_hook_memory_size(Application_Links* app, Hook_ID hook_id, u64 size)
#define custom_get_mouse_state_sig() Mouse_State custom_get_mouse_state(Application_Links* app)
#define custom_get_active_query_bars_sig() b32 custom_get_active_query_bars(Application_Links* app, View_ID view_id, i32 max_result_count, Query_Bar_Ptr_Array* array_out)
@ -296,6 +297,7 @@ typedef User_Input custom_get_current_input_type(Application_Links* app);
typedef void custom_set_current_input_type(Application_Links* app, User_Input* input);
typedef void custom_leave_current_input_unhandled_type(Application_Links* app);
typedef void custom_set_custom_hook_type(Application_Links* app, Hook_ID hook_id, Void_Func* func_ptr);
typedef Void_Func* custom_get_custom_hook_type(Application_Links* app, Hook_ID hook_id);
typedef b32 custom_set_custom_hook_memory_size_type(Application_Links* app, Hook_ID hook_id, u64 size);
typedef Mouse_State custom_get_mouse_state_type(Application_Links* app);
typedef b32 custom_get_active_query_bars_type(Application_Links* app, View_ID view_id, i32 max_result_count, Query_Bar_Ptr_Array* array_out);
@ -473,6 +475,7 @@ custom_get_current_input_type *get_current_input;
custom_set_current_input_type *set_current_input;
custom_leave_current_input_unhandled_type *leave_current_input_unhandled;
custom_set_custom_hook_type *set_custom_hook;
custom_get_custom_hook_type *get_custom_hook;
custom_set_custom_hook_memory_size_type *set_custom_hook_memory_size;
custom_get_mouse_state_type *get_mouse_state;
custom_get_active_query_bars_type *get_active_query_bars;
@ -651,6 +654,7 @@ internal User_Input get_current_input(Application_Links* app);
internal void set_current_input(Application_Links* app, User_Input* input);
internal void leave_current_input_unhandled(Application_Links* app);
internal void set_custom_hook(Application_Links* app, Hook_ID hook_id, Void_Func* func_ptr);
internal Void_Func* get_custom_hook(Application_Links* app, Hook_ID hook_id);
internal b32 set_custom_hook_memory_size(Application_Links* app, Hook_ID hook_id, u64 size);
internal Mouse_State get_mouse_state(Application_Links* app);
internal b32 get_active_query_bars(Application_Links* app, View_ID view_id, i32 max_result_count, Query_Bar_Ptr_Array* array_out);
@ -829,6 +833,7 @@ global custom_get_current_input_type *get_current_input = 0;
global custom_set_current_input_type *set_current_input = 0;
global custom_leave_current_input_unhandled_type *leave_current_input_unhandled = 0;
global custom_set_custom_hook_type *set_custom_hook = 0;
global custom_get_custom_hook_type *get_custom_hook = 0;
global custom_set_custom_hook_memory_size_type *set_custom_hook_memory_size = 0;
global custom_get_mouse_state_type *get_mouse_state = 0;
global custom_get_active_query_bars_type *get_active_query_bars = 0;

View File

@ -120,6 +120,7 @@ api(custom) function User_Input get_current_input(Application_Links* app);
api(custom) function void set_current_input(Application_Links* app, User_Input* input);
api(custom) function void leave_current_input_unhandled(Application_Links* app);
api(custom) function void set_custom_hook(Application_Links* app, Hook_ID hook_id, Void_Func* func_ptr);
api(custom) function Void_Func* get_custom_hook(Application_Links* app, Hook_ID hook_id);
api(custom) function b32 set_custom_hook_memory_size(Application_Links* app, Hook_ID hook_id, u64 size);
api(custom) function Mouse_State get_mouse_state(Application_Links* app);
api(custom) function b32 get_active_query_bars(Application_Links* app, View_ID view_id, i32 max_result_count, Query_Bar_Ptr_Array* array_out);

View File

@ -807,7 +807,7 @@ doc_custom_api__global(Arena *arena, API_Definition *api_def, Doc_Cluster *clust
////////////////////////////////
if (begin_doc_call(arena, cluster, api_def, "set_custom_hook", &func)){
doc_function_brief(arena, &func, "Modify the a global hook binding");
doc_function_brief(arena, &func, "Modify a global hook binding");
// params
Doc_Block *params = doc_function_begin_params(arena, &func);
@ -826,6 +826,28 @@ doc_custom_api__global(Arena *arena, API_Definition *api_def, Doc_Cluster *clust
////////////////////////////////
if (begin_doc_call(arena, cluster, api_def, "get_custom_hook", &func)){
doc_function_brief(arena, &func, "Get back a global hook binding");
// params
Doc_Block *params = doc_function_begin_params(arena, &func);
doc_custom_app_ptr(arena, &func);
doc_function_param(arena, &func, "hook_id");
doc_text(arena, params, "the id of the hook to be modified");
// return
Doc_Block *ret = doc_function_return(arena, &func);
doc_text(arena, ret, "when the hook id is valid the function pointer to the current hook function, otherwise zero");
// related
Doc_Block *rel = doc_function_begin_related(arena, &func);
doc_function_add_related(arena, rel, "Hook_ID");
}
////////////////////////////////
if (begin_doc_call(arena, cluster, api_def, "set_custom_hook_memory_size", &func)){
doc_function_brief(arena, &func, "Set the memory size for the extra memory used to store the state of certain hooks");

View File

@ -4,6 +4,7 @@
+ New Date_Time system APIs, and Date_Time string formatting
+ clean_all_lines remves trailing whitespace and removes blank lines
+ New command, clean_trailing_whitespace leaves blank lines
+ In config.4coder "enable_output_wrapping" determine whether to wrap buffers like *compilation*, *search*, etc.
+ Fix: when generated/metadata* files are missing buildsuper still succeeds
+ Fix: mac does not hang opening multiple files
+ Fix: line number margin performance

View File

@ -20,6 +20,7 @@ use_paren_helper = true;
use_comment_keywords = true;
lister_whole_word_backspace_when_modified = false;
show_line_number_margins = false;
enable_output_wrapping = false;
// Code Wrapping
treat_as_code = ".cpp.c.hpp.h.cc.cs.java.rs.glsl.m.mm";