From 2a255b8ad9dfae4ad73a091d8809e64a9e1effbc Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sun, 9 Feb 2020 02:22:35 -0800 Subject: [PATCH] Fix intricate async token reading; clean all lines overworking --- 4ed_api_implementation.cpp | 34 + 4ed_view.cpp | 16 +- 4ed_view.h | 2 + custom/4coder_async_tasks.cpp | 42 +- custom/4coder_async_tasks.h | 1 - custom/4coder_auto_indent.cpp | 22 +- custom/4coder_base_commands.cpp | 18 +- custom/4coder_code_index.cpp | 4 +- custom/4coder_default_hooks.cpp | 177 +- custom/4coder_default_include.cpp | 6 +- custom/4coder_helper.cpp | 2971 +++++++++++---------- custom/generated/command_metadata.h | 120 +- custom/generated/custom_api.cpp | 4 + custom/generated/custom_api.h | 10 + custom/generated/custom_api_master_list.h | 2 + platform_mac/mac_4ed_functions.mm | 248 +- platform_win32/win32_4ed.cpp | 22 +- 17 files changed, 1837 insertions(+), 1862 deletions(-) diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index c082dd47..10539c10 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -2738,6 +2738,40 @@ set_window_title(Application_Links *app, String_Const_u8 title) models->title_space[copy_size] = 0; } +api(custom) function void +acquire_global_frame_mutex(Application_Links *app){ + Thread_Context *tctx = app->tctx; + Thread_Context_Extra_Info *tctx_info = (Thread_Context_Extra_Info*)tctx->user_data; + if (tctx_info != 0 && tctx_info->coroutine != 0){ + Coroutine *coroutine = (Coroutine*)tctx_info->coroutine; + Assert(coroutine != 0); + Co_Out *out = (Co_Out*)coroutine->out; + out->request = CoRequest_AcquireGlobalFrameMutex; + coroutine_yield(coroutine); + } + else{ + system_acquire_global_frame_mutex(tctx); + } +} + +api(custom) function void +release_global_frame_mutex(Application_Links *app){ + Thread_Context *tctx = app->tctx; + Thread_Context_Extra_Info *tctx_info = (Thread_Context_Extra_Info*)tctx->user_data; + if (tctx_info != 0 && tctx_info->coroutine != 0){ + Coroutine *coroutine = (Coroutine*)tctx_info->coroutine; + Assert(coroutine != 0); + Co_Out *out = (Co_Out*)coroutine->out; + out->request = CoRequest_ReleaseGlobalFrameMutex; + coroutine_yield(coroutine); + } + else{ + system_release_global_frame_mutex(tctx); + } +} + +//////////////////////////////// + api(custom) function Vec2_f32 draw_string_oriented(Application_Links *app, Face_ID font_id, ARGB_Color color, String_Const_u8 str, Vec2_f32 point, u32 flags, Vec2_f32 delta) diff --git a/4ed_view.cpp b/4ed_view.cpp index 3a25ea21..8daeb537 100644 --- a/4ed_view.cpp +++ b/4ed_view.cpp @@ -511,7 +511,7 @@ view_current_context(View *view){ //////////////////////////////// internal Coroutine* -co_handle_request(Models *models, Coroutine *co, Co_Out *out){ +co_handle_request(Thread_Context *tctx, Models *models, Coroutine *co, Co_Out *out){ Coroutine *result = 0; switch (out->request){ case CoRequest_NewFontFace: @@ -531,6 +531,18 @@ co_handle_request(Models *models, Coroutine *co, Co_Out *out){ in.success = font_set_modify_face(&models->font_set, face_id, description); result = coroutine_run(&models->coroutines, co, &in, out); }break; + + case CoRequest_AcquireGlobalFrameMutex: + { + system_acquire_global_frame_mutex(tctx); + result = coroutine_run(&models->coroutines, co, 0, out); + }break; + + case CoRequest_ReleaseGlobalFrameMutex: + { + system_release_global_frame_mutex(tctx); + result = coroutine_run(&models->coroutines, co, 0, out); + }break; } return(result); } @@ -539,7 +551,7 @@ internal Coroutine* co_run(Thread_Context *tctx, Models *models, Coroutine *co, Co_In *in, Co_Out *out){ Coroutine *result = coroutine_run(&models->coroutines, co, in, out); for (;result != 0 && out->request != CoRequest_None;){ - result = co_handle_request(models, result, out); + result = co_handle_request(tctx, models, result, out); } return(result); } diff --git a/4ed_view.h b/4ed_view.h index 3d2c1947..2842a524 100644 --- a/4ed_view.h +++ b/4ed_view.h @@ -29,6 +29,8 @@ enum{ CoRequest_None = 0, CoRequest_NewFontFace = 1, CoRequest_ModifyFace = 2, + CoRequest_AcquireGlobalFrameMutex = 3, + CoRequest_ReleaseGlobalFrameMutex = 4, }; struct Co_Out{ diff --git a/custom/4coder_async_tasks.cpp b/custom/4coder_async_tasks.cpp index 4706bd88..328dbf6e 100644 --- a/custom/4coder_async_tasks.cpp +++ b/custom/4coder_async_tasks.cpp @@ -92,21 +92,17 @@ async_task_thread(void *thread_ptr){ thread->node = node; thread->task = node->task; thread->cancel_signal = false; - thread->join_signal = false; system_mutex_release(async_system->mutex); node->func(&ctx, node->data); system_mutex_acquire(async_system->mutex); - if (thread->join_signal){ - system_condition_variable_signal(async_system->join_cv); - } node->thread = 0; thread->node = 0; thread->task = 0; thread->cancel_signal = false; - thread->join_signal = false; async_free_node(async_system, node); + system_condition_variable_signal(async_system->join_cv); system_mutex_release(async_system->mutex); } } @@ -179,19 +175,42 @@ async_task_is_running(Async_System *async_system, Async_Task task){ } function b32 -async_task_is_running_or_pending(Async_System *async_system, Async_Task task){ - system_mutex_acquire(async_system->mutex); +async_task_is_running_or_pending__inner(Async_System *async_system, Async_Task task){ Async_Node *node = async_get_pending_node(async_system, task); - if (node != 0){ + if (node == 0){ node = async_get_running_node(async_system, task); } - system_mutex_release(async_system->mutex); return(node != 0); } -// TODO(allen): ensure that the job is canceled before this returns. +function b32 +async_task_is_running_or_pending(Async_System *async_system, Async_Task task){ + system_mutex_acquire(async_system->mutex); + b32 result = async_task_is_running_or_pending__inner(async_system, task); + system_mutex_release(async_system->mutex); + return(result); +} + function void -async_task_cancel(Async_System *async_system, Async_Task task){ +async_task_wait__inner(Application_Links *app, Async_System *async_system, Async_Task task){ + release_global_frame_mutex(app); + for (;async_task_is_running_or_pending__inner(async_system, task);){ + system_condition_variable_wait(async_system->join_cv, async_system->mutex); + } + acquire_global_frame_mutex(app); +} + +function void +async_task_wait(Application_Links *app, Async_System *async_system, Async_Task task){ + system_mutex_acquire(async_system->mutex); + if (async_task_is_running_or_pending__inner(async_system, task)){ + async_task_wait__inner(app, async_system, task); + } + system_mutex_release(async_system->mutex); +} + +function void +async_task_cancel(Application_Links *app, Async_System *async_system, Async_Task task){ system_mutex_acquire(async_system->mutex); Async_Node *node = async_get_pending_node(async_system, task); if (node != 0){ @@ -204,6 +223,7 @@ async_task_cancel(Async_System *async_system, Async_Task task){ if (node != 0){ b32 *cancel_signal = &node->thread->cancel_signal; atomic_write_b32(cancel_signal, true); + async_task_wait__inner(app, async_system, task); } } system_mutex_release(async_system->mutex); diff --git a/custom/4coder_async_tasks.h b/custom/4coder_async_tasks.h index 2e1af6e4..282c1f44 100644 --- a/custom/4coder_async_tasks.h +++ b/custom/4coder_async_tasks.h @@ -16,7 +16,6 @@ struct Async_Thread{ struct Async_Node *node; Async_Task task; b32 cancel_signal; - b32 join_signal; }; struct Async_Node{ diff --git a/custom/4coder_auto_indent.cpp b/custom/4coder_auto_indent.cpp index a8a76ff2..7da42733 100644 --- a/custom/4coder_auto_indent.cpp +++ b/custom/4coder_auto_indent.cpp @@ -166,8 +166,14 @@ get_indentation_array(Application_Links *app, Arena *arena, Buffer_ID buffer, Ra i64 *shifted_indentations = indentations - lines.first; block_fill_u64(indentations, sizeof(*indentations)*count, (u64)(-1)); +#if 0 Managed_Scope scope = buffer_get_managed_scope(app, buffer); Token_Array *tokens = scope_attachment(app, scope, attachment_tokens, Token_Array); +#endif + + Token_Array token_array = get_token_array_from_buffer(app, buffer); + Token_Array *tokens = &token_array; + i64 anchor_line = clamp_bot(1, lines.first - 1); Token *anchor_token = find_anchor_token(app, buffer, tokens, anchor_line); if (anchor_token != 0 && @@ -275,11 +281,11 @@ get_indentation_array(Application_Links *app, Arena *arena, Buffer_ID buffer, Ra } #define EMIT(N) \ - Stmnt(if (lines.first <= line_it){shifted_indentations[line_it]=N;} \ - if (line_it == lines.end){goto finished;} \ - actual_indent = N; ) - - i64 line_it = line_last_indented; +Stmnt(if (lines.first <= line_it){shifted_indentations[line_it]=N;} \ +if (line_it == lines.end){goto finished;} \ +actual_indent = N; ) + + i64 line_it = line_last_indented; if (lines.first <= line_cache.where_token_starts){ for (;line_it < line_cache.where_token_starts;){ line_it += 1; @@ -342,11 +348,11 @@ get_indentation_array(Application_Links *app, Arena *arena, Buffer_ID buffer, Ra internal b32 auto_indent_buffer(Application_Links *app, Buffer_ID buffer, Range_i64 pos, Indent_Flag flags, i32 tab_width, i32 indent_width){ ProfileScope(app, "auto indent buffer"); - Managed_Scope scope = buffer_get_managed_scope(app, buffer); - Token_Array *tokens = scope_attachment(app, scope, attachment_tokens, Token_Array); + Token_Array token_array = get_token_array_from_buffer(app, buffer); + Token_Array *tokens = &token_array; b32 result = false; - if (tokens != 0 && tokens->tokens != 0){ + if (tokens->tokens != 0){ result = true; Scratch_Block scratch(app); diff --git a/custom/4coder_base_commands.cpp b/custom/4coder_base_commands.cpp index d76b22cc..2ac0deb8 100644 --- a/custom/4coder_base_commands.cpp +++ b/custom/4coder_base_commands.cpp @@ -1,5 +1,5 @@ /* -4coder_base_commands.cpp - Base commands such as inserting characters, and +4coder_base_commands.cpp - Base commands such as inserting characters, and moving the cursor, which work even without the default 4coder framework. */ @@ -626,13 +626,15 @@ clean_all_lines_buffer(Application_Links *app, Buffer_ID buffer){ } } - i64 start = start_offset + line_start; - i64 end = end_offset + line_start; - - Batch_Edit *batch = push_array(scratch, Batch_Edit, 1); - sll_queue_push(batch_first, batch_last, batch); - batch->edit.text = SCu8(); - batch->edit.range = Ii64(start, end); + if (start_offset > 0){ + i64 start = start_offset + line_start; + i64 end = end_offset + line_start; + + Batch_Edit *batch = push_array(scratch, Batch_Edit, 1); + sll_queue_push(batch_first, batch_last, batch); + batch->edit.text = SCu8(); + batch->edit.range = Ii64(start, end); + } } } } diff --git a/custom/4coder_code_index.cpp b/custom/4coder_code_index.cpp index 560c1167..4319ee1c 100644 --- a/custom/4coder_code_index.cpp +++ b/custom/4coder_code_index.cpp @@ -881,8 +881,8 @@ function Layout_Item_List layout_index__inner(Application_Links *app, Arena *arena, Buffer_ID buffer, Range_i64 range, Face_ID face, f32 width, Code_Index_File *file, Layout_Wrap_Kind kind){ Scratch_Block scratch(app); - Managed_Scope scope = buffer_get_managed_scope(app, buffer); - Token_Array *tokens_ptr = scope_attachment(app, scope, attachment_tokens, Token_Array); + Token_Array tokens = get_token_array_from_buffer(app, buffer); + Token_Array *tokens_ptr = &tokens; Layout_Item_List list = get_empty_item_list(range); String_Const_u8 text = push_buffer_range(app, scratch, buffer, range); diff --git a/custom/4coder_default_hooks.cpp b/custom/4coder_default_hooks.cpp index 2becdc79..4f4c25c8 100644 --- a/custom/4coder_default_hooks.cpp +++ b/custom/4coder_default_hooks.cpp @@ -150,26 +150,19 @@ CUSTOM_DOC("Input consumption loop for default view behavior") } function void -default_tick(Application_Links *app, Frame_Info frame_info){ +code_index_update_tick(Application_Links *app){ Scratch_Block scratch(app); - for (Buffer_Modified_Node *node = global_buffer_modified_set.first; node != 0; node = node->next){ Temp_Memory_Block temp(scratch); Buffer_ID buffer_id = node->buffer; - Managed_Scope scope = buffer_get_managed_scope(app, buffer_id); - String_Const_u8 contents = push_whole_buffer(app, scratch, buffer_id); - Token_Array *tokens_ptr = scope_attachment(app, scope, attachment_tokens, Token_Array); - if (tokens_ptr == 0){ + Token_Array tokens = get_token_array_from_buffer(app, buffer_id); + if (tokens.count == 0){ continue; } - if (tokens_ptr->count == 0){ - continue; - } - Token_Array tokens = *tokens_ptr; Arena arena = make_arena_system(KB(16)); Code_Index_File *index = push_array_zero(&arena, Code_Index_File, 1); @@ -178,7 +171,8 @@ default_tick(Application_Links *app, Frame_Info frame_info){ Generic_Parse_State state = {}; generic_parse_init(app, &arena, contents, &tokens, &state); // TODO(allen): Actually determine this in a fair way. - // Maybe switch to an enum. + // Maybe switch to an enum? + // Actually probably a pointer to a struct that defines the language. state.do_cpp_parse = true; generic_parse_full_input_breaks(index, &state, max_i32); @@ -189,7 +183,11 @@ default_tick(Application_Links *app, Frame_Info frame_info){ } buffer_modified_set_clear(); - +} + +function void +default_tick(Application_Links *app, Frame_Info frame_info){ + code_index_update_tick(app); if (tick_all_fade_ranges(frame_info.animation_dt)){ animate_in_n_milliseconds(app, 0); } @@ -613,13 +611,12 @@ parse_async__inner(Async_Context *actx, Buffer_ID buffer_id, } if (!canceled){ - Thread_Context *tctx = get_thread_context(app); - system_acquire_global_frame_mutex(tctx); + acquire_global_frame_mutex(app); code_index_lock(); code_index_set_file(buffer_id, arena, index); code_index_unlock(); buffer_clear_layout_cache(app, buffer_id); - system_release_global_frame_mutex(tctx); + release_global_frame_mutex(app); } else{ linalloc_clear(&arena); @@ -630,16 +627,15 @@ function void do_full_lex_async__inner(Async_Context *actx, Buffer_ID buffer_id){ Application_Links *app = actx->app; ProfileScope(app, "async lex"); - Thread_Context *tctx = get_thread_context(app); - Scratch_Block scratch(tctx); + Scratch_Block scratch(app); String_Const_u8 contents = {}; { ProfileBlock(app, "async lex contents (before mutex)"); - system_acquire_global_frame_mutex(tctx); + acquire_global_frame_mutex(app); ProfileBlock(app, "async lex contents (after mutex)"); contents = push_whole_buffer(app, scratch, buffer_id); - system_release_global_frame_mutex(tctx); + release_global_frame_mutex(app); } i32 limit_factor = 10000; @@ -662,13 +658,12 @@ do_full_lex_async__inner(Async_Context *actx, Buffer_ID buffer_id){ if (!canceled){ ProfileBlock(app, "async lex save results (before mutex)"); - system_acquire_global_frame_mutex(tctx); + acquire_global_frame_mutex(app); ProfileBlock(app, "async lex save results (after mutex)"); Managed_Scope scope = buffer_get_managed_scope(app, buffer_id); if (scope != 0){ Base_Allocator *allocator = managed_scope_allocator(app, scope); - Token_Array *tokens_ptr = scope_attachment(app, scope, attachment_tokens, - Token_Array); + Token_Array *tokens_ptr = scope_attachment(app, scope, attachment_tokens, Token_Array); base_free(allocator, tokens_ptr->tokens); Token_Array tokens = {}; tokens.tokens = base_array(allocator, Token, list.total_count); @@ -678,7 +673,7 @@ do_full_lex_async__inner(Async_Context *actx, Buffer_ID buffer_id){ block_copy_struct(tokens_ptr, &tokens); } buffer_mark_as_modified(buffer_id); - system_release_global_frame_mutex(tctx); + release_global_frame_mutex(app); } } @@ -690,132 +685,6 @@ do_full_lex_async(Async_Context *actx, Data data){ } } -#if 0 -function void -do_full_lex_and_parse_async__inner(Async_Context *actx, Buffer_ID buffer_id){ - Application_Links *app = actx->app; - ProfileScope(app, "async lex"); - Thread_Context *tctx = get_thread_context(app); - Scratch_Block scratch(tctx); - - String_Const_u8 contents = {}; - { - ProfileBlock(app, "async lex contents (before mutex)"); - system_acquire_global_frame_mutex(tctx); - ProfileBlock(app, "async lex contents (after mutex)"); - - Managed_Scope scope = buffer_get_managed_scope(app, buffer_id); - if (scope != 0){ - Base_Allocator *allocator = managed_scope_allocator(app, scope); - Token_Array *tokens_ptr = scope_attachment(app, scope, attachment_tokens, - Token_Array); - base_free(allocator, tokens_ptr->tokens); - block_zero_struct(tokens_ptr); - } - - contents = push_whole_buffer(app, scratch, buffer_id); - system_release_global_frame_mutex(tctx); - } - - i32 limit_factor = 10000; - - Token_List list = {}; - b32 canceled = false; - - { - Lex_State_Cpp state = {}; - lex_full_input_cpp_init(&state, contents); - for (;;){ - ProfileBlock(app, "async lex block"); - if (lex_full_input_cpp_breaks(scratch, &list, &state, limit_factor)){ - break; - } - if (async_check_canceled(actx)){ - canceled = true; - break; - } - } - } - - Token_Array tokens = {}; - if (!canceled){ - ProfileBlock(app, "async lex save results (before mutex)"); - system_acquire_global_frame_mutex(tctx); - ProfileBlock(app, "async lex save results (after mutex)"); - Managed_Scope scope = buffer_get_managed_scope(app, buffer_id); - if (scope != 0){ - Base_Allocator *allocator = managed_scope_allocator(app, scope); - Token_Array *tokens_ptr = scope_attachment(app, scope, attachment_tokens, - Token_Array); - base_free(allocator, tokens_ptr->tokens); - tokens.tokens = base_array(allocator, Token, list.total_count); - tokens.count = list.total_count; - tokens.max = list.total_count; - token_fill_memory_from_list(tokens.tokens, &list); - block_copy_struct(tokens_ptr, &tokens); - } - system_release_global_frame_mutex(tctx); - } - - if (tokens.count > 0){ - parse_async__inner(actx, buffer_id, contents, &tokens, limit_factor); - } -} - -function void -do_full_lex_and_parse_async(Async_Context *actx, Data data){ - if (data.size == sizeof(Buffer_ID)){ - Buffer_ID buffer = *(Buffer_ID*)data.data; - do_full_lex_and_parse_async__inner(actx, buffer); - } -} -#endif - -#if 0 -function void -do_parse_async__inner(Async_Context *actx, Buffer_ID buffer_id){ - Application_Links *app = actx->app; - ProfileScope(app, "async lex"); - Thread_Context *tctx = get_thread_context(app); - Scratch_Block scratch(tctx); - - String_Const_u8 contents = {}; - Token_Array tokens = {}; - { - ProfileBlock(app, "async parse contents (before mutex)"); - system_acquire_global_frame_mutex(tctx); - ProfileBlock(app, "async parse contents (after mutex)"); - - Managed_Scope scope = buffer_get_managed_scope(app, buffer_id); - if (scope != 0){ - Token_Array *tokens_ptr = scope_attachment(app, scope, attachment_tokens, - Token_Array); - tokens.count = tokens_ptr->count; - tokens.tokens = push_array_write(scratch, Token, tokens.count, tokens_ptr->tokens); - if (tokens.count > 0){ - contents = push_whole_buffer(app, scratch, buffer_id); - } - } - - system_release_global_frame_mutex(tctx); - } - - i32 limit_factor = 10000; - - if (tokens.count > 0){ - parse_async__inner(actx, buffer_id, contents, &tokens, limit_factor); - } -} - -function void -do_parse_async(Async_Context *actx, Data data){ - if (data.size == sizeof(Buffer_ID)){ - Buffer_ID buffer = *(Buffer_ID*)data.data; - do_parse_async__inner(actx, buffer); - } -} -#endif - BUFFER_HOOK_SIG(default_begin_buffer){ ProfileScope(app, "begin buffer"); @@ -829,7 +698,7 @@ BUFFER_HOOK_SIG(default_begin_buffer){ for (i32 i = 0; i < extensions.count; ++i){ if (string_match(ext, extensions.strings[i])){ - if (string_match(ext, string_u8_litexpr("cpp")) || + if (string_match(ext, string_u8_litexpr("cpp")) || string_match(ext, string_u8_litexpr("h")) || string_match(ext, string_u8_litexpr("c")) || string_match(ext, string_u8_litexpr("hpp")) || @@ -837,7 +706,7 @@ BUFFER_HOOK_SIG(default_begin_buffer){ treat_as_code = true; } -#if 0 +#if 0 treat_as_code = true; if (string_match(ext, string_u8_litexpr("cs"))){ @@ -861,7 +730,7 @@ BUFFER_HOOK_SIG(default_begin_buffer){ parse_context_id = parse_context_language_rust; } - if (string_match(ext, string_u8_litexpr("cpp")) || + if (string_match(ext, string_u8_litexpr("cpp")) || string_match(ext, string_u8_litexpr("h")) || string_match(ext, string_u8_litexpr("c")) || string_match(ext, string_u8_litexpr("hpp")) || @@ -1043,7 +912,7 @@ BUFFER_EDIT_RANGE_SIG(default_buffer_edit_range){ b32 do_full_relex = false; if (async_task_is_running_or_pending(&global_async_system, *lex_task_ptr)){ - async_task_cancel(&global_async_system, *lex_task_ptr); + async_task_cancel(app, &global_async_system, *lex_task_ptr); buffer_unmark_as_modified(buffer_id); do_full_relex = true; *lex_task_ptr = 0; @@ -1129,7 +998,7 @@ BUFFER_HOOK_SIG(default_end_buffer){ Managed_Scope scope = buffer_get_managed_scope(app, buffer_id); Async_Task *lex_task_ptr = scope_attachment(app, scope, buffer_lex_task, Async_Task); if (lex_task_ptr != 0){ - async_task_cancel(&global_async_system, *lex_task_ptr); + async_task_cancel(app, &global_async_system, *lex_task_ptr); } buffer_unmark_as_modified(buffer_id); code_index_lock(); diff --git a/custom/4coder_default_include.cpp b/custom/4coder_default_include.cpp index 9d6f1435..0e13797d 100644 --- a/custom/4coder_default_include.cpp +++ b/custom/4coder_default_include.cpp @@ -79,12 +79,14 @@ #include "4coder_async_tasks.cpp" #include "4coder_string_match.cpp" #include "4coder_buffer_seek_constructors.cpp" - #include "4coder_token.cpp" -#include "generated/lexer_cpp.cpp" #include "4coder_command_map.cpp" + +#include "generated/lexer_cpp.cpp" + #include "4coder_default_map.cpp" #include "4coder_mac_map.cpp" + #include "4coder_default_framework_variables.cpp" #include "4coder_default_colors.cpp" #include "4coder_helper.cpp" diff --git a/custom/4coder_helper.cpp b/custom/4coder_helper.cpp index 38edd9f6..986397e2 100644 --- a/custom/4coder_helper.cpp +++ b/custom/4coder_helper.cpp @@ -5,7 +5,6 @@ // TOP #define scope_attachment(app,S,I,T) ((T*)managed_scope_get_attachment((app), (S), (I), sizeof(T))) - #define set_custom_hook(app,ID,F) set_custom_hook((app),(ID),(Void_Func*)(F)) //////////////////////////////// @@ -14,6 +13,10 @@ internal Token_Array get_token_array_from_buffer(Application_Links *app, Buffer_ID buffer){ Token_Array result = {}; Managed_Scope scope = buffer_get_managed_scope(app, buffer); + Async_Task *lex_task_ptr = scope_attachment(app, scope, buffer_lex_task, Async_Task); + if (lex_task_ptr != 0){ + async_task_wait(app, &global_async_system, *lex_task_ptr); + } Token_Array *ptr = scope_attachment(app, scope, attachment_tokens, Token_Array); if (ptr != 0){ result = *ptr; @@ -609,318 +612,318 @@ boundary_token(Application_Links *app, Buffer_ID buffer, Side side, Scan_Directi }break; case Scan_Backward: - { - result = 0; + { + result = 0; if (tokens.count > 0){ - Token_Iterator_Array it = token_iterator_pos(0, &tokens, pos); - Token *token = token_it_read(&it); - if (token->kind == TokenBaseKind_Whitespace){ - token_it_dec_non_whitespace(&it); - token = token_it_read(&it); - } + Token_Iterator_Array it = token_iterator_pos(0, &tokens, pos); + Token *token = token_it_read(&it); +if (token->kind == TokenBaseKind_Whitespace){ + token_it_dec_non_whitespace(&it); +token = token_it_read(&it); + } if (token != 0){ - if (side == Side_Min){ - if (token->pos >= pos){ - token_it_dec_non_whitespace(&it); - token = token_it_read(&it); - } + if (side == Side_Min){ + if (token->pos >= pos){ + token_it_dec_non_whitespace(&it); +token = token_it_read(&it); + } result = token->pos; - } + } else{ - if (token->pos + token->size >= pos){ - token_it_dec_non_whitespace(&it); - token = token_it_read(&it); - } + if (token->pos + token->size >= pos){ + token_it_dec_non_whitespace(&it); +token = token_it_read(&it); + } result = token->pos + token->size; + } } } - } - }break; - } - } - return(result); + }break; + } + } + return(result); } -internal i64 + internal i64 boundary_line(Application_Links *app, Buffer_ID buffer, Side side, Scan_Direction direction, i64 pos){ - i64 line_number = get_line_number_from_pos(app, buffer, pos); - i64 new_pos = get_line_side_pos(app, buffer, line_number, side); - if (direction == Scan_Backward && new_pos >= pos){ - if (line_number > 1){ - new_pos = get_line_side_pos(app, buffer, line_number - 1, side); - } + i64 line_number = get_line_number_from_pos(app, buffer, pos); + i64 new_pos = get_line_side_pos(app, buffer, line_number, side); + if (direction == Scan_Backward && new_pos >= pos){ + if (line_number > 1){ + new_pos = get_line_side_pos(app, buffer, line_number - 1, side); + } else{ - new_pos = 0; + new_pos = 0; + } + } + else if (direction == Scan_Forward && new_pos <= pos){ + new_pos = get_line_side_pos(app, buffer, line_number + 1, side); + if (new_pos <= pos){ + new_pos = (i32)buffer_get_size(app, buffer); + } } - } - else if (direction == Scan_Forward && new_pos <= pos){ - new_pos = get_line_side_pos(app, buffer, line_number + 1, side); - if (new_pos <= pos){ - new_pos = (i32)buffer_get_size(app, buffer); - } - } return(new_pos); } - -//////////////////////////////// + + //////////////////////////////// // TODO(allen): these need a little more rewrite internal void seek_string_forward(Application_Links *app, Buffer_ID buffer, i64 pos, i64 end, String_Const_u8 needle, i64 *result){ - if (end == 0){ - end = (i32)buffer_get_size(app, buffer); - } + if (end == 0){ + end = (i32)buffer_get_size(app, buffer); + } String_Match match = {}; - match.range.first = pos; - for (;;){ +match.range.first = pos; + for (;;){ match = buffer_seek_string(app, buffer, needle, Scan_Forward, (i32)match.range.first); - if (HasFlag(match.flags, StringMatch_CaseSensitive) || - match.buffer != buffer || match.range.first >= end) break; - } + if (HasFlag(match.flags, StringMatch_CaseSensitive) || + match.buffer != buffer || match.range.first >= end) break; + } if (match.range.first < end && match.buffer == buffer){ - *result = match.range.first; - } - else{ - *result = buffer_get_size(app, buffer); - } + *result = match.range.first; } - -internal void + else{ + *result = buffer_get_size(app, buffer); + } + } + + internal void seek_string_backward(Application_Links *app, Buffer_ID buffer, i64 pos, i64 min, String_Const_u8 needle, i64 *result){ - String_Match match = {}; + String_Match match = {}; match.range.first = pos; - for (;;){ - match = buffer_seek_string(app, buffer, needle, Scan_Backward, match.range.first); - if (HasFlag(match.flags, StringMatch_CaseSensitive) || - match.buffer != buffer || match.range.first < min) break; - } + for (;;){ + match = buffer_seek_string(app, buffer, needle, Scan_Backward, match.range.first); + if (HasFlag(match.flags, StringMatch_CaseSensitive) || + match.buffer != buffer || match.range.first < min) break; + } if (match.range.first >= min && match.buffer == buffer){ - *result = match.range.first; - } - else{ - *result = -1; - } + *result = match.range.first; } - -internal void + else{ + *result = -1; + } + } + + internal void seek_string_insensitive_forward(Application_Links *app, Buffer_ID buffer, i64 pos, i64 end, String_Const_u8 needle, i64 *result){ - if (end == 0){ - end = (i32)buffer_get_size(app, buffer); - } - String_Match match = buffer_seek_string(app, buffer, needle, Scan_Forward, pos); - if (match.range.first < end && match.buffer == buffer){ - *result = match.range.first; - } - else{ - *result = buffer_get_size(app, buffer); - } -} + if (end == 0){ + end = (i32)buffer_get_size(app, buffer); + } + String_Match match = buffer_seek_string(app, buffer, needle, Scan_Forward, pos); + if (match.range.first < end && match.buffer == buffer){ + *result = match.range.first; + } + else{ + *result = buffer_get_size(app, buffer); + } + } -internal void + internal void seek_string_insensitive_backward(Application_Links *app, Buffer_ID buffer, i64 pos, i64 min, String_Const_u8 needle, i64 *result){ - String_Match match = buffer_seek_string(app, buffer, needle, Scan_Backward, pos); - if (match.range.first >= min && match.buffer == buffer){ - *result = match.range.first; + String_Match match = buffer_seek_string(app, buffer, needle, Scan_Backward, pos); + if (match.range.first >= min && match.buffer == buffer){ + *result = match.range.first; + } + else{ + *result = -1; } - else{ - *result = -1; } -} - -internal void -seek_string(Application_Links *app, Buffer_ID buffer_id, i64 pos, i64 end, i64 min, String_Const_u8 str, i64 *result, Buffer_Seek_String_Flags flags){ - switch (flags & 3){ - case 0: - { - seek_string_forward(app, buffer_id, pos, end, str, result); - }break; + + internal void + seek_string(Application_Links *app, Buffer_ID buffer_id, i64 pos, i64 end, i64 min, String_Const_u8 str, i64 *result, Buffer_Seek_String_Flags flags){ + switch (flags & 3){ + case 0: + { + seek_string_forward(app, buffer_id, pos, end, str, result); + }break; case BufferSeekString_Backward: + { + seek_string_backward(app, buffer_id, pos, min, str, result); +}break; + + case BufferSeekString_CaseInsensitive: { - seek_string_backward(app, buffer_id, pos, min, str, result); - }break; - - case BufferSeekString_CaseInsensitive: + seek_string_insensitive_forward(app, buffer_id, pos, end, str, result); + }break; + + case BufferSeekString_Backward|BufferSeekString_CaseInsensitive: { - seek_string_insensitive_forward(app, buffer_id, pos, end, str, result); - }break; - - case BufferSeekString_Backward|BufferSeekString_CaseInsensitive: - { - seek_string_insensitive_backward(app, buffer_id, pos, min, str, result); - }break; - } -} - -//////////////////////////////// - + seek_string_insensitive_backward(app, buffer_id, pos, min, str, result); + }break; + } + } + + //////////////////////////////// + internal Range_i64 get_line_range_from_pos_range(Application_Links *app, Buffer_ID buffer, Range_i64 pos_range){ - Range_i64 line_range = {}; - line_range.first = get_line_number_from_pos(app, buffer, pos_range.first); - if (line_range.first != 0){ - line_range.end = get_line_number_from_pos(app, buffer, pos_range.one_past_last); - if (line_range.end == 0){ - line_range.first = 0; - } - } - return(line_range); -} - -// NOTE(allen): The end of the returned range does not include the terminating newline character of + Range_i64 line_range = {}; + line_range.first = get_line_number_from_pos(app, buffer, pos_range.first); + if (line_range.first != 0){ + line_range.end = get_line_number_from_pos(app, buffer, pos_range.one_past_last); +if (line_range.end == 0){ + line_range.first = 0; + } + } + return(line_range); + } + + // NOTE(allen): The end of the returned range does not include the terminating newline character of // the last line. internal Range_i64 get_pos_range_from_line_range(Application_Links *app, Buffer_ID buffer, Range_i64 line_range){ - Range_i64 pos_range = {}; - if (is_valid_line_range(app, buffer, line_range)){ - pos_range.first = get_line_start_pos(app, buffer, line_range.first); - pos_range.one_past_last = get_line_end_pos(app, buffer, line_range.end); - } + Range_i64 pos_range = {}; + if (is_valid_line_range(app, buffer, line_range)){ + pos_range.first = get_line_start_pos(app, buffer, line_range.first); +pos_range.one_past_last = get_line_end_pos(app, buffer, line_range.end); + } return(pos_range); -} - -internal Range_i64 -enclose_boundary(Application_Links *app, Buffer_ID buffer, Range_i64 range, - Boundary_Function *func){ - i64 new_min = func(app, buffer, Side_Min, Scan_Backward, range.min + 1); - i64 new_min_check = func(app, buffer, Side_Max, Scan_Backward, range.min + 1); - if (new_min_check <= new_min && new_min < range.min){ - range.min = new_min; } - i64 new_max = func(app, buffer, Side_Max, Scan_Forward, range.max - 1); - i64 new_max_check = func(app, buffer, Side_Min, Scan_Forward, range.max); - if (new_max_check >= new_max && new_max > range.max){ - range.max = new_max; - } - return(range); -} - -internal Range_i64 -left_enclose_boundary(Application_Links *app, Buffer_ID buffer, Range_i64 range, - Boundary_Function *func){ - i64 new_min = func(app, buffer, Side_Min, Scan_Backward, range.min + 1); - i64 new_min_check = func(app, buffer, Side_Max, Scan_Backward, range.min + 1); - if (new_min_check <= new_min && new_min < range.min){ - range.min = new_min; - } - return(range); -} - -internal Range_i64 -right_enclose_boundary(Application_Links *app, Buffer_ID buffer, Range_i64 range, - Boundary_Function *func){ - i64 new_max = func(app, buffer, Side_Max, Scan_Forward, range.max - 1); - i64 new_max_check = func(app, buffer, Side_Min, Scan_Forward, range.max - 1); - if (new_max_check >= new_max && new_max > range.max){ - range.max = new_max; - } - return(range); -} - -internal Range_i64 -enclose_non_whitespace(Application_Links *app, Buffer_ID buffer, Range_i64 range){ - return(enclose_boundary(app, buffer, range, boundary_non_whitespace)); -} -internal Range_i64 + + internal Range_i64 + enclose_boundary(Application_Links *app, Buffer_ID buffer, Range_i64 range, +Boundary_Function *func){ + i64 new_min = func(app, buffer, Side_Min, Scan_Backward, range.min + 1); + i64 new_min_check = func(app, buffer, Side_Max, Scan_Backward, range.min + 1); + if (new_min_check <= new_min && new_min < range.min){ + range.min = new_min; + } + i64 new_max = func(app, buffer, Side_Max, Scan_Forward, range.max - 1); + i64 new_max_check = func(app, buffer, Side_Min, Scan_Forward, range.max); + if (new_max_check >= new_max && new_max > range.max){ + range.max = new_max; + } + return(range); + } + + internal Range_i64 + left_enclose_boundary(Application_Links *app, Buffer_ID buffer, Range_i64 range, +Boundary_Function *func){ + i64 new_min = func(app, buffer, Side_Min, Scan_Backward, range.min + 1); + i64 new_min_check = func(app, buffer, Side_Max, Scan_Backward, range.min + 1); + if (new_min_check <= new_min && new_min < range.min){ + range.min = new_min; + } + return(range); + } + + internal Range_i64 + right_enclose_boundary(Application_Links *app, Buffer_ID buffer, Range_i64 range, +Boundary_Function *func){ + i64 new_max = func(app, buffer, Side_Max, Scan_Forward, range.max - 1); + i64 new_max_check = func(app, buffer, Side_Min, Scan_Forward, range.max - 1); +if (new_max_check >= new_max && new_max > range.max){ + range.max = new_max; + } + return(range); + } + + internal Range_i64 + enclose_non_whitespace(Application_Links *app, Buffer_ID buffer, Range_i64 range){ +return(enclose_boundary(app, buffer, range, boundary_non_whitespace)); + } + internal Range_i64 enclose_pos_non_whitespace(Application_Links *app, Buffer_ID buffer, i64 pos){ - return(enclose_boundary(app, buffer, Ii64(pos), boundary_non_whitespace)); + return(enclose_boundary(app, buffer, Ii64(pos), boundary_non_whitespace)); } internal Range_i64 -enclose_tokens(Application_Links *app, Buffer_ID buffer, Range_i64 range){ - return(enclose_boundary(app, buffer, range, boundary_token)); -} -internal Range_i64 -enclose_pos_tokens(Application_Links *app, Buffer_ID buffer, i64 pos){ - return(enclose_boundary(app, buffer, Ii64(pos), boundary_token)); + enclose_tokens(Application_Links *app, Buffer_ID buffer, Range_i64 range){ + return(enclose_boundary(app, buffer, range, boundary_token)); + } + internal Range_i64 + enclose_pos_tokens(Application_Links *app, Buffer_ID buffer, i64 pos){ +return(enclose_boundary(app, buffer, Ii64(pos), boundary_token)); + } + + internal Range_i64 + enclose_base10(Application_Links *app, Buffer_ID buffer, Range_i64 range){ + return(enclose_boundary(app, buffer, range, boundary_base10)); + } + internal Range_i64 + enclose_pos_base10(Application_Links *app, Buffer_ID buffer, i64 pos){ +return(enclose_boundary(app, buffer, Ii64(pos), boundary_base10)); + } + + internal Range_i64 + enclose_base16(Application_Links *app, Buffer_ID buffer, Range_i64 range){ + return(enclose_boundary(app, buffer, range, boundary_base16)); + } + internal Range_i64 + enclose_pos_base16(Application_Links *app, Buffer_ID buffer, i64 pos){ +return(enclose_boundary(app, buffer, Ii64(pos), boundary_base16)); + } + + internal Range_i64 + enclose_base10_colon(Application_Links *app, Buffer_ID buffer, Range_i64 range){ + return(enclose_boundary(app, buffer, range, boundary_base10_colon)); + } + internal Range_i64 + enclose_pos_base10_colon(Application_Links *app, Buffer_ID buffer, i64 pos){ + return(enclose_boundary(app, buffer, Ii64(pos), boundary_base10_colon)); } internal Range_i64 -enclose_base10(Application_Links *app, Buffer_ID buffer, Range_i64 range){ - return(enclose_boundary(app, buffer, range, boundary_base10)); -} -internal Range_i64 -enclose_pos_base10(Application_Links *app, Buffer_ID buffer, i64 pos){ - return(enclose_boundary(app, buffer, Ii64(pos), boundary_base10)); + enclose_alpha_numeric(Application_Links *app, Buffer_ID buffer, Range_i64 range){ + return(enclose_boundary(app, buffer, range, boundary_alpha_numeric)); + } + internal Range_i64 + enclose_pos_alpha_numeric(Application_Links *app, Buffer_ID buffer, i64 pos){ + return(enclose_boundary(app, buffer, Ii64(pos), boundary_alpha_numeric)); } internal Range_i64 -enclose_base16(Application_Links *app, Buffer_ID buffer, Range_i64 range){ - return(enclose_boundary(app, buffer, range, boundary_base16)); + enclose_alpha_numeric_unicode(Application_Links *app, Buffer_ID buffer, Range_i64 range){ + return(enclose_boundary(app, buffer, range, boundary_alpha_numeric_unicode)); } -internal Range_i64 -enclose_pos_base16(Application_Links *app, Buffer_ID buffer, i64 pos){ - return(enclose_boundary(app, buffer, Ii64(pos), boundary_base16)); -} - -internal Range_i64 -enclose_base10_colon(Application_Links *app, Buffer_ID buffer, Range_i64 range){ - return(enclose_boundary(app, buffer, range, boundary_base10_colon)); -} -internal Range_i64 -enclose_pos_base10_colon(Application_Links *app, Buffer_ID buffer, i64 pos){ - return(enclose_boundary(app, buffer, Ii64(pos), boundary_base10_colon)); -} - -internal Range_i64 -enclose_alpha_numeric(Application_Links *app, Buffer_ID buffer, Range_i64 range){ - return(enclose_boundary(app, buffer, range, boundary_alpha_numeric)); -} -internal Range_i64 -enclose_pos_alpha_numeric(Application_Links *app, Buffer_ID buffer, i64 pos){ - return(enclose_boundary(app, buffer, Ii64(pos), boundary_alpha_numeric)); -} - -internal Range_i64 -enclose_alpha_numeric_unicode(Application_Links *app, Buffer_ID buffer, Range_i64 range){ - return(enclose_boundary(app, buffer, range, boundary_alpha_numeric_unicode)); -} -internal Range_i64 -enclose_pos_alpha_numeric_unicode(Application_Links *app, Buffer_ID buffer, i64 pos){ - return(enclose_boundary(app, buffer, Ii64(pos), boundary_alpha_numeric_unicode)); -} - -internal Range_i64 -enclose_alpha_numeric_underscore(Application_Links *app, Buffer_ID buffer, Range_i64 range){ - return(enclose_boundary(app, buffer, range, boundary_alpha_numeric_underscore)); -} -internal Range_i64 -enclose_pos_alpha_numeric_underscore(Application_Links *app, Buffer_ID buffer, i64 pos){ - return(enclose_boundary(app, buffer, Ii64(pos), boundary_alpha_numeric_underscore)); -} -internal Range_i64 -right_enclose_alpha_numeric_underscore(Application_Links *app, Buffer_ID buffer, - Range_i64 range){ - return(right_enclose_boundary(app, buffer, range, boundary_alpha_numeric_underscore)); -} - + internal Range_i64 + enclose_pos_alpha_numeric_unicode(Application_Links *app, Buffer_ID buffer, i64 pos){ + return(enclose_boundary(app, buffer, Ii64(pos), boundary_alpha_numeric_unicode)); + } + + internal Range_i64 + enclose_alpha_numeric_underscore(Application_Links *app, Buffer_ID buffer, Range_i64 range){ + return(enclose_boundary(app, buffer, range, boundary_alpha_numeric_underscore)); + } + internal Range_i64 + enclose_pos_alpha_numeric_underscore(Application_Links *app, Buffer_ID buffer, i64 pos){ + return(enclose_boundary(app, buffer, Ii64(pos), boundary_alpha_numeric_underscore)); + } + internal Range_i64 + right_enclose_alpha_numeric_underscore(Application_Links *app, Buffer_ID buffer, + Range_i64 range){ + return(right_enclose_boundary(app, buffer, range, boundary_alpha_numeric_underscore)); + } + internal Range_i64 enclose_alpha_numeric_underscore_utf8(Application_Links *app, Buffer_ID buffer, Range_i64 range){ - return(enclose_boundary(app, buffer, range, boundary_alpha_numeric_underscore_utf8)); +return(enclose_boundary(app, buffer, range, boundary_alpha_numeric_underscore_utf8)); } internal Range_i64 -enclose_pos_alpha_numeric_underscore_utf8(Application_Links *app, Buffer_ID buffer, i64 pos){ - return(enclose_boundary(app, buffer, Ii64(pos), boundary_alpha_numeric_underscore_utf8)); -} -internal Range_i64 -right_enclose_alpha_numeric_underscore_utf8(Application_Links *app, Buffer_ID buffer, - Range_i64 range){ - return(right_enclose_boundary(app, buffer, range, boundary_alpha_numeric_underscore_utf8)); -} + enclose_pos_alpha_numeric_underscore_utf8(Application_Links *app, Buffer_ID buffer, i64 pos){ +return(enclose_boundary(app, buffer, Ii64(pos), boundary_alpha_numeric_underscore_utf8)); + } + internal Range_i64 + right_enclose_alpha_numeric_underscore_utf8(Application_Links *app, Buffer_ID buffer, + Range_i64 range){ +return(right_enclose_boundary(app, buffer, range, boundary_alpha_numeric_underscore_utf8)); + } -internal Range_i64 + internal Range_i64 enclose_alpha_numeric_camel(Application_Links *app, Buffer_ID buffer, Range_i64 range){ - return(enclose_boundary(app, buffer, range, boundary_alpha_numeric_camel)); +return(enclose_boundary(app, buffer, range, boundary_alpha_numeric_camel)); } internal Range_i64 enclose_pos_alpha_numeric_camel(Application_Links *app, Buffer_ID buffer, i64 pos){ - return(enclose_boundary(app, buffer, Ii64(pos), boundary_alpha_numeric_camel)); +return(enclose_boundary(app, buffer, Ii64(pos), boundary_alpha_numeric_camel)); } internal Range_i64 enclose_pos_inside_quotes(Application_Links *app, Buffer_ID buffer, i64 pos){ - return(enclose_boundary(app, buffer, Ii64(pos), boundary_inside_quotes)); + return(enclose_boundary(app, buffer, Ii64(pos), boundary_inside_quotes)); } internal Range_i64 @@ -929,1544 +932,1544 @@ enclose_whole_lines(Application_Links *app, Buffer_ID buffer, Range_i64 range){ } internal Range_i64 enclose_pos_whole_lines(Application_Links *app, Buffer_ID buffer, i64 pos){ - return(enclose_boundary(app, buffer, Ii64(pos), boundary_line)); -} - -//////////////////////////////// - -internal Range_i64 -get_snipe_range(Application_Links *app, Boundary_Function_List funcs, Buffer_ID buffer, i64 pos, Scan_Direction direction){ - Range_i64 result = {}; - i64 buffer_size = buffer_get_size(app, buffer); + return(enclose_boundary(app, buffer, Ii64(pos), boundary_line)); + } + + //////////////////////////////// + + internal Range_i64 + get_snipe_range(Application_Links *app, Boundary_Function_List funcs, Buffer_ID buffer, i64 pos, Scan_Direction direction){ + Range_i64 result = {}; + i64 buffer_size = buffer_get_size(app, buffer); i64 pos0 = pos; i64 pos1 = scan(app, funcs, buffer, direction, pos0); - if (0 <= pos1 && pos1 <= buffer_size){ - i64 pos2 = scan(app, funcs, buffer, flip_direction(direction), pos1); - if (0 <= pos2 && pos2 <= buffer_size){ - if (direction == Scan_Backward){ - pos2 = clamp_bot(pos2, pos0); - } - else{ - pos2 = clamp_top(pos2, pos0); - } - result = Ii64(pos1, pos2); - } +if (0 <= pos1 && pos1 <= buffer_size){ +i64 pos2 = scan(app, funcs, buffer, flip_direction(direction), pos1); + if (0 <= pos2 && pos2 <= buffer_size){ +if (direction == Scan_Backward){ + pos2 = clamp_bot(pos2, pos0); + } +else{ + pos2 = clamp_top(pos2, pos0); } - return(result); -} - -internal Range_i64 -get_snipe_range(Application_Links *app, Boundary_Function *func, Buffer_ID buffer, i64 pos, Scan_Direction direction){ - Scratch_Block scratch(app); - return(get_snipe_range(app, push_boundary_list(scratch, func), buffer, pos, direction)); -} - -//////////////////////////////// + result = Ii64(pos1, pos2); + } + } + return(result); + } + + internal Range_i64 + get_snipe_range(Application_Links *app, Boundary_Function *func, Buffer_ID buffer, i64 pos, Scan_Direction direction){ + Scratch_Block scratch(app); + return(get_snipe_range(app, push_boundary_list(scratch, func), buffer, pos, direction)); + } + + //////////////////////////////// internal String_Const_u8 push_buffer_range(Application_Links *app, Arena *arena, Buffer_ID buffer, Range_i64 range){ - String_Const_u8 result = {}; - i64 length = range_size(range); + String_Const_u8 result = {}; + i64 length = range_size(range); if (length > 0){ - Temp_Memory restore_point = begin_temp(arena); - u8 *memory = push_array(arena, u8, length); - if (buffer_read_range(app, buffer, range, memory)){ - result = SCu8(memory, length); - } - else{ - end_temp(restore_point); - } - } - return(result); + Temp_Memory restore_point = begin_temp(arena); + u8 *memory = push_array(arena, u8, length); + if (buffer_read_range(app, buffer, range, memory)){ + result = SCu8(memory, length); + } + else{ + end_temp(restore_point); +} +} +return(result); } internal String_Const_u8 -push_token_lexeme(Application_Links *app, Arena *arena, Buffer_ID buffer, Token *token){ - return(push_buffer_range(app, arena, buffer, Ii64(token))); + push_token_lexeme(Application_Links *app, Arena *arena, Buffer_ID buffer, Token *token){ + return(push_buffer_range(app, arena, buffer, Ii64(token))); + } + + internal String_Const_u8 + push_buffer_line(Application_Links *app, Arena *arena, Buffer_ID buffer, i64 line_number){ + return(push_buffer_range(app, arena, buffer, get_line_pos_range(app, buffer, line_number))); } internal String_Const_u8 -push_buffer_line(Application_Links *app, Arena *arena, Buffer_ID buffer, i64 line_number){ - return(push_buffer_range(app, arena, buffer, get_line_pos_range(app, buffer, line_number))); -} - -internal String_Const_u8 -push_whole_buffer(Application_Links *app, Arena *arena, Buffer_ID buffer){ + push_whole_buffer(Application_Links *app, Arena *arena, Buffer_ID buffer){ return(push_buffer_range(app, arena, buffer, buffer_range(app, buffer))); -} - -internal String_Const_u8 -push_view_range_string(Application_Links *app, Arena *arena, View_ID view){ - Buffer_ID buffer = view_get_buffer(app, view, Access_ReadVisible); + } + + internal String_Const_u8 + push_view_range_string(Application_Links *app, Arena *arena, View_ID view){ + Buffer_ID buffer = view_get_buffer(app, view, Access_ReadVisible); return(push_buffer_range(app, arena, buffer, get_view_range(app, view))); -} + } -internal String_Const_u8 -push_view_range_string(Application_Links *app, Arena *arena){ - View_ID view = get_active_view(app, Access_Always); - return(push_view_range_string(app, arena, view)); + internal String_Const_u8 + push_view_range_string(Application_Links *app, Arena *arena){ + View_ID view = get_active_view(app, Access_Always); +return(push_view_range_string(app, arena, view)); } internal String_Const_u8 push_enclose_range_at_pos(Application_Links *app, Arena *arena, Buffer_ID buffer, i64 pos, Enclose_Function *enclose){ - Range_i64 range = enclose(app, buffer, Ii64(pos)); + Range_i64 range = enclose(app, buffer, Ii64(pos)); return(push_buffer_range(app, arena, buffer, range)); -} + } //////////////////////////////// - -internal String_Const_u8 -token_it_lexeme(Application_Links *app, Arena *arena, Token_Iterator_Array *it){ - String_Const_u8 result = {}; - Token *token = token_it_read(it); - if (token != 0){ + + internal String_Const_u8 + token_it_lexeme(Application_Links *app, Arena *arena, Token_Iterator_Array *it){ + String_Const_u8 result = {}; + Token *token = token_it_read(it); +if (token != 0){ result = push_token_lexeme(app, arena, (Buffer_ID)it->user_id, token); - } - return(result); + } +return(result); } internal b32 token_it_check_and_get_lexeme(Application_Links *app, Arena *arena, Token_Iterator_Array *it, Token_Base_Kind kind, String_Const_u8 *lexeme_out){ - Token *token = token_it_read(it); + Token *token = token_it_read(it); b32 result = {}; if (token != 0 && token->kind == kind){ - result = true; - *lexeme_out = push_token_lexeme(app, arena, (Buffer_ID)it->user_id, token); + result = true; + *lexeme_out = push_token_lexeme(app, arena, (Buffer_ID)it->user_id, token); } - return(result); -} +return(result); + } -internal String_Const_u8 -token_it_lexeme(Application_Links *app, Arena *arena, Token_Iterator_List *it){ + internal String_Const_u8 + token_it_lexeme(Application_Links *app, Arena *arena, Token_Iterator_List *it){ String_Const_u8 result = {}; Token *token = token_it_read(it); - if (token != 0){ - result = push_token_lexeme(app, arena, (Buffer_ID)it->user_id, token); - } - return(result); +if (token != 0){ +result = push_token_lexeme(app, arena, (Buffer_ID)it->user_id, token); } - -internal b32 -token_it_check_and_get_lexeme(Application_Links *app, Arena *arena, Token_Iterator_List *it, Token_Base_Kind kind, String_Const_u8 *lexeme_out){ +return(result); + } + + internal b32 + token_it_check_and_get_lexeme(Application_Links *app, Arena *arena, Token_Iterator_List *it, Token_Base_Kind kind, String_Const_u8 *lexeme_out){ Token *token = token_it_read(it); b32 result = {}; if (token != 0 && token->kind == kind){ - result = true; - *lexeme_out = push_token_lexeme(app, arena, (Buffer_ID)it->user_id, token); - } - return(result); -} - -//////////////////////////////// - -internal b32 + result = true; + *lexeme_out = push_token_lexeme(app, arena, (Buffer_ID)it->user_id, token); + } + return(result); + } + + //////////////////////////////// + + internal b32 buffer_has_name_with_star(Application_Links *app, Buffer_ID buffer){ - Scratch_Block scratch(app); - String_Const_u8 str = push_buffer_unique_name(app, scratch, buffer); - return(str.size > 0 && str.str[0] == '*'); -} - -internal u8 -buffer_get_char(Application_Links *app, Buffer_ID buffer_id, i64 pos){ - i64 buffer_size = buffer_get_size(app, buffer_id); - u8 result = ' '; - if (0 <= pos && pos < buffer_size){ - buffer_read_range(app, buffer_id, Ii64(pos, pos + 1), &result); + Scratch_Block scratch(app); +String_Const_u8 str = push_buffer_unique_name(app, scratch, buffer); + return(str.size > 0 && str.str[0] == '*'); } - return(result); + + internal u8 + buffer_get_char(Application_Links *app, Buffer_ID buffer_id, i64 pos){ + i64 buffer_size = buffer_get_size(app, buffer_id); + u8 result = ' '; + if (0 <= pos && pos < buffer_size){ + buffer_read_range(app, buffer_id, Ii64(pos, pos + 1), &result); + } + return(result); } internal b32 -line_is_valid_and_blank(Application_Links *app, Buffer_ID buffer, i64 line_number){ - b32 result = false; - if (is_valid_line(app, buffer, line_number)){ - Scratch_Block scratch(app); - String_Const_u8 line = push_buffer_line(app, scratch, buffer, line_number); - result = true; - for (u64 i = 0; i < line.size; i += 1){ - if (!character_is_whitespace(line.str[i])){ - result = false; - break; - } - } - } - return(result); + line_is_valid_and_blank(Application_Links *app, Buffer_ID buffer, i64 line_number){ +b32 result = false; +if (is_valid_line(app, buffer, line_number)){ +Scratch_Block scratch(app); + String_Const_u8 line = push_buffer_line(app, scratch, buffer, line_number); + result = true; + for (u64 i = 0; i < line.size; i += 1){ + if (!character_is_whitespace(line.str[i])){ + result = false; + break; } + } + } + return(result); + } -//////////////////////////////// - -internal i64 -get_pos_past_lead_whitespace_from_line_number(Application_Links *app, Buffer_ID buffer, i64 line_number){ + //////////////////////////////// + + internal i64 + get_pos_past_lead_whitespace_from_line_number(Application_Links *app, Buffer_ID buffer, i64 line_number){ Scratch_Block scratch(app); Range_i64 line_range = get_line_pos_range(app, buffer, line_number); - String_Const_u8 line = push_buffer_range(app, scratch, buffer, line_range); - i64 result = line_range.end; - for (u64 i = 0; i < line.size; i += 1){ - if (!character_is_whitespace(line.str[i])){ - result = line_range.start + i; - break; +String_Const_u8 line = push_buffer_range(app, scratch, buffer, line_range); + i64 result = line_range.end; + for (u64 i = 0; i < line.size; i += 1){ + if (!character_is_whitespace(line.str[i])){ + result = line_range.start + i; +break; } - } - return(result); -} + } + return(result); + } + + internal i64 + get_pos_past_lead_whitespace(Application_Links *app, Buffer_ID buffer, i64 pos){ + i64 line_number = get_line_number_from_pos(app, buffer, pos); +i64 result = get_pos_past_lead_whitespace_from_line_number(app, buffer, line_number); +result = clamp_bot(pos, result); + return(result); + } -internal i64 -get_pos_past_lead_whitespace(Application_Links *app, Buffer_ID buffer, i64 pos){ - i64 line_number = get_line_number_from_pos(app, buffer, pos); - i64 result = get_pos_past_lead_whitespace_from_line_number(app, buffer, line_number); - result = clamp_bot(pos, result); - return(result); -} + internal void + move_past_lead_whitespace(Application_Links *app, View_ID view, Buffer_ID buffer){ + i64 pos = view_get_cursor_pos(app, view); + i64 new_pos = get_pos_past_lead_whitespace(app, buffer, pos); +view_set_cursor_and_preferred_x(app, view, seek_pos(new_pos)); + } -internal void -move_past_lead_whitespace(Application_Links *app, View_ID view, Buffer_ID buffer){ - i64 pos = view_get_cursor_pos(app, view); - i64 new_pos = get_pos_past_lead_whitespace(app, buffer, pos); - view_set_cursor_and_preferred_x(app, view, seek_pos(new_pos)); -} - -internal void -move_past_lead_whitespace(Application_Links *app, View_ID view){ - Buffer_ID buffer = view_get_buffer(app, view, Access_ReadVisible); + internal void + move_past_lead_whitespace(Application_Links *app, View_ID view){ +Buffer_ID buffer = view_get_buffer(app, view, Access_ReadVisible); move_past_lead_whitespace(app, view, buffer); -} + } internal b32 line_is_blank(Application_Links *app, Buffer_ID buffer, i64 line_number){ - Scratch_Block scratch(app); - String_Const_u8 line = push_buffer_line(app, scratch, buffer, line_number); - b32 is_blank = true; - for (u64 i = 0; i < line.size; i += 1){ - if (!character_is_whitespace(line.str[i])){ - is_blank = false; - break; - } + Scratch_Block scratch(app); + String_Const_u8 line = push_buffer_line(app, scratch, buffer, line_number); + b32 is_blank = true; +for (u64 i = 0; i < line.size; i += 1){ + if (!character_is_whitespace(line.str[i])){ + is_blank = false; + break; + } + } + return(is_blank); } - return(is_blank); -} - -internal i64 + + internal i64 get_line_number_of__whitespace_status_line(Application_Links *app, Buffer_ID buffer, Scan_Direction direction, i64 line_number_start, b32 get_blank_line){ - i64 line_count = buffer_get_line_count(app, buffer); - i64 line_number = line_number_start + direction; - for (;1 <= line_number && line_number <= line_count; line_number += direction){ - b32 is_blank = line_is_blank(app, buffer, line_number); - if (is_blank == get_blank_line){ - break; - } +i64 line_count = buffer_get_line_count(app, buffer); + i64 line_number = line_number_start + direction; + for (;1 <= line_number && line_number <= line_count; line_number += direction){ +b32 is_blank = line_is_blank(app, buffer, line_number); +if (is_blank == get_blank_line){ + break; + } } line_number = clamp(1, line_number, line_count); - return(line_number); + return(line_number); + } + + internal i64 + get_line_number_of_non_blank_line(Application_Links *app, Buffer_ID buffer, Scan_Direction direction, i64 line_number_start){ + return(get_line_number_of__whitespace_status_line(app, buffer, direction, line_number_start, false)); } internal i64 -get_line_number_of_non_blank_line(Application_Links *app, Buffer_ID buffer, Scan_Direction direction, i64 line_number_start){ - return(get_line_number_of__whitespace_status_line(app, buffer, direction, line_number_start, false)); -} - -internal i64 -get_line_number_of_blank_line(Application_Links *app, Buffer_ID buffer, Scan_Direction direction, i64 line_number_start){ - return(get_line_number_of__whitespace_status_line(app, buffer, direction, line_number_start, true)); -} - -internal i64 -get_pos_of_blank_line(Application_Links *app, Buffer_ID buffer, Scan_Direction direction, i64 pos_start){ - i64 line_number_start = get_line_number_from_pos(app, buffer, pos_start); - i64 blank_line = get_line_number_of_blank_line(app, buffer, direction, line_number_start); - i64 pos = get_line_start_pos(app, buffer, blank_line); + get_line_number_of_blank_line(Application_Links *app, Buffer_ID buffer, Scan_Direction direction, i64 line_number_start){ + return(get_line_number_of__whitespace_status_line(app, buffer, direction, line_number_start, true)); + } + + internal i64 + get_pos_of_blank_line(Application_Links *app, Buffer_ID buffer, Scan_Direction direction, i64 pos_start){ + i64 line_number_start = get_line_number_from_pos(app, buffer, pos_start); + i64 blank_line = get_line_number_of_blank_line(app, buffer, direction, line_number_start); + i64 pos = get_line_start_pos(app, buffer, blank_line); return(pos); } -internal i64 -get_line_number_of_blank_line_grouped(Application_Links *app, Buffer_ID buffer, Scan_Direction direction, i64 line_number_start){ - i64 line_number = line_number_start; + internal i64 + get_line_number_of_blank_line_grouped(Application_Links *app, Buffer_ID buffer, Scan_Direction direction, i64 line_number_start){ + i64 line_number = line_number_start; if (line_is_blank(app, buffer, line_number)){ - line_number = get_line_number_of_non_blank_line(app, buffer, direction, line_number); - } + line_number = get_line_number_of_non_blank_line(app, buffer, direction, line_number); + } line_number = get_line_number_of_blank_line(app, buffer, direction, line_number); return(line_number); -} - -internal i64 -get_pos_of_blank_line_grouped(Application_Links *app, Buffer_ID buffer, Scan_Direction direction, i64 pos_start){ - i64 line_number_start = get_line_number_from_pos(app, buffer, pos_start); - i64 blank_line = get_line_number_of_blank_line_grouped(app, buffer, direction, line_number_start); - i64 pos = get_line_start_pos(app, buffer, blank_line); - return(pos); -} - -internal Indent_Info -get_indent_info_range(Application_Links *app, Buffer_ID buffer, Range_i64 range, i32 tab_width){ - Scratch_Block scratch(app); - String_Const_u8 s = push_buffer_range(app, scratch, buffer, range); + } - Indent_Info info = {}; - info.first_char_pos = range.end; + internal i64 + get_pos_of_blank_line_grouped(Application_Links *app, Buffer_ID buffer, Scan_Direction direction, i64 pos_start){ +i64 line_number_start = get_line_number_from_pos(app, buffer, pos_start); + i64 blank_line = get_line_number_of_blank_line_grouped(app, buffer, direction, line_number_start); + i64 pos = get_line_start_pos(app, buffer, blank_line); + return(pos); + } + + internal Indent_Info + get_indent_info_range(Application_Links *app, Buffer_ID buffer, Range_i64 range, i32 tab_width){ + Scratch_Block scratch(app); + String_Const_u8 s = push_buffer_range(app, scratch, buffer, range); + + Indent_Info info = {}; +info.first_char_pos = range.end; info.is_blank = true; info.all_space = true; - - for (u64 i = 0; i < s.size; i += 1){ - u8 c = s.str[i]; - if (!character_is_whitespace(c)){ - info.is_blank = false; - info.all_space = false; - info.first_char_pos = range.start + (i64)i; - break; - } - if (c == ' '){ - info.indent_pos += 1; - } - else{ - info.all_space = false; - } - if (c == '\t'){ - info.indent_pos += tab_width; - } + + for (u64 i = 0; i < s.size; i += 1){ + u8 c = s.str[i]; + if (!character_is_whitespace(c)){ + info.is_blank = false; + info.all_space = false; +info.first_char_pos = range.start + (i64)i; + break; } + if (c == ' '){ + info.indent_pos += 1; + } + else{ +info.all_space = false; +} +if (c == '\t'){ + info.indent_pos += tab_width; + } + } return(info); -} - -internal Indent_Info -get_indent_info_line_number_and_start(Application_Links *app, Buffer_ID buffer, i64 line_number, i64 line_start, i32 tab_width){ + } + + internal Indent_Info + get_indent_info_line_number_and_start(Application_Links *app, Buffer_ID buffer, i64 line_number, i64 line_start, i32 tab_width){ i64 end = get_line_side_pos(app, buffer, line_number, Side_Max); - return(get_indent_info_range(app, buffer, Ii64(line_start, end), tab_width)); +return(get_indent_info_range(app, buffer, Ii64(line_start, end), tab_width)); + } + + //////////////////////////////// + + internal History_Group + history_group_begin(Application_Links *app, Buffer_ID buffer){ + History_Group group = {}; + group.app = app; + group.buffer = buffer; + group.first = buffer_history_get_current_state_index(app, buffer); + group.first += 1; + return(group); + } + + internal void + history_group_end(History_Group group){ + History_Record_Index last = buffer_history_get_current_state_index(group.app, group.buffer); + if (group.first < last){ + buffer_history_merge_record_range(group.app, group.buffer, group.first, last, RecordMergeFlag_StateInRange_MoveStateForward); } - -//////////////////////////////// - -internal History_Group -history_group_begin(Application_Links *app, Buffer_ID buffer){ - History_Group group = {}; - group.app = app; - group.buffer = buffer; - group.first = buffer_history_get_current_state_index(app, buffer); - group.first += 1; - return(group); -} - -internal void -history_group_end(History_Group group){ - History_Record_Index last = buffer_history_get_current_state_index(group.app, group.buffer); - if (group.first < last){ - buffer_history_merge_record_range(group.app, group.buffer, group.first, last, RecordMergeFlag_StateInRange_MoveStateForward); - } } //////////////////////////////// internal void -replace_in_range(Application_Links *app, Buffer_ID buffer, Range_i64 range, String_Const_u8 needle, String_Const_u8 string){ + replace_in_range(Application_Links *app, Buffer_ID buffer, Range_i64 range, String_Const_u8 needle, String_Const_u8 string){ // TODO(allen): rewrite History_Group group = history_group_begin(app, buffer); i64 pos = range.min - 1; i64 new_pos = 0; - seek_string_forward(app, buffer, pos, range.end, needle, &new_pos); - i64 shift = replace_range_shift(needle.size, string.size); - for (; new_pos + (i64)needle.size <= range.end;){ - Range_i64 needle_range = Ii64(new_pos, new_pos + (i32)needle.size); - buffer_replace_range(app, buffer, needle_range, string); - range.end += shift; - pos = new_pos + (i32)string.size - 1; - seek_string_forward(app, buffer, pos, range.end, needle, &new_pos); - } - history_group_end(group); + seek_string_forward(app, buffer, pos, range.end, needle, &new_pos); + i64 shift = replace_range_shift(needle.size, string.size); + for (; new_pos + (i64)needle.size <= range.end;){ + Range_i64 needle_range = Ii64(new_pos, new_pos + (i32)needle.size); + buffer_replace_range(app, buffer, needle_range, string); + range.end += shift; +pos = new_pos + (i32)string.size - 1; + seek_string_forward(app, buffer, pos, range.end, needle, &new_pos); + } + history_group_end(group); } - -internal Range_i64 -swap_lines(Application_Links *app, Buffer_ID buffer, i64 line_1, i64 line_2){ - Range_i64 result = {}; - i64 line_count = buffer_get_line_count(app, buffer); - if (1 <= line_1 && line_2 <= line_count){ - Range_i64 range_1 = get_line_pos_range(app, buffer, line_1); - Range_i64 range_2 = get_line_pos_range(app, buffer, line_2); - - Scratch_Block scratch(app); - - String_Const_u8 text_1 = push_buffer_range(app, scratch, buffer, range_1); + + internal Range_i64 + swap_lines(Application_Links *app, Buffer_ID buffer, i64 line_1, i64 line_2){ +Range_i64 result = {}; +i64 line_count = buffer_get_line_count(app, buffer); + if (1 <= line_1 && line_2 <= line_count){ + Range_i64 range_1 = get_line_pos_range(app, buffer, line_1); + Range_i64 range_2 = get_line_pos_range(app, buffer, line_2); + + Scratch_Block scratch(app); + + String_Const_u8 text_1 = push_buffer_range(app, scratch, buffer, range_1); String_Const_u8 text_2 = push_buffer_range(app, scratch, buffer, range_2); History_Group group = history_group_begin(app, buffer); - buffer_replace_range(app, buffer, range_2, text_1); - buffer_replace_range(app, buffer, range_1, text_2); - history_group_end(group); - - i64 shift = replace_range_shift(range_1, text_2.size); - result.min = range_1.min; - result.max = range_2.min + shift; - } - return(result); -} + buffer_replace_range(app, buffer, range_2, text_1); +buffer_replace_range(app, buffer, range_1, text_2); + history_group_end(group); -internal i64 -move_line(Application_Links *app, Buffer_ID buffer, i64 line_number, Scan_Direction direction){ - i64 line_1 = 0; - i64 line_2 = 0; - if (direction == Scan_Forward){ - line_1 = line_number; - line_2 = line_number + 1; - } - else{ - line_1 = line_number - 1; - line_2 = line_number; - } - Range_i64 line_starts = swap_lines(app, buffer, line_1, line_2); - i64 result = 0; - if (line_starts.min < line_starts.max){ - if (direction == Scan_Forward){ - result = line_starts.max; +i64 shift = replace_range_shift(range_1, text_2.size); + result.min = range_1.min; +result.max = range_2.min + shift; + } + return(result); +} + + internal i64 + move_line(Application_Links *app, Buffer_ID buffer, i64 line_number, Scan_Direction direction){ + i64 line_1 = 0; + i64 line_2 = 0; + if (direction == Scan_Forward){ + line_1 = line_number; +line_2 = line_number + 1; } else{ - result = line_starts.min; + line_1 = line_number - 1; + line_2 = line_number; + } + Range_i64 line_starts = swap_lines(app, buffer, line_1, line_2); + i64 result = 0; + if (line_starts.min < line_starts.max){ + if (direction == Scan_Forward){ + result = line_starts.max; } - } - else{ + else{ + result = line_starts.min; + } + } + else{ result = get_line_side_pos(app, buffer, line_number, Side_Min); - } - return(result); -} - -internal void -clear_buffer(Application_Links *app, Buffer_ID buffer){ - buffer_replace_range(app, buffer, buffer_range(app, buffer), string_u8_litexpr("")); -} - -//////////////////////////////// - -internal String_Match_List -find_all_matches_all_buffers(Application_Links *app, Arena *arena, String_Const_u8_Array match_patterns, String_Match_Flag must_have_flags, String_Match_Flag must_not_have_flags){ - String_Match_List all_matches = {}; - for (Buffer_ID buffer = get_buffer_next(app, 0, Access_Always); - buffer != 0; - buffer = get_buffer_next(app, buffer, Access_Always)){ - String_Match_List buffer_matches = {}; - for (i32 i = 0; i < match_patterns.count; i += 1){ - Range_i64 range = buffer_range(app, buffer); - String_Match_List pattern_matches = buffer_find_all_matches(app, arena, buffer, i, range, match_patterns.vals[i], - &character_predicate_alpha_numeric_underscore_utf8, Scan_Forward); - string_match_list_filter_flags(&pattern_matches, must_have_flags, must_not_have_flags); - if (pattern_matches.count > 0){ - if (buffer_matches.count == 0){ - buffer_matches = pattern_matches; - } - else{ - buffer_matches = string_match_list_merge_front_to_back(&buffer_matches, &pattern_matches); - } - } } - all_matches = string_match_list_join(&all_matches, &buffer_matches); - } - return(all_matches); -} + return(result); + } + + internal void + clear_buffer(Application_Links *app, Buffer_ID buffer){ + buffer_replace_range(app, buffer, buffer_range(app, buffer), string_u8_litexpr("")); + } + + //////////////////////////////// -internal String_Match_List -find_all_matches_all_buffers(Application_Links *app, Arena *arena, String_Const_u8 pattern, String_Match_Flag must_have_flags, String_Match_Flag must_not_have_flags){ - String_Const_u8_Array array = {&pattern, 1}; - return(find_all_matches_all_buffers(app, arena, array, must_have_flags, must_not_have_flags)); + internal String_Match_List + find_all_matches_all_buffers(Application_Links *app, Arena *arena, String_Const_u8_Array match_patterns, String_Match_Flag must_have_flags, String_Match_Flag must_not_have_flags){ + String_Match_List all_matches = {}; +for (Buffer_ID buffer = get_buffer_next(app, 0, Access_Always); + buffer != 0; + buffer = get_buffer_next(app, buffer, Access_Always)){ +String_Match_List buffer_matches = {}; + for (i32 i = 0; i < match_patterns.count; i += 1){ + Range_i64 range = buffer_range(app, buffer); + String_Match_List pattern_matches = buffer_find_all_matches(app, arena, buffer, i, range, match_patterns.vals[i], + &character_predicate_alpha_numeric_underscore_utf8, Scan_Forward); + string_match_list_filter_flags(&pattern_matches, must_have_flags, must_not_have_flags); +if (pattern_matches.count > 0){ +if (buffer_matches.count == 0){ + buffer_matches = pattern_matches; + } + else{ +buffer_matches = string_match_list_merge_front_to_back(&buffer_matches, &pattern_matches); } +} +} +all_matches = string_match_list_join(&all_matches, &buffer_matches); + } + return(all_matches); + } + + internal String_Match_List + find_all_matches_all_buffers(Application_Links *app, Arena *arena, String_Const_u8 pattern, String_Match_Flag must_have_flags, String_Match_Flag must_not_have_flags){ + String_Const_u8_Array array = {&pattern, 1}; + return(find_all_matches_all_buffers(app, arena, array, must_have_flags, must_not_have_flags)); + } //////////////////////////////// - -internal b32 -is_modified(User_Input *input){ - return(is_modified(&input->event)); -} - -internal String_Const_u8 -to_writable(User_Input *in){ - return(to_writable(&in->event)); -} - -internal b32 -has_modifier(User_Input *in, Key_Code key_code){ - b32 result = false; - Input_Modifier_Set *mods = get_modifiers(&in->event); - if (mods != 0){ - result = has_modifier(mods, key_code); - } - return(result); -} - -internal b32 -match_key_code(User_Input *in, Key_Code key_code){ + + internal b32 + is_modified(User_Input *input){ + return(is_modified(&input->event)); + } + + internal String_Const_u8 + to_writable(User_Input *in){ + return(to_writable(&in->event)); + } + + internal b32 + has_modifier(User_Input *in, Key_Code key_code){ + b32 result = false; + Input_Modifier_Set *mods = get_modifiers(&in->event); + if (mods != 0){ + result = has_modifier(mods, key_code); + } + return(result); + } + + internal b32 + match_key_code(User_Input *in, Key_Code key_code){ return(match_key_code(&in->event, key_code)); -} - + } + internal b32 match_core_code(User_Input *in, Key_Code core_code){ - return(match_core_code(&in->event, core_code)); +return(match_core_code(&in->event, core_code)); } internal String_Const_u8 backspace_utf8(String_Const_u8 string){ - if (string.size > 0){ - u64 i = string.size - 1; - for (; i > 0; --i){ - if (string.str[i] <= 0x7F || string.str[i] >= 0xC0){ - break; - } - } - string.size = i; + if (string.size > 0){ +u64 i = string.size - 1; + for (; i > 0; --i){ + if (string.str[i] <= 0x7F || string.str[i] >= 0xC0){ + break; + } + } + string.size = i; } return(string); -} - -//////////////////////////////// - + } + + //////////////////////////////// + Query_Bar_Group::Query_Bar_Group(Application_Links *app){ - this->app = app; + this->app = app; this->view = get_active_view(app, Access_Always); } Query_Bar_Group::Query_Bar_Group(Application_Links *app, View_ID view){ - this->app = app; - this->view = view; + this->app = app; + this->view = view; } Query_Bar_Group::~Query_Bar_Group(){ - clear_all_query_bars(this->app, this->view); -} - -internal b32 -query_user_general(Application_Links *app, Query_Bar *bar, b32 force_number, String_Const_u8 init_string){ - // NOTE(allen|a3.4.4): It will not cause an *error* if we continue on after failing to. - // start a query bar, but it will be unusual behavior from the point of view of the +clear_all_query_bars(this->app, this->view); + } + + internal b32 + query_user_general(Application_Links *app, Query_Bar *bar, b32 force_number, String_Const_u8 init_string){ +// NOTE(allen|a3.4.4): It will not cause an *error* if we continue on after failing to. +// start a query bar, but it will be unusual behavior from the point of view of the // user, if this command starts intercepting input even though no prompt is shown. - // This will only happen if you have a lot of bars open already or if the current view - // doesn't support query bars. - if (start_query_bar(app, bar, 0) == 0){ - return(false); - } - - if (init_string.size > 0){ - String_u8 string = Su8(bar->string.str, bar->string.size, bar->string_capacity); - string_append(&string, init_string); +// This will only happen if you have a lot of bars open already or if the current view + // doesn't support query bars. + if (start_query_bar(app, bar, 0) == 0){ + return(false); + } + + if (init_string.size > 0){ + String_u8 string = Su8(bar->string.str, bar->string.size, bar->string_capacity); + string_append(&string, init_string); bar->string.size = string.string.size; - } - + } + b32 success = true; for (;;){ - // NOTE(allen|a3.4.4): This call will block until the user does one of the input - // types specified in the flags. The first set of flags are inputs you'd like to - // intercept that you don't want to abort on. The second set are inputs that - // you'd like to cause the command to abort. If an event satisfies both flags, it - // is treated as an abort. - User_Input in = get_next_input(app, EventPropertyGroup_AnyKeyboardEvent, - EventProperty_Escape|EventProperty_MouseButton); - - // NOTE(allen|a3.4.4): The responsible thing to do on abort is to end the command - // without waiting on get_next_input again. - if (in.abort){ - success = false; - break; + // NOTE(allen|a3.4.4): This call will block until the user does one of the input +// types specified in the flags. The first set of flags are inputs you'd like to + // intercept that you don't want to abort on. The second set are inputs that + // you'd like to cause the command to abort. If an event satisfies both flags, it +// is treated as an abort. + User_Input in = get_next_input(app, EventPropertyGroup_AnyKeyboardEvent, + EventProperty_Escape|EventProperty_MouseButton); + + // NOTE(allen|a3.4.4): The responsible thing to do on abort is to end the command + // without waiting on get_next_input again. +if (in.abort){ +success = false; + break; + } + + Scratch_Block scratch(app); + b32 good_insert = false; +String_Const_u8 insert_string = to_writable(&in); + if (insert_string.str != 0 && insert_string.size > 0){ + insert_string = string_replace(scratch, insert_string, + string_u8_litexpr("\n"), + string_u8_litexpr("")); + insert_string = string_replace(scratch, insert_string, + string_u8_litexpr("\t"), + string_u8_litexpr("")); + if (force_number){ +if (string_is_integer(insert_string, 10)){ + good_insert = true; } - - Scratch_Block scratch(app); - b32 good_insert = false; - String_Const_u8 insert_string = to_writable(&in); - if (insert_string.str != 0 && insert_string.size > 0){ - insert_string = string_replace(scratch, insert_string, - string_u8_litexpr("\n"), - string_u8_litexpr("")); - insert_string = string_replace(scratch, insert_string, - string_u8_litexpr("\t"), - string_u8_litexpr("")); - if (force_number){ - if (string_is_integer(insert_string, 10)){ - good_insert = true; - } - } - else{ - good_insert = true; - } } - - // NOTE(allen|a3.4.4): All we have to do to update the query bar is edit our + else{ + good_insert = true; + } +} + +// NOTE(allen|a3.4.4): All we have to do to update the query bar is edit our // local Query_Bar struct! This is handy because it means our Query_Bar - // is always correct for typical use without extra work updating the bar. + // is always correct for typical use without extra work updating the bar. if (in.event.kind == InputEventKind_KeyStroke && - (in.event.key.code == KeyCode_Return || in.event.key.code == KeyCode_Tab)){ - break; - } - else if (in.event.kind == InputEventKind_KeyStroke && - in.event.key.code == KeyCode_Backspace){ - bar->string = backspace_utf8(bar->string); + (in.event.key.code == KeyCode_Return || in.event.key.code == KeyCode_Tab)){ + break; + } + else if (in.event.kind == InputEventKind_KeyStroke && + in.event.key.code == KeyCode_Backspace){ + bar->string = backspace_utf8(bar->string); } else if (good_insert){ String_u8 string = Su8(bar->string.str, bar->string.size, bar->string_capacity); - string_append(&string, insert_string); - bar->string.size = string.string.size; + string_append(&string, insert_string); + bar->string.size = string.string.size; + } + else{ + leave_current_input_unhandled(app); + } + } + + return(success); + } + + internal b32 + query_user_string(Application_Links *app, Query_Bar *bar){ + return(query_user_general(app, bar, false, string_u8_empty)); + } + + internal b32 + query_user_number(Application_Links *app, Query_Bar *bar){ +return(query_user_general(app, bar, true, string_u8_empty)); } - else{ - leave_current_input_unhandled(app); - } - } - - return(success); -} - -internal b32 -query_user_string(Application_Links *app, Query_Bar *bar){ - return(query_user_general(app, bar, false, string_u8_empty)); -} - -internal b32 -query_user_number(Application_Links *app, Query_Bar *bar){ - return(query_user_general(app, bar, true, string_u8_empty)); -} - -internal b32 -query_user_number(Application_Links *app, Query_Bar *bar, i32 x){ - Scratch_Block scratch(app); - String_Const_u8 string = push_u8_stringf(scratch, "%d", x); - return(query_user_general(app, bar, true, string)); -} - -//////////////////////////////// - -internal Buffer_Identifier -buffer_identifier(char *str, i32 len){ - Buffer_Identifier identifier; - identifier.name = str; - identifier.name_len = len; - identifier.id = 0; - return(identifier); -} - -internal Buffer_Identifier -buffer_identifier(String_Const_u8 str){ - return(buffer_identifier((char*)str.str, (i32)str.size)); -} - -internal Buffer_Identifier -buffer_identifier(Buffer_ID id){ + + internal b32 + query_user_number(Application_Links *app, Query_Bar *bar, i32 x){ + Scratch_Block scratch(app); + String_Const_u8 string = push_u8_stringf(scratch, "%d", x); + return(query_user_general(app, bar, true, string)); + } + + //////////////////////////////// + + internal Buffer_Identifier + buffer_identifier(char *str, i32 len){ + Buffer_Identifier identifier; + identifier.name = str; + identifier.name_len = len; + identifier.id = 0; + return(identifier); + } + + internal Buffer_Identifier + buffer_identifier(String_Const_u8 str){ + return(buffer_identifier((char*)str.str, (i32)str.size)); + } + + internal Buffer_Identifier + buffer_identifier(Buffer_ID id){ Buffer_Identifier identifier; identifier.name = 0; - identifier.name_len = 0; - identifier.id = id; - return(identifier); -} - -internal Buffer_ID -buffer_identifier_to_id(Application_Links *app, Buffer_Identifier identifier){ - Buffer_ID id = 0; - if (identifier.id != 0){ - id = identifier.id; +identifier.name_len = 0; +identifier.id = id; +return(identifier); + } + + internal Buffer_ID + buffer_identifier_to_id(Application_Links *app, Buffer_Identifier identifier){ +Buffer_ID id = 0; + if (identifier.id != 0){ +id = identifier.id; } else{ - String_Const_u8 name = SCu8(identifier.name, identifier.name_len); - id = get_buffer_by_name(app, name, Access_Always); - if (id == 0){ - id = get_buffer_by_file_name(app, name, Access_Always); - } + String_Const_u8 name = SCu8(identifier.name, identifier.name_len); + id = get_buffer_by_name(app, name, Access_Always); + if (id == 0){ + id = get_buffer_by_file_name(app, name, Access_Always); + } } return(id); -} - -internal Buffer_ID -buffer_identifier_to_id_create_out_buffer(Application_Links *app, Buffer_Identifier buffer_id){ + } + + internal Buffer_ID + buffer_identifier_to_id_create_out_buffer(Application_Links *app, Buffer_Identifier buffer_id){ Buffer_ID result = 0; if (buffer_id.name != 0 && buffer_id.name_len > 0){ - String_Const_u8 buffer_name = SCu8(buffer_id.name, buffer_id.name_len); - Buffer_ID buffer_attach_id = get_buffer_by_name(app, buffer_name, Access_Always); - if (buffer_attach_id != 0){ - result = buffer_attach_id; - } - else{ - buffer_attach_id = create_buffer(app, buffer_name, BufferCreate_AlwaysNew|BufferCreate_NeverAttachToFile); - if (buffer_attach_id != 0){ - buffer_set_setting(app, buffer_attach_id, BufferSetting_ReadOnly, true); - buffer_set_setting(app, buffer_attach_id, BufferSetting_Unimportant, true); - result = buffer_attach_id; - } - } - } - else{ - result = buffer_id.id; + String_Const_u8 buffer_name = SCu8(buffer_id.name, buffer_id.name_len); + Buffer_ID buffer_attach_id = get_buffer_by_name(app, buffer_name, Access_Always); + if (buffer_attach_id != 0){ + result = buffer_attach_id; + } +else{ +buffer_attach_id = create_buffer(app, buffer_name, BufferCreate_AlwaysNew|BufferCreate_NeverAttachToFile); +if (buffer_attach_id != 0){ +buffer_set_setting(app, buffer_attach_id, BufferSetting_ReadOnly, true); + buffer_set_setting(app, buffer_attach_id, BufferSetting_Unimportant, true); + result = buffer_attach_id; +} +} +} +else{ +result = buffer_id.id; } return(result); -} - -//////////////////////////////// - -function void + } + + //////////////////////////////// + + function void place_begin_and_end_on_own_lines(Application_Links *app, char *begin, char *end){ - View_ID view = get_active_view(app, Access_ReadWriteVisible); - Buffer_ID buffer = view_get_buffer(app, view, Access_ReadWriteVisible); + View_ID view = get_active_view(app, Access_ReadWriteVisible); + Buffer_ID buffer = view_get_buffer(app, view, Access_ReadWriteVisible); + + Range_i64 range = get_view_range(app, view); + Range_i64 lines = get_line_range_from_pos_range(app, buffer, range); + range = get_pos_range_from_line_range(app, buffer, lines); + +Scratch_Block scratch(app); + + b32 min_line_blank = line_is_valid_and_blank(app, buffer, lines.min); + b32 max_line_blank = line_is_valid_and_blank(app, buffer, lines.max); - Range_i64 range = get_view_range(app, view); - Range_i64 lines = get_line_range_from_pos_range(app, buffer, range); - range = get_pos_range_from_line_range(app, buffer, lines); - - Scratch_Block scratch(app); - - b32 min_line_blank = line_is_valid_and_blank(app, buffer, lines.min); - b32 max_line_blank = line_is_valid_and_blank(app, buffer, lines.max); - - if ((lines.min < lines.max) || (!min_line_blank)){ + if ((lines.min < lines.max) || (!min_line_blank)){ String_Const_u8 begin_str = {}; String_Const_u8 end_str = {}; - - i64 min_adjustment = 0; - i64 max_adjustment = 0; - + + i64 min_adjustment = 0; + i64 max_adjustment = 0; + if (min_line_blank){ begin_str = push_u8_stringf(scratch, "\n%s", begin); - min_adjustment += 1; - } - else{ - begin_str = push_u8_stringf(scratch, "%s\n", begin); - } - if (max_line_blank){ - end_str = push_u8_stringf(scratch, "%s\n", end); - } - else{ - end_str = push_u8_stringf(scratch, "\n%s", end); - max_adjustment += 1; - } - - max_adjustment += begin_str.size; - Range_i64 new_pos = Ii64(range.min + min_adjustment, range.max + max_adjustment); - - History_Group group = history_group_begin(app, buffer); - buffer_replace_range(app, buffer, Ii64(range.min), begin_str); - buffer_replace_range(app, buffer, Ii64(range.max + begin_str.size), end_str); - history_group_end(group); - - set_view_range(app, view, new_pos); - } + min_adjustment += 1; + } + else{ + begin_str = push_u8_stringf(scratch, "%s\n", begin); + } + if (max_line_blank){ +end_str = push_u8_stringf(scratch, "%s\n", end); + } + else{ + end_str = push_u8_stringf(scratch, "\n%s", end); + max_adjustment += 1; +} + +max_adjustment += begin_str.size; +Range_i64 new_pos = Ii64(range.min + min_adjustment, range.max + max_adjustment); + + History_Group group = history_group_begin(app, buffer); + buffer_replace_range(app, buffer, Ii64(range.min), begin_str); + buffer_replace_range(app, buffer, Ii64(range.max + begin_str.size), end_str); + history_group_end(group); + + set_view_range(app, view, new_pos); + } else{ - String_Const_u8 str = push_u8_stringf(scratch, "%s\n\n%s", begin, end); - buffer_replace_range(app, buffer, range, str); - i64 center_pos = range.min + cstring_length(begin) + 1; - view_set_cursor_and_preferred_x(app, view, seek_pos(center_pos)); - view_set_mark(app, view, seek_pos(center_pos)); + String_Const_u8 str = push_u8_stringf(scratch, "%s\n\n%s", begin, end); + buffer_replace_range(app, buffer, range, str); + i64 center_pos = range.min + cstring_length(begin) + 1; + view_set_cursor_and_preferred_x(app, view, seek_pos(center_pos)); + view_set_mark(app, view, seek_pos(center_pos)); } -} + } -//////////////////////////////// - -function Face_ID -get_view_face_id(Application_Links *app, View_ID view){ - Buffer_ID buffer = view_get_buffer(app, view, Access_Always); - return(get_face_id(app, buffer)); -} - -function Face_Metrics -get_view_face_metrics(Application_Links *app, View_ID view){ - Face_ID face = get_view_face_id(app, view); - return(get_face_metrics(app, face)); -} - -function f32 -get_view_line_height(Application_Links *app, View_ID view){ - Face_Metrics metrics = get_view_face_metrics(app, view); - return(metrics.line_height); -} + //////////////////////////////// + + function Face_ID + get_view_face_id(Application_Links *app, View_ID view){ + Buffer_ID buffer = view_get_buffer(app, view, Access_Always); + return(get_face_id(app, buffer)); + } + + function Face_Metrics + get_view_face_metrics(Application_Links *app, View_ID view){ + Face_ID face = get_view_face_id(app, view); + return(get_face_metrics(app, face)); + } + + function f32 + get_view_line_height(Application_Links *app, View_ID view){ + Face_Metrics metrics = get_view_face_metrics(app, view); + return(metrics.line_height); + } internal View_ID -open_view(Application_Links *app, View_ID view_location, View_Split_Position position){ - View_ID result = 0; - if (view_location != 0 && view_exists(app, view_location)){ - Panel_ID panel_id = view_get_panel(app, view_location); + open_view(Application_Links *app, View_ID view_location, View_Split_Position position){ + View_ID result = 0; + if (view_location != 0 && view_exists(app, view_location)){ + Panel_ID panel_id = view_get_panel(app, view_location); if (panel_id != 0){ - Dimension split = (position == ViewSplit_Left || - position == ViewSplit_Right)?Dimension_X:Dimension_Y; - Side side = (position == ViewSplit_Left || - position == ViewSplit_Top)?Side_Min:Side_Max; + Dimension split = (position == ViewSplit_Left || + position == ViewSplit_Right)?Dimension_X:Dimension_Y; + Side side = (position == ViewSplit_Left || + position == ViewSplit_Top)?Side_Min:Side_Max; if (panel_split(app, panel_id, split)){ - Panel_ID new_panel_id = panel_get_child(app, panel_id, side); - if (new_panel_id != 0){ - View_ID new_view_id = panel_get_view(app, new_panel_id, - Access_Always); - if (new_view_id != 0){ - result = new_view_id; - } - } - } - } + Panel_ID new_panel_id = panel_get_child(app, panel_id, side); + if (new_panel_id != 0){ +View_ID new_view_id = panel_get_view(app, new_panel_id, + Access_Always); + if (new_view_id != 0){ + result = new_view_id; } - return(result); + } +} +} +} +return(result); } internal View_ID get_first_view_with_buffer(Application_Links *app, Buffer_ID buffer_id){ - View_ID result = {}; - if (buffer_id != 0){ - for (View_ID test = get_view_next(app, 0, Access_Always); - test != 0; - test = get_view_next(app, test, Access_Always)){ - Buffer_ID test_buffer = view_get_buffer(app, test, Access_Always); - if (test_buffer == buffer_id){ - result = test; - break; - } + View_ID result = {}; + if (buffer_id != 0){ +for (View_ID test = get_view_next(app, 0, Access_Always); +test != 0; + test = get_view_next(app, test, Access_Always)){ + Buffer_ID test_buffer = view_get_buffer(app, test, Access_Always); + if (test_buffer == buffer_id){ + result = test; + break; } - } - return(result); -} - -internal b32 + } + } + return(result); + } + + internal b32 open_file(Application_Links *app, Buffer_ID *buffer_out, String_Const_u8 file_name, b32 background, b32 never_new){ b32 result = false; - Buffer_ID buffer = get_buffer_by_name(app, file_name, Access_ReadVisible); - b32 exists = buffer_exists(app, buffer); - if (!exists){ - Buffer_Create_Flag flags = 0; - if (background){ - flags |= BufferCreate_Background; - } - if (never_new){ - flags |= BufferCreate_NeverNew; - } - buffer = create_buffer(app, file_name, flags); - exists = buffer_exists(app, buffer); - } - if (exists){ - if (buffer_out != 0){ +Buffer_ID buffer = get_buffer_by_name(app, file_name, Access_ReadVisible); + b32 exists = buffer_exists(app, buffer); + if (!exists){ + Buffer_Create_Flag flags = 0; + if (background){ + flags |= BufferCreate_Background; + } + if (never_new){ + flags |= BufferCreate_NeverNew; + } + buffer = create_buffer(app, file_name, flags); + exists = buffer_exists(app, buffer); + } + if (exists){ + if (buffer_out != 0){ *buffer_out = buffer; + } + result = true; } - result = true; - } return(result); -} + } internal b32 view_open_file(Application_Links *app, View_ID view, String_Const_u8 file_name, b32 never_new){ - b32 result = false; - if (view != 0){ - Buffer_ID buffer = 0; - if (open_file(app, &buffer, file_name, false, never_new)){ - view_set_buffer(app, view, buffer, 0); - result = true; + b32 result = false; + if (view != 0){ + Buffer_ID buffer = 0; + if (open_file(app, &buffer, file_name, false, never_new)){ + view_set_buffer(app, view, buffer, 0); + result = true; } - } - return(result); +} + return(result); } internal void view_disable_highlight_range(Application_Links *app, View_ID view){ - Managed_Scope scope = view_get_managed_scope(app, view); - Managed_Object *highlight = scope_attachment(app, scope, view_highlight_range, Managed_Object); - if (*highlight != 0){ - managed_object_free(app, *highlight); - } - managed_scope_attachment_erase(app, scope, view_highlight_range); - managed_scope_attachment_erase(app, scope, view_highlight_buffer); -} - -internal void -view_set_highlight_range(Application_Links *app, View_ID view, Range_i64 range){ + Managed_Scope scope = view_get_managed_scope(app, view); + Managed_Object *highlight = scope_attachment(app, scope, view_highlight_range, Managed_Object); + if (*highlight != 0){ + managed_object_free(app, *highlight); + } + managed_scope_attachment_erase(app, scope, view_highlight_range); +managed_scope_attachment_erase(app, scope, view_highlight_buffer); + } + + internal void + view_set_highlight_range(Application_Links *app, View_ID view, Range_i64 range){ view_disable_highlight_range(app, view); Buffer_ID buffer = view_get_buffer(app, view, Access_Always); - Managed_Scope scope = view_get_managed_scope(app, view); - Managed_Object *highlight = scope_attachment(app, scope, view_highlight_range, Managed_Object); - *highlight = alloc_buffer_markers_on_buffer(app, buffer, 2, &scope); - Marker markers[2] = {}; - markers[0].pos = range.min; - markers[1].pos = range.max; - managed_object_store_data(app, *highlight, 0, 2, markers); - Buffer_ID *highlight_buffer = scope_attachment(app, scope, view_highlight_buffer, Buffer_ID); + Managed_Scope scope = view_get_managed_scope(app, view); + Managed_Object *highlight = scope_attachment(app, scope, view_highlight_range, Managed_Object); + *highlight = alloc_buffer_markers_on_buffer(app, buffer, 2, &scope); +Marker markers[2] = {}; +markers[0].pos = range.min; + markers[1].pos = range.max; + managed_object_store_data(app, *highlight, 0, 2, markers); + Buffer_ID *highlight_buffer = scope_attachment(app, scope, view_highlight_buffer, Buffer_ID); *highlight_buffer = buffer; } - -function void -view_look_at_region(Application_Links *app, View_ID view, i64 major_pos, i64 minor_pos){ - Range_i64 range = Ii64(major_pos, minor_pos); - b32 bottom_major = false; - if (major_pos == range.max){ - bottom_major = true; - } - Buffer_Cursor top = view_compute_cursor(app, view, seek_pos(range.min)); + function void + view_look_at_region(Application_Links *app, View_ID view, i64 major_pos, i64 minor_pos){ + Range_i64 range = Ii64(major_pos, minor_pos); + b32 bottom_major = false; + if (major_pos == range.max){ + bottom_major = true; +} + +Buffer_Cursor top = view_compute_cursor(app, view, seek_pos(range.min)); if (top.line > 0){ - Buffer_Cursor bottom = view_compute_cursor(app, view, seek_pos(range.max)); - if (bottom.line > 0){ - Rect_f32 region = view_get_buffer_region(app, view); - f32 view_height = rect_height(region); - f32 skirt_height = view_height*.1f; - Range_f32 acceptable_y = If32(skirt_height, view_height*.9f); - - f32 target_height = view_line_y_difference(app, view, bottom.line + 1, top.line); - - f32 line_height = get_view_line_height(app, view); - if (target_height + 2*line_height > view_height){ - i64 major_line = bottom.line; - if (range.min == major_pos){ - major_line = top.line; + Buffer_Cursor bottom = view_compute_cursor(app, view, seek_pos(range.max)); + if (bottom.line > 0){ + Rect_f32 region = view_get_buffer_region(app, view); + f32 view_height = rect_height(region); +f32 skirt_height = view_height*.1f; + Range_f32 acceptable_y = If32(skirt_height, view_height*.9f); + + f32 target_height = view_line_y_difference(app, view, bottom.line + 1, top.line); + +f32 line_height = get_view_line_height(app, view); + if (target_height + 2*line_height > view_height){ + i64 major_line = bottom.line; + if (range.min == major_pos){ + major_line = top.line; + } + + Buffer_Scroll scroll = view_get_buffer_scroll(app, view); + scroll.target.line_number = major_line; + scroll.target.pixel_shift.y = -skirt_height; + view_set_buffer_scroll(app, view, scroll, SetBufferScroll_SnapCursorIntoView); + } +else{ + Buffer_Scroll scroll = view_get_buffer_scroll(app, view); + Vec2_f32 top_p = view_relative_xy_of_pos(app, view, scroll.position.line_number, range.min); + top_p -= scroll.position.pixel_shift; +if (top_p.y < acceptable_y.min){ + scroll.target.line_number = top.line; + scroll.target.pixel_shift.y = -skirt_height; + view_set_buffer_scroll(app, view, scroll, SetBufferScroll_NoCursorChange); + } + else{ + Vec2_f32 bot_p = view_relative_xy_of_pos(app, view, scroll.position.line_number, range.max); + bot_p -= scroll.position.pixel_shift; + if (bot_p.y > acceptable_y.max){ + scroll.target.line_number = bottom.line; + scroll.target.pixel_shift.y = skirt_height - view_height; + view_set_buffer_scroll(app, view, scroll, SetBufferScroll_NoCursorChange); + } + } + } +} + } + } + + function void + view_look_at_region(Application_Links *app, View_ID view, Range_i64 range){ + view_look_at_region(app, view, range.min, range.max); + } + + //////////////////////////////// + + function Buffer_ID + get_buffer_next_looped(Application_Links *app, Buffer_ID buffer, Access_Flag access){ + buffer = get_buffer_next(app, buffer, access); + if (buffer == 0){ +buffer = get_buffer_next(app, 0, access); + } + return(buffer); } - Buffer_Scroll scroll = view_get_buffer_scroll(app, view); - scroll.target.line_number = major_line; - scroll.target.pixel_shift.y = -skirt_height; - view_set_buffer_scroll(app, view, scroll, SetBufferScroll_SnapCursorIntoView); - } - else{ - Buffer_Scroll scroll = view_get_buffer_scroll(app, view); - Vec2_f32 top_p = view_relative_xy_of_pos(app, view, scroll.position.line_number, range.min); - top_p -= scroll.position.pixel_shift; - if (top_p.y < acceptable_y.min){ - scroll.target.line_number = top.line; - scroll.target.pixel_shift.y = -skirt_height; - view_set_buffer_scroll(app, view, scroll, SetBufferScroll_NoCursorChange); - } - else{ - Vec2_f32 bot_p = view_relative_xy_of_pos(app, view, scroll.position.line_number, range.max); - bot_p -= scroll.position.pixel_shift; - if (bot_p.y > acceptable_y.max){ - scroll.target.line_number = bottom.line; - scroll.target.pixel_shift.y = skirt_height - view_height; - view_set_buffer_scroll(app, view, scroll, SetBufferScroll_NoCursorChange); + //////////////////////////////// + + internal View_ID + get_next_view_looped_all_panels(Application_Links *app, View_ID view_id, Access_Flag access){ +view_id = get_view_next(app, view_id, access); + if (view_id == 0){ + view_id = get_view_next(app, 0, access); +} + return(view_id); } + + internal View_ID + get_prev_view_looped_all_panels(Application_Links *app, View_ID view_id, Access_Flag access){ + view_id = get_view_prev(app, view_id, access); + if (view_id == 0){ + view_id = get_view_prev(app, 0, access); + } + return(view_id); + } + + //////////////////////////////// + + internal Buffer_Kill_Result + try_buffer_kill(Application_Links *app, Buffer_ID buffer, View_ID gui_view_id, Buffer_Kill_Flag flags){ + Buffer_Kill_Result result = buffer_kill(app, buffer, flags); + if (result == BufferKillResult_Dirty){ + if (do_buffer_kill_user_check(app, buffer, gui_view_id)){ + result = buffer_kill(app, buffer, BufferKill_AlwaysKill); +} } + return(result); } - } - } -} - -function void -view_look_at_region(Application_Links *app, View_ID view, Range_i64 range){ - view_look_at_region(app, view, range.min, range.max); -} - -//////////////////////////////// - -function Buffer_ID -get_buffer_next_looped(Application_Links *app, Buffer_ID buffer, Access_Flag access){ - buffer = get_buffer_next(app, buffer, access); - if (buffer == 0){ - buffer = get_buffer_next(app, 0, access); - } - return(buffer); -} - -//////////////////////////////// - -internal View_ID -get_next_view_looped_all_panels(Application_Links *app, View_ID view_id, Access_Flag access){ - view_id = get_view_next(app, view_id, access); - if (view_id == 0){ - view_id = get_view_next(app, 0, access); - } - return(view_id); -} - -internal View_ID -get_prev_view_looped_all_panels(Application_Links *app, View_ID view_id, Access_Flag access){ - view_id = get_view_prev(app, view_id, access); - if (view_id == 0){ - view_id = get_view_prev(app, 0, access); - } - return(view_id); -} - -//////////////////////////////// - -internal Buffer_Kill_Result -try_buffer_kill(Application_Links *app, Buffer_ID buffer, View_ID gui_view_id, Buffer_Kill_Flag flags){ - Buffer_Kill_Result result = buffer_kill(app, buffer, flags); - if (result == BufferKillResult_Dirty){ - if (do_buffer_kill_user_check(app, buffer, gui_view_id)){ - result = buffer_kill(app, buffer, BufferKill_AlwaysKill); - } - } - return(result); -} - -//////////////////////////////// - -internal String_Const_u8 + + //////////////////////////////// + + internal String_Const_u8 get_query_string(Application_Links *app, char *query_str, u8 *string_space, i32 space_size){ - Query_Bar_Group group(app); - Query_Bar bar = {}; - bar.prompt = SCu8((u8*)query_str); - bar.string = SCu8(string_space, (u64)0); - bar.string_capacity = space_size; - if (!query_user_string(app, &bar)){ - bar.string.size = 0; + Query_Bar_Group group(app); +Query_Bar bar = {}; +bar.prompt = SCu8((u8*)query_str); +bar.string = SCu8(string_space, (u64)0); +bar.string_capacity = space_size; +if (!query_user_string(app, &bar)){ + bar.string.size = 0; + } + return(bar.string); } - return(bar.string); -} internal Token* -get_token_from_pos(Application_Links *app, Token_Array *array, u64 pos){ - Token *result = 0; + get_token_from_pos(Application_Links *app, Token_Array *array, u64 pos){ + Token *result = 0; if (array->count > 0){ - i64 index = token_index_from_pos(array, pos); - result = array->tokens + index; - } - return(result); + i64 index = token_index_from_pos(array, pos); +result = array->tokens + index; +} +return(result); } internal Token* get_token_from_pos(Application_Links *app, Buffer_ID buffer, u64 pos){ - Token_Array array = get_token_array_from_buffer(app, buffer); - return(get_token_from_pos(app, &array, pos)); + Token_Array array = get_token_array_from_buffer(app, buffer); +return(get_token_from_pos(app, &array, pos)); } internal String_Const_u8 -push_token_or_word_under_pos(Application_Links *app, Arena *arena, Buffer_ID buffer, u64 pos){ - String_Const_u8 result = {}; - Token *token = get_token_from_pos(app, buffer, pos); - if (token != 0 && token->size > 0 && token->kind != TokenBaseKind_Whitespace){ - Range_i64 range = Ii64(token); - result = push_buffer_range(app, arena, buffer, range); - } - return(result); + push_token_or_word_under_pos(Application_Links *app, Arena *arena, Buffer_ID buffer, u64 pos){ + String_Const_u8 result = {}; +Token *token = get_token_from_pos(app, buffer, pos); +if (token != 0 && token->size > 0 && token->kind != TokenBaseKind_Whitespace){ + Range_i64 range = Ii64(token); + result = push_buffer_range(app, arena, buffer, range); + } + return(result); } - -internal String_Const_u8 -push_token_or_word_under_active_cursor(Application_Links *app, Arena *arena){ - View_ID view = get_active_view(app, Access_Always); - Buffer_ID buffer = view_get_buffer(app, view, Access_Always); - i64 pos = view_get_cursor_pos(app, view); - return(push_token_or_word_under_pos(app, arena, buffer, pos)); -} - -//////////////////////////////// - -internal b32 + + internal String_Const_u8 + push_token_or_word_under_active_cursor(Application_Links *app, Arena *arena){ + View_ID view = get_active_view(app, Access_Always); + Buffer_ID buffer = view_get_buffer(app, view, Access_Always); + i64 pos = view_get_cursor_pos(app, view); +return(push_token_or_word_under_pos(app, arena, buffer, pos)); + } + + //////////////////////////////// + + internal b32 file_exists(Application_Links *app, String_Const_u8 file_name){ Scratch_Block scratch(app); - File_Attributes attributes = system_quick_file_attributes(scratch, file_name); - return(attributes.last_write_time > 0); -} + File_Attributes attributes = system_quick_file_attributes(scratch, file_name); +return(attributes.last_write_time > 0); + } -internal b32 -file_exists_and_is_file(Application_Links *app, String_Const_u8 file_name){ - Scratch_Block scratch(app); - File_Attributes attributes = system_quick_file_attributes(scratch, file_name); + internal b32 + file_exists_and_is_file(Application_Links *app, String_Const_u8 file_name){ + Scratch_Block scratch(app); +File_Attributes attributes = system_quick_file_attributes(scratch, file_name); return(attributes.last_write_time > 0 && !HasFlag(attributes.flags, FileAttribute_IsDirectory)); -} - -internal b32 -file_exists_and_is_folder(Application_Links *app, String_Const_u8 file_name){ + } + + internal b32 + file_exists_and_is_folder(Application_Links *app, String_Const_u8 file_name){ Scratch_Block scratch(app); - File_Attributes attributes = system_quick_file_attributes(scratch, file_name); +File_Attributes attributes = system_quick_file_attributes(scratch, file_name); return(attributes.last_write_time > 0 && HasFlag(attributes.flags, FileAttribute_IsDirectory)); -} + } internal Data -dump_file_handle(Arena *arena, FILE *file){ - Data result = {}; - if (file != 0){ - fseek(file, 0, SEEK_END); + dump_file_handle(Arena *arena, FILE *file){ +Data result = {}; + if (file != 0){ + fseek(file, 0, SEEK_END); u64 size = ftell(file); - char *mem = push_array(arena, char, size); - if (mem != 0){ - fseek(file, 0, SEEK_SET); - fread(mem, 1, (size_t)size, file); - result = make_data(mem, size); - } - } + char *mem = push_array(arena, char, size); + if (mem != 0){ + fseek(file, 0, SEEK_SET); + fread(mem, 1, (size_t)size, file); + result = make_data(mem, size); + } + } return(result); -} - + } + internal String_Const_u8 push_file_search_up_path(Application_Links *app, Arena *arena, String_Const_u8 start_path, String_Const_u8 file_name){ - String_Const_u8 result = {}; - String_Const_u8 path = start_path; - for (;path.size > 0;){ - Temp_Memory temp = begin_temp(arena); - if (character_is_slash(string_get_character(path, path.size - 1))){ - path = string_chop(path, 1); - } - String_Const_u8 full_path = push_u8_stringf(arena, "%.*s/%.*s", - string_expand(path), - string_expand(file_name)); - if (file_exists(app, full_path)){ - result = full_path; - break; - } - path = string_remove_last_folder(path); - end_temp(temp); +String_Const_u8 result = {}; +String_Const_u8 path = start_path; +for (;path.size > 0;){ + Temp_Memory temp = begin_temp(arena); + if (character_is_slash(string_get_character(path, path.size - 1))){ + path = string_chop(path, 1); } - return(result); -} - -internal FILE* -open_file_try_current_path_then_binary_path(Application_Links *app, char *file_name){ - FILE *file = fopen(file_name, "rb"); + String_Const_u8 full_path = push_u8_stringf(arena, "%.*s/%.*s", + string_expand(path), +string_expand(file_name)); + if (file_exists(app, full_path)){ + result = full_path; + break; + } + path = string_remove_last_folder(path); + end_temp(temp); + } + return(result); + } + + internal FILE* + open_file_try_current_path_then_binary_path(Application_Links *app, char *file_name){ + FILE *file = fopen(file_name, "rb"); if (file == 0){ - Scratch_Block scratch(app); - List_String_Const_u8 list = {}; - string_list_push(scratch, &list, system_get_path(scratch, SystemPath_Binary)); - string_list_push_overlap(scratch, &list, '/', SCu8(file_name)); - String_Const_u8 str = string_list_flatten(scratch, list, StringFill_NullTerminate); - file = fopen((char*)str.str, "rb"); - } - return(file); +Scratch_Block scratch(app); + List_String_Const_u8 list = {}; + string_list_push(scratch, &list, system_get_path(scratch, SystemPath_Binary)); + string_list_push_overlap(scratch, &list, '/', SCu8(file_name)); + String_Const_u8 str = string_list_flatten(scratch, list, StringFill_NullTerminate); +file = fopen((char*)str.str, "rb"); +} +return(file); } internal FILE* open_file(Arena *scratch, String_Const_u8 name){ - Temp_Memory temp = begin_temp(scratch); - String_Const_u8 name_copy = push_string_copy(scratch, name); - FILE *file = fopen((char*)name_copy.str, "rb"); - end_temp(temp); - return(file); -} - -internal File_Name_Data -dump_file(Arena *arena, String_Const_u8 file_name){ - File_Name_Data result = {}; - FILE *file = open_file(arena, file_name); - if (file != 0){ - result.file_name = file_name; - result.data = dump_file_handle(arena, file); - fclose(file); +Temp_Memory temp = begin_temp(scratch); + String_Const_u8 name_copy = push_string_copy(scratch, name); + FILE *file = fopen((char*)name_copy.str, "rb"); + end_temp(temp); + return(file); + } + + internal File_Name_Data + dump_file(Arena *arena, String_Const_u8 file_name){ +File_Name_Data result = {}; + FILE *file = open_file(arena, file_name); +if (file != 0){ + result.file_name = file_name; + result.data = dump_file_handle(arena, file); +fclose(file); + } +return(result); } - return(result); + + internal File_Name_Data + dump_file_search_up_path(Application_Links *app, Arena *arena, String_Const_u8 path, String_Const_u8 file_name){ + File_Name_Data result = {}; + String_Const_u8 full_path = push_file_search_up_path(app, arena, path, file_name); + if (full_path.size > 0){ + result = dump_file(arena, full_path); } - -internal File_Name_Data -dump_file_search_up_path(Application_Links *app, Arena *arena, String_Const_u8 path, String_Const_u8 file_name){ - File_Name_Data result = {}; - String_Const_u8 full_path = push_file_search_up_path(app, arena, path, file_name); - if (full_path.size > 0){ - result = dump_file(arena, full_path); - } - return(result); +return(result); } internal void sort_pairs_by_key__quick(Sort_Pair_i32 *pairs, i32 first, i32 one_past_last){ - i32 dif = one_past_last - first; + i32 dif = one_past_last - first; if (dif >= 2){ - i32 pivot = one_past_last - 1; + i32 pivot = one_past_last - 1; Sort_Pair_i32 pivot_pair = pairs[pivot]; i32 j = first; - b32 interleave = false; + b32 interleave = false; for (i32 i = first; i < pivot; i += 1){ - Sort_Pair_i32 pair = pairs[i]; - if (pair.key < pivot_pair.key){ - pairs[i] = pairs[j]; - pairs[j] = pair; - j += 1; - } - else if (pair.key == pivot_pair.key){ - if (interleave){ - pairs[i] = pairs[j]; - pairs[j] = pair; - j += 1; - } - interleave = !interleave; - } + Sort_Pair_i32 pair = pairs[i]; + if (pair.key < pivot_pair.key){ + pairs[i] = pairs[j]; + pairs[j] = pair; + j += 1; +} + else if (pair.key == pivot_pair.key){ + if (interleave){ + pairs[i] = pairs[j]; + pairs[j] = pair; + j += 1; + } + interleave = !interleave; + } } pairs[pivot] = pairs[j]; pairs[j] = pivot_pair; sort_pairs_by_key__quick(pairs, first, j); - sort_pairs_by_key__quick(pairs, j + 1, one_past_last); - } -} + sort_pairs_by_key__quick(pairs, j + 1, one_past_last); + } + } + + internal void + sort_pairs_by_key(Sort_Pair_i32 *pairs, i32 count){ + sort_pairs_by_key__quick(pairs, 0, count); + } -internal void -sort_pairs_by_key(Sort_Pair_i32 *pairs, i32 count){ - sort_pairs_by_key__quick(pairs, 0, count); -} - -internal Range_i32_Array -get_ranges_of_duplicate_keys(Arena *arena, i32 *keys, i32 stride, i32 count){ - Range_i32_Array result = {}; - result.ranges = push_array(arena, Range_i32, count); - u8 *ptr = (u8*)keys; - i32 start_i = 0; + internal Range_i32_Array + get_ranges_of_duplicate_keys(Arena *arena, i32 *keys, i32 stride, i32 count){ + Range_i32_Array result = {}; + result.ranges = push_array(arena, Range_i32, count); +u8 *ptr = (u8*)keys; + i32 start_i = 0; for (i32 i = 1; i <= count; i += 1){ - b32 is_end = false; - if (i == count){ - is_end = true; - } + b32 is_end = false; + if (i == count){ + is_end = true; + } else if (*(i32*)(ptr + i*stride) != *(i32*)(ptr + start_i*stride)){ - is_end = true; - } + is_end = true; + } if (is_end){ - Range_i32 *new_range = &result.ranges[result.count++]; - new_range->first = start_i; - new_range->one_past_last = i; - start_i = i; - } - } - pop_array(arena, Range_i32, count - result.count); + Range_i32 *new_range = &result.ranges[result.count++]; + new_range->first = start_i; +new_range->one_past_last = i; + start_i = i; + } + } + pop_array(arena, Range_i32, count - result.count); return(result); -} - -internal void -no_mark_snap_to_cursor(Application_Links *app, Managed_Scope view_scope){ + } + + internal void + no_mark_snap_to_cursor(Application_Links *app, Managed_Scope view_scope){ b32 *snap_to_cursor = scope_attachment(app, view_scope, view_snap_mark_to_cursor, b32); - *snap_to_cursor = false; + *snap_to_cursor = false; + } + + internal void + no_mark_snap_to_cursor(Application_Links *app, View_ID view_id){ + Managed_Scope scope = view_get_managed_scope(app, view_id); + no_mark_snap_to_cursor(app, scope); + } + + internal void + no_mark_snap_to_cursor_if_shift(Application_Links *app, View_ID view_id){ + Scratch_Block scratch(app); + Input_Modifier_Set mods = system_get_keyboard_modifiers(scratch); + if (has_modifier(&mods, KeyCode_Shift)){ +no_mark_snap_to_cursor(app, view_id); + } + } + + internal b32 + view_has_highlighted_range(Application_Links *app, View_ID view){ +b32 result = false; + if (fcoder_mode == FCoderMode_NotepadLike){ + i64 pos = view_get_cursor_pos(app, view); +i64 mark = view_get_mark_pos(app, view); +result = (pos != mark); } - -internal void -no_mark_snap_to_cursor(Application_Links *app, View_ID view_id){ - Managed_Scope scope = view_get_managed_scope(app, view_id); - no_mark_snap_to_cursor(app, scope); -} - -internal void -no_mark_snap_to_cursor_if_shift(Application_Links *app, View_ID view_id){ - Scratch_Block scratch(app); - Input_Modifier_Set mods = system_get_keyboard_modifiers(scratch); - if (has_modifier(&mods, KeyCode_Shift)){ - no_mark_snap_to_cursor(app, view_id); - } +return(result); } internal b32 -view_has_highlighted_range(Application_Links *app, View_ID view){ - b32 result = false; - if (fcoder_mode == FCoderMode_NotepadLike){ - i64 pos = view_get_cursor_pos(app, view); - i64 mark = view_get_mark_pos(app, view); - result = (pos != mark); - } - return(result); -} - -internal b32 -if_view_has_highlighted_range_delete_range(Application_Links *app, View_ID view_id){ - b32 result = false; + if_view_has_highlighted_range_delete_range(Application_Links *app, View_ID view_id){ + b32 result = false; if (view_has_highlighted_range(app, view_id)){ - Range_i64 range = get_view_range(app, view_id); + Range_i64 range = get_view_range(app, view_id); Buffer_ID buffer = view_get_buffer(app, view_id, Access_ReadWriteVisible); buffer_replace_range(app, buffer, range, string_u8_litexpr("")); - result = true; - } - return(result); -} + result = true; + } + return(result); + } -internal void -begin_notepad_mode(Application_Links *app){ - fcoder_mode = FCoderMode_NotepadLike; - for (View_ID view = get_view_next(app, 0, Access_Always); - view != 0; - view = get_view_next(app, view, Access_Always)){ - i64 pos = view_get_cursor_pos(app, view); - view_set_mark(app, view, seek_pos(pos)); - } + internal void + begin_notepad_mode(Application_Links *app){ + fcoder_mode = FCoderMode_NotepadLike; +for (View_ID view = get_view_next(app, 0, Access_Always); + view != 0; +view = get_view_next(app, view, Access_Always)){ + i64 pos = view_get_cursor_pos(app, view); + view_set_mark(app, view, seek_pos(pos)); +} } //////////////////////////////// -internal void + internal void seek_pos_of_textual_line(Application_Links *app, Side side){ - View_ID view = get_active_view(app, Access_ReadVisible); + View_ID view = get_active_view(app, Access_ReadVisible); Buffer_ID buffer = view_get_buffer(app, view, Access_ReadVisible); i64 pos = view_get_cursor_pos(app, view); - i64 new_pos = get_line_side_pos_from_pos(app, buffer, pos, side); +i64 new_pos = get_line_side_pos_from_pos(app, buffer, pos, side); view_set_cursor_and_preferred_x(app, view, seek_pos(new_pos)); - no_mark_snap_to_cursor_if_shift(app, view); -} + no_mark_snap_to_cursor_if_shift(app, view); + } internal void seek_pos_of_visual_line(Application_Links *app, Side side){ - View_ID view = get_active_view(app, Access_ReadVisible); + View_ID view = get_active_view(app, Access_ReadVisible); i64 pos = view_get_cursor_pos(app, view); Buffer_Cursor cursor = view_compute_cursor(app, view, seek_pos(pos)); - Vec2_f32 p = view_relative_xy_of_pos(app, view, cursor.line, pos); - p.x = (side == Side_Min)?(0.f):(max_f32); - i64 new_pos = view_pos_at_relative_xy(app, view, cursor.line, p); - view_set_cursor_and_preferred_x(app, view, seek_pos(new_pos)); - no_mark_snap_to_cursor_if_shift(app, view); -} - -CUSTOM_COMMAND_SIG(seek_beginning_of_textual_line) -CUSTOM_DOC("Seeks the cursor to the beginning of the line across all text.") + Vec2_f32 p = view_relative_xy_of_pos(app, view, cursor.line, pos); + p.x = (side == Side_Min)?(0.f):(max_f32); +i64 new_pos = view_pos_at_relative_xy(app, view, cursor.line, p); + view_set_cursor_and_preferred_x(app, view, seek_pos(new_pos)); + no_mark_snap_to_cursor_if_shift(app, view); + } + + CUSTOM_COMMAND_SIG(seek_beginning_of_textual_line) + CUSTOM_DOC("Seeks the cursor to the beginning of the line across all text.") { seek_pos_of_textual_line(app, Side_Min); -} + } -CUSTOM_COMMAND_SIG(seek_end_of_textual_line) + CUSTOM_COMMAND_SIG(seek_end_of_textual_line) CUSTOM_DOC("Seeks the cursor to the end of the line across all text.") -{ - seek_pos_of_textual_line(app, Side_Max); -} - -CUSTOM_COMMAND_SIG(seek_beginning_of_line) -CUSTOM_DOC("Seeks the cursor to the beginning of the visual line.") + { + seek_pos_of_textual_line(app, Side_Max); + } + + CUSTOM_COMMAND_SIG(seek_beginning_of_line) + CUSTOM_DOC("Seeks the cursor to the beginning of the visual line.") { seek_pos_of_visual_line(app, Side_Min); -} - -CUSTOM_COMMAND_SIG(seek_end_of_line) -CUSTOM_DOC("Seeks the cursor to the end of the visual line.") -{ - seek_pos_of_visual_line(app, Side_Max); -} - -CUSTOM_COMMAND_SIG(goto_beginning_of_file) -CUSTOM_DOC("Sets the cursor to the beginning of the file.") -{ - View_ID view = get_active_view(app, Access_ReadVisible); - view_set_cursor_and_preferred_x(app, view, seek_pos(0)); - no_mark_snap_to_cursor_if_shift(app, view); -} - -CUSTOM_COMMAND_SIG(goto_end_of_file) -CUSTOM_DOC("Sets the cursor to the end of the file.") -{ - View_ID view = get_active_view(app, Access_ReadVisible); - Buffer_ID buffer_id = view_get_buffer(app, view, Access_ReadVisible); - i32 size = (i32)buffer_get_size(app, buffer_id); - view_set_cursor_and_preferred_x(app, view, seek_pos(size)); - no_mark_snap_to_cursor_if_shift(app, view); -} - -//////////////////////////////// - -internal b32 -view_set_split(Application_Links *app, View_ID view, View_Split_Kind kind, f32 t){ - b32 result = false; - if (view != 0){ - Panel_ID panel_id = view_get_panel(app, view); - if (panel_id != 0){ - Panel_ID parent_panel_id = panel_get_parent(app, panel_id); - if (parent_panel_id != 0){ - Panel_ID min_child_id = panel_get_child(app, parent_panel_id, Side_Min); - if (min_child_id != 0){ - b32 panel_is_min = (min_child_id == panel_id); - Panel_Split_Kind panel_kind = ((kind == ViewSplitKind_Ratio)? - (panel_is_min?PanelSplitKind_Ratio_Min:PanelSplitKind_Ratio_Max): - (panel_is_min?PanelSplitKind_FixedPixels_Min:PanelSplitKind_FixedPixels_Max)); - result = panel_set_split(app, parent_panel_id, panel_kind, t); - } - } } + + CUSTOM_COMMAND_SIG(seek_end_of_line) + CUSTOM_DOC("Seeks the cursor to the end of the visual line.") + { + seek_pos_of_visual_line(app, Side_Max); + } + + CUSTOM_COMMAND_SIG(goto_beginning_of_file) + CUSTOM_DOC("Sets the cursor to the beginning of the file.") +{ +View_ID view = get_active_view(app, Access_ReadVisible); +view_set_cursor_and_preferred_x(app, view, seek_pos(0)); + no_mark_snap_to_cursor_if_shift(app, view); + } + + CUSTOM_COMMAND_SIG(goto_end_of_file) + CUSTOM_DOC("Sets the cursor to the end of the file.") + { + View_ID view = get_active_view(app, Access_ReadVisible); + Buffer_ID buffer_id = view_get_buffer(app, view, Access_ReadVisible); + i32 size = (i32)buffer_get_size(app, buffer_id); + view_set_cursor_and_preferred_x(app, view, seek_pos(size)); +no_mark_snap_to_cursor_if_shift(app, view); + } + + //////////////////////////////// + + internal b32 +view_set_split(Application_Links *app, View_ID view, View_Split_Kind kind, f32 t){ + b32 result = false; + if (view != 0){ + Panel_ID panel_id = view_get_panel(app, view); + if (panel_id != 0){ + Panel_ID parent_panel_id = panel_get_parent(app, panel_id); +if (parent_panel_id != 0){ + Panel_ID min_child_id = panel_get_child(app, parent_panel_id, Side_Min); + if (min_child_id != 0){ + b32 panel_is_min = (min_child_id == panel_id); +Panel_Split_Kind panel_kind = ((kind == ViewSplitKind_Ratio)? + (panel_is_min?PanelSplitKind_Ratio_Min:PanelSplitKind_Ratio_Max): +(panel_is_min?PanelSplitKind_FixedPixels_Min:PanelSplitKind_FixedPixels_Max)); + result = panel_set_split(app, parent_panel_id, panel_kind, t); + } +} +} +} +return(result); + } + +internal b32 + view_set_split_proportion(Application_Links *app, View_ID view, f32 t){ +return(view_set_split(app, view, ViewSplitKind_Ratio, t)); } - return(result); -} - -internal b32 -view_set_split_proportion(Application_Links *app, View_ID view, f32 t){ - return(view_set_split(app, view, ViewSplitKind_Ratio, t)); -} - -internal b32 + + internal b32 view_set_split_pixel_size(Application_Links *app, View_ID view, i32 t){ return(view_set_split(app, view, ViewSplitKind_FixedPixels, (f32)t)); -} - -//////////////////////////////// + } + + //////////////////////////////// internal Record_Info get_single_record(Application_Links *app, Buffer_ID buffer_id, History_Record_Index index){ - Record_Info record = buffer_history_get_record_info(app, buffer_id, index); - if (record.error == RecordError_NoError && record.kind == RecordKind_Group){ - record = buffer_history_get_group_sub_record(app, buffer_id, index, record.group_count - 1); +Record_Info record = buffer_history_get_record_info(app, buffer_id, index); + if (record.error == RecordError_NoError && record.kind == RecordKind_Group){ + record = buffer_history_get_group_sub_record(app, buffer_id, index, record.group_count - 1); } return(record); -} - -//////////////////////////////// - -function Nest_Delimiter_Kind -get_nest_delimiter_kind(Token_Base_Kind kind, Find_Nest_Flag flags){ + } + + //////////////////////////////// + + function Nest_Delimiter_Kind + get_nest_delimiter_kind(Token_Base_Kind kind, Find_Nest_Flag flags){ Nest_Delimiter_Kind result = NestDelim_None; switch (kind){ - case TokenBaseKind_ScopeOpen: - { - if (HasFlag(flags, FindNest_Scope)){ - result = NestDelim_Open; - } - }break; - case TokenBaseKind_ScopeClose: - { - if (HasFlag(flags, FindNest_Scope)){ - result = NestDelim_Close; - } - }break; - case TokenBaseKind_ParentheticalOpen: - { - if (HasFlag(flags, FindNest_Paren)){ - result = NestDelim_Open; - } - }break; - case TokenBaseKind_ParentheticalClose: - { - if (HasFlag(flags, FindNest_Paren)){ - result = NestDelim_Close; - } - }break; + case TokenBaseKind_ScopeOpen: + { + if (HasFlag(flags, FindNest_Scope)){ + result = NestDelim_Open; } - return(result); + }break; +case TokenBaseKind_ScopeClose: +{ +if (HasFlag(flags, FindNest_Scope)){ +result = NestDelim_Close; +} +}break; +case TokenBaseKind_ParentheticalOpen: +{ +if (HasFlag(flags, FindNest_Paren)){ +result = NestDelim_Open; +} +}break; +case TokenBaseKind_ParentheticalClose: +{ +if (HasFlag(flags, FindNest_Paren)){ +result = NestDelim_Close; +} +}break; +} +return(result); } function b32 find_nest_side(Application_Links *app, Buffer_ID buffer, i64 pos, - Find_Nest_Flag flags, Scan_Direction scan, Nest_Delimiter_Kind delim, - Range_i64 *out){ - b32 result = false; - - b32 balanced = HasFlag(flags, FindNest_Balanced); +Find_Nest_Flag flags, Scan_Direction scan, Nest_Delimiter_Kind delim, +Range_i64 *out){ +b32 result = false; + + b32 balanced = HasFlag(flags, FindNest_Balanced); if (balanced){ - if ((delim == NestDelim_Open && scan == Scan_Forward) || - (delim == NestDelim_Close && scan == Scan_Backward)){ - balanced = false; - } + if ((delim == NestDelim_Open && scan == Scan_Forward) || + (delim == NestDelim_Close && scan == Scan_Backward)){ + balanced = false; } +} Managed_Scope scope = buffer_get_managed_scope(app, buffer); Token_Array *tokens = scope_attachment(app, scope, attachment_tokens, Token_Array); - if (tokens != 0 && tokens->count > 0){ - Token_Iterator_Array it = token_iterator_pos(0, tokens, pos); - i32 level = 0; - for (;;){ - Token *token = token_it_read(&it); - Nest_Delimiter_Kind token_delim = get_nest_delimiter_kind(token->kind, flags); - - if (level == 0 && token_delim == delim){ - *out = Ii64_size(token->pos, token->size); - result = true; - break; - } - - if (balanced && token_delim != NestDelim_None){ - level += (token_delim == delim)?-1:1; - } - - b32 good = false; - if (scan == Scan_Forward){ - good = token_it_inc(&it); - } - else{ - good = token_it_dec(&it); - } - if (!good){ - break; - } - } - } - - return(result); +if (tokens != 0 && tokens->count > 0){ +Token_Iterator_Array it = token_iterator_pos(0, tokens, pos); +i32 level = 0; +for (;;){ +Token *token = token_it_read(&it); +Nest_Delimiter_Kind token_delim = get_nest_delimiter_kind(token->kind, flags); + +if (level == 0 && token_delim == delim){ +*out = Ii64_size(token->pos, token->size); +result = true; +break; } -function b32 +if (balanced && token_delim != NestDelim_None){ +level += (token_delim == delim)?-1:1; +} + +b32 good = false; +if (scan == Scan_Forward){ +good = token_it_inc(&it); + } +else{ +good = token_it_dec(&it); + } +if (!good){ + break; + } + } + } + + return(result); +} + + function b32 find_nest_side(Application_Links *app, Buffer_ID buffer, i64 pos, - Find_Nest_Flag flags, Scan_Direction scan, Nest_Delimiter_Kind delim, - i64 *out){ - Range_i64 range = {}; - b32 result = find_nest_side(app, buffer, pos, flags, scan, delim, &range); - if (result){ - if (HasFlag(flags, FindNest_EndOfToken)){ - *out = range.end; +Find_Nest_Flag flags, Scan_Direction scan, Nest_Delimiter_Kind delim, + i64 *out){ +Range_i64 range = {}; + b32 result = find_nest_side(app, buffer, pos, flags, scan, delim, &range); +if (result){ + if (HasFlag(flags, FindNest_EndOfToken)){ + *out = range.end; + } + else{ + *out = range.start; + } } - else{ - *out = range.start; - } - } - return(result); -} - -function b32 -find_surrounding_nest(Application_Links *app, Buffer_ID buffer, i64 pos, - Find_Nest_Flag flags, Range_i64 *out){ - b32 result = false; - Range_i64 range = {}; - if (find_nest_side(app, buffer, pos - 1, flags|FindNest_Balanced, - Scan_Backward, NestDelim_Open, &range.start) && - find_nest_side(app, buffer, pos, flags|FindNest_Balanced|FindNest_EndOfToken, - Scan_Forward, NestDelim_Close, &range.end)){ - *out = range; - result = true; - } - return(result); -} - -function void -select_scope(Application_Links *app, View_ID view, Range_i64 range){ - view_set_cursor_and_preferred_x(app, view, seek_pos(range.first)); - view_set_mark(app, view, seek_pos(range.end)); + return(result); + } + + function b32 + find_surrounding_nest(Application_Links *app, Buffer_ID buffer, i64 pos, + Find_Nest_Flag flags, Range_i64 *out){ +b32 result = false; + Range_i64 range = {}; + if (find_nest_side(app, buffer, pos - 1, flags|FindNest_Balanced, +Scan_Backward, NestDelim_Open, &range.start) && + find_nest_side(app, buffer, pos, flags|FindNest_Balanced|FindNest_EndOfToken, + Scan_Forward, NestDelim_Close, &range.end)){ + *out = range; + result = true; + } + return(result); + } + + function void + select_scope(Application_Links *app, View_ID view, Range_i64 range){ + view_set_cursor_and_preferred_x(app, view, seek_pos(range.first)); + view_set_mark(app, view, seek_pos(range.end)); view_look_at_region(app, view, range.first, range.end); no_mark_snap_to_cursor(app, view); -} + } + + //////////////////////////////// -//////////////////////////////// - -function Line_Ending_Kind + function Line_Ending_Kind guess_line_ending_kind_from_buffer(Application_Links *app, Buffer_ID buffer){ - u64 size = buffer_get_size(app, buffer); - size = clamp_top(size, KB(8)); - Scratch_Block scratch(app); - String_Const_u8 string = push_buffer_range(app, scratch, buffer, Ii64(0, size)); - return(string_guess_line_ending_kind(string)); -} - -//////////////////////////////// - -function i32 -get_command_id(Custom_Command_Function *func){ - i32 result = -1; - for (i32 i = 0; i < ArrayCount(fcoder_metacmd_table); i += 1){ - if (func == fcoder_metacmd_table[i].proc){ - result = i; + u64 size = buffer_get_size(app, buffer); + size = clamp_top(size, KB(8)); + Scratch_Block scratch(app); + String_Const_u8 string = push_buffer_range(app, scratch, buffer, Ii64(0, size)); + return(string_guess_line_ending_kind(string)); + } + + //////////////////////////////// + + function i32 + get_command_id(Custom_Command_Function *func){ + i32 result = -1; + for (i32 i = 0; i < ArrayCount(fcoder_metacmd_table); i += 1){ + if (func == fcoder_metacmd_table[i].proc){ +result = i; break; - } + } + } + return(result); + } + + function Command_Metadata* + get_command_metadata(Custom_Command_Function *func){ +Command_Metadata *result = 0; + i32 id = get_command_id(func); + if (id >= 0){ + result = &fcoder_metacmd_table[id]; + } + return(result); + } + + //////////////////////////////// + + // TODO(allen): REWRITE THIS EXACTLY HOW YOU WANT IT --- start --- + + internal Child_Process_Set_Target_Flags + flags_system_command(Command_Line_Interface_Flag flags){ + Child_Process_Set_Target_Flags set_buffer_flags = 0; + if (!HasFlag(flags, CLI_OverlapWithConflict)){ + set_buffer_flags |= ChildProcessSet_FailIfBufferAlreadyAttachedToAProcess; } - return(result); +if (HasFlag(flags, CLI_CursorAtEnd)){ + set_buffer_flags |= ChildProcessSet_CursorAtEnd; } - -function Command_Metadata* -get_command_metadata(Custom_Command_Function *func){ - Command_Metadata *result = 0; - i32 id = get_command_id(func); - if (id >= 0){ - result = &fcoder_metacmd_table[id]; +return(set_buffer_flags); } - return(result); -} - -//////////////////////////////// - -// TODO(allen): REWRITE THIS EXACTLY HOW YOU WANT IT --- start --- - -internal Child_Process_Set_Target_Flags -flags_system_command(Command_Line_Interface_Flag flags){ - Child_Process_Set_Target_Flags set_buffer_flags = 0; - if (!HasFlag(flags, CLI_OverlapWithConflict)){ - set_buffer_flags |= ChildProcessSet_FailIfBufferAlreadyAttachedToAProcess; - } - if (HasFlag(flags, CLI_CursorAtEnd)){ - set_buffer_flags |= ChildProcessSet_CursorAtEnd; - } - return(set_buffer_flags); -} - -internal b32 -set_buffer_system_command(Application_Links *app, Child_Process_ID process, Buffer_ID buffer, Command_Line_Interface_Flag flags){ - b32 result = false; - Child_Process_Set_Target_Flags set_buffer_flags = flags_system_command(flags); - if (child_process_set_target_buffer(app, process, buffer, set_buffer_flags)){ - clear_buffer(app, buffer); + + internal b32 + set_buffer_system_command(Application_Links *app, Child_Process_ID process, Buffer_ID buffer, Command_Line_Interface_Flag flags){ + b32 result = false; +Child_Process_Set_Target_Flags set_buffer_flags = flags_system_command(flags); + if (child_process_set_target_buffer(app, process, buffer, set_buffer_flags)){ + clear_buffer(app, buffer); if (HasFlag(flags, CLI_SendEndSignal)){ - buffer_send_end_signal(app, buffer); - } - result = true; - } - return(result); + buffer_send_end_signal(app, buffer); + } +result = true; +} +return(result); } internal b32 exec_system_command(Application_Links *app, View_ID view, Buffer_Identifier buffer_id, - String_Const_u8 path, String_Const_u8 command, Command_Line_Interface_Flag flags){ + String_Const_u8 path, String_Const_u8 command, Command_Line_Interface_Flag flags){ b32 result = false; - Child_Process_ID child_process_id = create_child_process(app, path, command); - if (child_process_id != 0){ - result = true; - Buffer_ID buffer_attach_id = buffer_identifier_to_id_create_out_buffer(app, buffer_id); - if (buffer_attach_id != 0){ - if (set_buffer_system_command(app, child_process_id, buffer_attach_id, flags)){ - if (view != 0){ - view_set_buffer(app, view, buffer_attach_id, 0); - view_set_cursor(app, view, seek_pos(0)); - } - } - } - } - return(result); -} +Child_Process_ID child_process_id = create_child_process(app, path, command); + if (child_process_id != 0){ +result = true; +Buffer_ID buffer_attach_id = buffer_identifier_to_id_create_out_buffer(app, buffer_id); + if (buffer_attach_id != 0){ + if (set_buffer_system_command(app, child_process_id, buffer_attach_id, flags)){ + if (view != 0){ + view_set_buffer(app, view, buffer_attach_id, 0); + view_set_cursor(app, view, seek_pos(0)); + } + } + } + } + return(result); + } -// TODO(allen): --- end --- + // TODO(allen): --- end --- // BOTTOM diff --git a/custom/generated/command_metadata.h b/custom/generated/command_metadata.h index 41eb07a9..768aefd6 100644 --- a/custom/generated/command_metadata.h +++ b/custom/generated/command_metadata.h @@ -261,12 +261,12 @@ i32 line_number; }; static Command_Metadata fcoder_metacmd_table[238] = { { PROC_LINKS(allow_mouse, 0), false, "allow_mouse", 11, "Shows the mouse and causes all mouse input to be processed normally.", 68, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 409 }, -{ PROC_LINKS(auto_indent_line_at_cursor, 0), false, "auto_indent_line_at_cursor", 26, "Auto-indents the line on which the cursor sits.", 47, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 407 }, -{ PROC_LINKS(auto_indent_range, 0), false, "auto_indent_range", 17, "Auto-indents the range between the cursor and the mark.", 55, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 417 }, -{ PROC_LINKS(auto_indent_whole_file, 0), false, "auto_indent_whole_file", 22, "Audo-indents the entire current buffer.", 39, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 398 }, +{ PROC_LINKS(auto_indent_line_at_cursor, 0), false, "auto_indent_line_at_cursor", 26, "Auto-indents the line on which the cursor sits.", 47, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 413 }, +{ PROC_LINKS(auto_indent_range, 0), false, "auto_indent_range", 17, "Auto-indents the range between the cursor and the mark.", 55, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 423 }, +{ PROC_LINKS(auto_indent_whole_file, 0), false, "auto_indent_whole_file", 22, "Audo-indents the entire current buffer.", 39, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 404 }, { PROC_LINKS(backspace_alpha_numeric_boundary, 0), false, "backspace_alpha_numeric_boundary", 32, "Delete characters between the cursor position and the first alphanumeric boundary to the left.", 94, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 165 }, { PROC_LINKS(backspace_char, 0), false, "backspace_char", 14, "Deletes the character to the left of the cursor.", 48, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 96 }, -{ PROC_LINKS(basic_change_active_panel, 0), false, "basic_change_active_panel", 25, "Change the currently active panel, moving to the panel with the next highest view_id. Will not skipe the build panel if it is open.", 132, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 656 }, +{ PROC_LINKS(basic_change_active_panel, 0), false, "basic_change_active_panel", 25, "Change the currently active panel, moving to the panel with the next highest view_id. Will not skipe the build panel if it is open.", 132, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 658 }, { PROC_LINKS(begin_clipboard_collection_mode, 0), true, "begin_clipboard_collection_mode", 31, "Allows the user to copy multiple strings from other applications before switching to 4coder and pasting them all.", 113, "w:\\4ed\\code\\custom\\4coder_clipboard.cpp", 39, 172 }, { PROC_LINKS(build_in_build_panel, 0), false, "build_in_build_panel", 20, "Looks for a build.bat, build.sh, or makefile in the current and parent directories. Runs the first that it finds and prints the output to *compilation*. Puts the *compilation* buffer in a panel at the footer of the current view.", 230, "w:\\4ed\\code\\custom\\4coder_build_commands.cpp", 44, 159 }, { PROC_LINKS(build_search, 0), false, "build_search", 12, "Looks for a build.bat, build.sh, or makefile in the current and parent directories. Runs the first that it finds and prints the output to *compilation*.", 153, "w:\\4ed\\code\\custom\\4coder_build_commands.cpp", 44, 122 }, @@ -274,7 +274,7 @@ static Command_Metadata fcoder_metacmd_table[238] = { { PROC_LINKS(change_active_panel, 0), false, "change_active_panel", 19, "Change the currently active panel, moving to the panel with the next highest view_id.", 85, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 284 }, { PROC_LINKS(change_active_panel_backwards, 0), false, "change_active_panel_backwards", 29, "Change the currently active panel, moving to the panel with the next lowest view_id.", 84, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 290 }, { PROC_LINKS(change_to_build_panel, 0), false, "change_to_build_panel", 21, "If the special build panel is open, makes the build panel the active panel.", 75, "w:\\4ed\\code\\custom\\4coder_build_commands.cpp", 44, 180 }, -{ PROC_LINKS(clean_all_lines, 0), false, "clean_all_lines", 15, "Removes trailing whitespace from all lines in the current buffer.", 65, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 645 }, +{ PROC_LINKS(clean_all_lines, 0), false, "clean_all_lines", 15, "Removes trailing whitespace from all lines in the current buffer.", 65, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 647 }, { PROC_LINKS(clear_all_themes, 0), false, "clear_all_themes", 16, "Clear the theme list", 20, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 480 }, { PROC_LINKS(clear_clipboard, 0), false, "clear_clipboard", 15, "Clears the history of the clipboard", 35, "w:\\4ed\\code\\custom\\4coder_clipboard.cpp", 39, 320 }, { PROC_LINKS(click_set_cursor, 0), false, "click_set_cursor", 16, "Sets the cursor position to the mouse position.", 47, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 244 }, @@ -284,7 +284,7 @@ static Command_Metadata fcoder_metacmd_table[238] = { { PROC_LINKS(clipboard_record_clip, 0), false, "clipboard_record_clip", 21, "In response to a new clipboard contents events, saves the new clip onto the clipboard history", 93, "w:\\4ed\\code\\custom\\4coder_clipboard.cpp", 39, 111 }, { PROC_LINKS(close_all_code, 0), false, "close_all_code", 14, "Closes any buffer with a filename ending with an extension configured to be recognized as a code file type.", 107, "w:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 843 }, { PROC_LINKS(close_build_panel, 0), false, "close_build_panel", 17, "If the special build panel is open, closes it.", 46, "w:\\4ed\\code\\custom\\4coder_build_commands.cpp", 44, 174 }, -{ PROC_LINKS(close_panel, 0), false, "close_panel", 11, "Closes the currently active panel if it is not the only panel open.", 67, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 664 }, +{ PROC_LINKS(close_panel, 0), false, "close_panel", 11, "Closes the currently active panel if it is not the only panel open.", 67, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 666 }, { PROC_LINKS(command_documentation, 0), true, "command_documentation", 21, "Prompts the user to select a command then loads a doc buffer for that item", 74, "w:\\4ed\\code\\custom\\4coder_docs.cpp", 34, 190 }, { PROC_LINKS(command_lister, 0), true, "command_lister", 14, "Opens an interactive list of all registered commands.", 53, "w:\\4ed\\code\\custom\\4coder_lists.cpp", 35, 761 }, { PROC_LINKS(comment_line, 0), false, "comment_line", 12, "Insert '//' at the beginning of the line after leading whitespace.", 66, "w:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 125 }, @@ -293,39 +293,39 @@ static Command_Metadata fcoder_metacmd_table[238] = { { PROC_LINKS(cursor_mark_swap, 0), false, "cursor_mark_swap", 16, "Swaps the position of the cursor and the mark.", 46, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 135 }, { PROC_LINKS(custom_api_documentation, 0), true, "custom_api_documentation", 24, "Prompts the user to select a Custom API item then loads a doc buffer for that item", 82, "w:\\4ed\\code\\custom\\4coder_docs.cpp", 34, 175 }, { PROC_LINKS(cut, 0), false, "cut", 3, "Cut the text in the range from the cursor to the mark onto the clipboard.", 73, "w:\\4ed\\code\\custom\\4coder_clipboard.cpp", 39, 220 }, -{ PROC_LINKS(decrease_face_size, 0), false, "decrease_face_size", 18, "Decrease the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 747 }, -{ PROC_LINKS(default_file_externally_modified, 0), false, "default_file_externally_modified", 32, "Notes the external modification of attached files by printing a message.", 72, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1889 }, +{ PROC_LINKS(decrease_face_size, 0), false, "decrease_face_size", 18, "Decrease the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 749 }, +{ PROC_LINKS(default_file_externally_modified, 0), false, "default_file_externally_modified", 32, "Notes the external modification of attached files by printing a message.", 72, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1891 }, { PROC_LINKS(default_startup, 0), false, "default_startup", 15, "Default command for responding to a startup event", 49, "w:\\4ed\\code\\custom\\4coder_default_hooks.cpp", 43, 7 }, { PROC_LINKS(default_try_exit, 0), false, "default_try_exit", 16, "Default command for responding to a try-exit event", 50, "w:\\4ed\\code\\custom\\4coder_default_hooks.cpp", 43, 23 }, { PROC_LINKS(default_view_input_handler, 0), false, "default_view_input_handler", 26, "Input consumption loop for default view behavior", 48, "w:\\4ed\\code\\custom\\4coder_default_hooks.cpp", 43, 51 }, { PROC_LINKS(delete_alpha_numeric_boundary, 0), false, "delete_alpha_numeric_boundary", 29, "Delete characters between the cursor position and the first alphanumeric boundary to the right.", 95, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 173 }, { PROC_LINKS(delete_char, 0), false, "delete_char", 11, "Deletes the character to the right of the cursor.", 49, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 79 }, { PROC_LINKS(delete_current_scope, 0), false, "delete_current_scope", 20, "Deletes the braces surrounding the currently selected scope. Leaves the contents within the scope.", 99, "w:\\4ed\\code\\custom\\4coder_scope_commands.cpp", 44, 112 }, -{ PROC_LINKS(delete_file_query, 0), false, "delete_file_query", 17, "Deletes the file of the current buffer if 4coder has the appropriate access rights. Will ask the user for confirmation first.", 125, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1315 }, -{ PROC_LINKS(delete_line, 0), false, "delete_line", 11, "Delete the line the on which the cursor sits.", 45, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1487 }, +{ PROC_LINKS(delete_file_query, 0), false, "delete_file_query", 17, "Deletes the file of the current buffer if 4coder has the appropriate access rights. Will ask the user for confirmation first.", 125, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1317 }, +{ PROC_LINKS(delete_line, 0), false, "delete_line", 11, "Delete the line the on which the cursor sits.", 45, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1489 }, { PROC_LINKS(delete_range, 0), false, "delete_range", 12, "Deletes the text in the range between the cursor and the mark.", 62, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 145 }, -{ PROC_LINKS(duplicate_line, 0), false, "duplicate_line", 14, "Create a copy of the line on which the cursor sits.", 51, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1473 }, +{ PROC_LINKS(duplicate_line, 0), false, "duplicate_line", 14, "Create a copy of the line on which the cursor sits.", 51, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1475 }, { PROC_LINKS(execute_any_cli, 0), false, "execute_any_cli", 15, "Queries for an output buffer name and system command, runs the system command as a CLI and prints the output to the specified buffer.", 133, "w:\\4ed\\code\\custom\\4coder_cli_command.cpp", 41, 22 }, { PROC_LINKS(execute_previous_cli, 0), false, "execute_previous_cli", 20, "If the command execute_any_cli has already been used, this will execute a CLI reusing the most recent buffer name and command.", 126, "w:\\4ed\\code\\custom\\4coder_cli_command.cpp", 41, 7 }, -{ PROC_LINKS(exit_4coder, 0), false, "exit_4coder", 11, "Attempts to close 4coder.", 25, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 834 }, -{ PROC_LINKS(goto_beginning_of_file, 0), false, "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2198 }, -{ PROC_LINKS(goto_end_of_file, 0), false, "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2206 }, +{ PROC_LINKS(exit_4coder, 0), false, "exit_4coder", 11, "Attempts to close 4coder.", 25, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 836 }, +{ PROC_LINKS(goto_beginning_of_file, 0), false, "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2201 }, +{ PROC_LINKS(goto_end_of_file, 0), false, "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2209 }, { PROC_LINKS(goto_first_jump, 0), false, "goto_first_jump", 15, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "w:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 525 }, { PROC_LINKS(goto_first_jump_same_panel_sticky, 0), false, "goto_first_jump_same_panel_sticky", 33, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer and views the buffer in the panel where the jump list was.", 153, "w:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 542 }, { PROC_LINKS(goto_jump_at_cursor, 0), false, "goto_jump_at_cursor", 19, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.", 187, "w:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 348 }, { PROC_LINKS(goto_jump_at_cursor_same_panel, 0), false, "goto_jump_at_cursor_same_panel", 30, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list.", 167, "w:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 375 }, -{ PROC_LINKS(goto_line, 0), false, "goto_line", 9, "Queries the user for a number, and jumps the cursor to the corresponding line.", 78, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 842 }, +{ PROC_LINKS(goto_line, 0), false, "goto_line", 9, "Queries the user for a number, and jumps the cursor to the corresponding line.", 78, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 844 }, { PROC_LINKS(goto_next_jump, 0), false, "goto_next_jump", 14, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.", 123, "w:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 464 }, { PROC_LINKS(goto_next_jump_no_skips, 0), false, "goto_next_jump_no_skips", 23, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, and does not skip sub jump locations.", 132, "w:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 494 }, { PROC_LINKS(goto_prev_jump, 0), false, "goto_prev_jump", 14, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations.", 127, "w:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 481 }, { PROC_LINKS(goto_prev_jump_no_skips, 0), false, "goto_prev_jump_no_skips", 23, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.", 136, "w:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 511 }, -{ PROC_LINKS(hide_filebar, 0), false, "hide_filebar", 12, "Sets the current view to hide it's filebar.", 43, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 694 }, -{ PROC_LINKS(hide_scrollbar, 0), false, "hide_scrollbar", 14, "Sets the current view to hide it's scrollbar.", 45, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 680 }, +{ PROC_LINKS(hide_filebar, 0), false, "hide_filebar", 12, "Sets the current view to hide it's filebar.", 43, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 696 }, +{ PROC_LINKS(hide_scrollbar, 0), false, "hide_scrollbar", 14, "Sets the current view to hide it's scrollbar.", 45, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 682 }, { PROC_LINKS(hms_demo_tutorial, 0), false, "hms_demo_tutorial", 17, "Tutorial for built in 4coder bindings and features.", 51, "w:\\4ed\\code\\custom\\4coder_tutorial.cpp", 38, 869 }, { PROC_LINKS(if0_off, 0), false, "if0_off", 7, "Surround the range between the cursor and mark with an '#if 0' and an '#endif'", 78, "w:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 70 }, { PROC_LINKS(if_read_only_goto_position, 0), false, "if_read_only_goto_position", 26, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "w:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 564 }, { PROC_LINKS(if_read_only_goto_position_same_panel, 0), false, "if_read_only_goto_position_same_panel", 37, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "w:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 581 }, -{ PROC_LINKS(increase_face_size, 0), false, "increase_face_size", 18, "Increase the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 736 }, +{ PROC_LINKS(increase_face_size, 0), false, "increase_face_size", 18, "Increase the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 738 }, { PROC_LINKS(interactive_kill_buffer, 0), true, "interactive_kill_buffer", 23, "Interactively kill an open buffer.", 34, "w:\\4ed\\code\\custom\\4coder_lists.cpp", 35, 520 }, { PROC_LINKS(interactive_new, 0), true, "interactive_new", 15, "Interactively creates a new file.", 33, "w:\\4ed\\code\\custom\\4coder_lists.cpp", 35, 661 }, { PROC_LINKS(interactive_open, 0), true, "interactive_open", 16, "Interactively opens a file.", 27, "w:\\4ed\\code\\custom\\4coder_lists.cpp", 35, 715 }, @@ -335,7 +335,7 @@ static Command_Metadata fcoder_metacmd_table[238] = { { PROC_LINKS(keyboard_macro_finish_recording, 0), false, "keyboard_macro_finish_recording", 31, "Stop macro recording, do nothing if macro recording is not already started", 74, "w:\\4ed\\code\\custom\\4coder_keyboard_macro.cpp", 44, 54 }, { PROC_LINKS(keyboard_macro_replay, 0), false, "keyboard_macro_replay", 21, "Replay the most recently recorded keyboard macro", 48, "w:\\4ed\\code\\custom\\4coder_keyboard_macro.cpp", 44, 77 }, { PROC_LINKS(keyboard_macro_start_recording, 0), false, "keyboard_macro_start_recording", 30, "Start macro recording, do nothing if macro recording is already started", 71, "w:\\4ed\\code\\custom\\4coder_keyboard_macro.cpp", 44, 41 }, -{ PROC_LINKS(kill_buffer, 0), false, "kill_buffer", 11, "Kills the current buffer.", 25, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1633 }, +{ PROC_LINKS(kill_buffer, 0), false, "kill_buffer", 11, "Kills the current buffer.", 25, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1635 }, { PROC_LINKS(kill_tutorial, 0), false, "kill_tutorial", 13, "If there is an active tutorial, kill it.", 40, "w:\\4ed\\code\\custom\\4coder_tutorial.cpp", 38, 9 }, { PROC_LINKS(left_adjust_view, 0), false, "left_adjust_view", 16, "Sets the left size of the view near the x position of the cursor.", 65, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 222 }, { PROC_LINKS(list_all_functions_all_buffers, 0), false, "list_all_functions_all_buffers", 30, "Creates a jump list of lines from all buffers that appear to define or declare functions.", 89, "w:\\4ed\\code\\custom\\4coder_function_list.cpp", 43, 295 }, @@ -356,14 +356,14 @@ static Command_Metadata fcoder_metacmd_table[238] = { { 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_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, 1427 }, +{ 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, 1429 }, { PROC_LINKS(miblo_decrement_basic, 0), false, "miblo_decrement_basic", 21, "Decrement an integer under the cursor by one.", 45, "w:\\4ed\\code\\custom\\4coder_miblo_numbers.cpp", 43, 44 }, { PROC_LINKS(miblo_decrement_time_stamp, 0), false, "miblo_decrement_time_stamp", 26, "Decrement a time stamp under the cursor by one second. (format [m]m:ss or h:mm:ss", 81, "w:\\4ed\\code\\custom\\4coder_miblo_numbers.cpp", 43, 237 }, { PROC_LINKS(miblo_decrement_time_stamp_minute, 0), false, "miblo_decrement_time_stamp_minute", 33, "Decrement a time stamp under the cursor by one minute. (format [m]m:ss or h:mm:ss", 81, "w:\\4ed\\code\\custom\\4coder_miblo_numbers.cpp", 43, 249 }, { PROC_LINKS(miblo_increment_basic, 0), false, "miblo_increment_basic", 21, "Increment an integer under the cursor by one.", 45, "w:\\4ed\\code\\custom\\4coder_miblo_numbers.cpp", 43, 29 }, { PROC_LINKS(miblo_increment_time_stamp, 0), false, "miblo_increment_time_stamp", 26, "Increment a time stamp under the cursor by one second. (format [m]m:ss or h:mm:ss", 81, "w:\\4ed\\code\\custom\\4coder_miblo_numbers.cpp", 43, 231 }, { PROC_LINKS(miblo_increment_time_stamp_minute, 0), false, "miblo_increment_time_stamp_minute", 33, "Increment a time stamp under the cursor by one minute. (format [m]m:ss or h:mm:ss", 81, "w:\\4ed\\code\\custom\\4coder_miblo_numbers.cpp", 43, 243 }, -{ PROC_LINKS(mouse_wheel_change_face_size, 0), false, "mouse_wheel_change_face_size", 28, "Reads the state of the mouse wheel and uses it to either increase or decrease the face size.", 92, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 789 }, +{ PROC_LINKS(mouse_wheel_change_face_size, 0), false, "mouse_wheel_change_face_size", 28, "Reads the state of the mouse wheel and uses it to either increase or decrease the face size.", 92, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 791 }, { PROC_LINKS(mouse_wheel_scroll, 0), false, "mouse_wheel_scroll", 18, "Reads the scroll wheel value from the mouse state and scrolls accordingly.", 74, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 276 }, { PROC_LINKS(move_down, 0), false, "move_down", 9, "Moves the cursor down one line.", 31, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 347 }, { PROC_LINKS(move_down_10, 0), false, "move_down_10", 12, "Moves the cursor down ten lines.", 32, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 359 }, @@ -377,8 +377,8 @@ static Command_Metadata fcoder_metacmd_table[238] = { { PROC_LINKS(move_left_token_boundary, 0), false, "move_left_token_boundary", 24, "Seek left for the next beginning of a token.", 44, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 497 }, { PROC_LINKS(move_left_whitespace_boundary, 0), false, "move_left_whitespace_boundary", 29, "Seek left for the next boundary between whitespace and non-whitespace.", 70, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 482 }, { PROC_LINKS(move_left_whitespace_or_token_boundary, 0), false, "move_left_whitespace_or_token_boundary", 38, "Seek left for the next end of a token or boundary between whitespace and non-whitespace.", 88, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 511 }, -{ PROC_LINKS(move_line_down, 0), false, "move_line_down", 14, "Swaps the line under the cursor with the line below it, and moves the cursor down with it.", 90, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1467 }, -{ PROC_LINKS(move_line_up, 0), false, "move_line_up", 12, "Swaps the line under the cursor with the line above it, and moves the cursor up with it.", 88, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1461 }, +{ PROC_LINKS(move_line_down, 0), false, "move_line_down", 14, "Swaps the line under the cursor with the line below it, and moves the cursor down with it.", 90, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1469 }, +{ PROC_LINKS(move_line_up, 0), false, "move_line_up", 12, "Swaps the line under the cursor with the line above it, and moves the cursor up with it.", 88, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1463 }, { PROC_LINKS(move_right, 0), false, "move_right", 10, "Moves the cursor one character to the right.", 44, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 456 }, { PROC_LINKS(move_right_alpha_numeric_boundary, 0), false, "move_right_alpha_numeric_boundary", 33, "Seek right for boundary between alphanumeric characters and non-alphanumeric characters.", 88, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 518 }, { PROC_LINKS(move_right_alpha_numeric_or_camel_boundary, 0), false, "move_right_alpha_numeric_or_camel_boundary", 42, "Seek right for boundary between alphanumeric characters or camel case word and non-alphanumeric characters.", 107, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 532 }, @@ -394,12 +394,12 @@ static Command_Metadata fcoder_metacmd_table[238] = { { PROC_LINKS(multi_paste_interactive_quick, 0), false, "multi_paste_interactive_quick", 29, "Paste multiple lines from the clipboard history, controlled by inputing the number of lines to paste", 100, "w:\\4ed\\code\\custom\\4coder_clipboard.cpp", 39, 477 }, { PROC_LINKS(open_all_code, 0), false, "open_all_code", 13, "Open all code in the current directory. File types are determined by extensions. An extension is considered code based on the extensions specified in 4coder.config.", 164, "w:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 849 }, { PROC_LINKS(open_all_code_recursive, 0), false, "open_all_code_recursive", 23, "Works as open_all_code but also runs in all subdirectories.", 59, "w:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 855 }, -{ PROC_LINKS(open_file_in_quotes, 0), false, "open_file_in_quotes", 19, "Reads a filename from surrounding '\"' characters and attempts to open the corresponding file.", 94, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1552 }, -{ PROC_LINKS(open_in_other, 0), false, "open_in_other", 13, "Interactively opens a file in the other panel.", 46, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1883 }, +{ PROC_LINKS(open_file_in_quotes, 0), false, "open_file_in_quotes", 19, "Reads a filename from surrounding '\"' characters and attempts to open the corresponding file.", 94, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1554 }, +{ PROC_LINKS(open_in_other, 0), false, "open_in_other", 13, "Interactively opens a file in the other panel.", 46, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1885 }, { PROC_LINKS(open_long_braces, 0), false, "open_long_braces", 16, "At the cursor, insert a '{' and '}' separated by a blank line.", 62, "w:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 46 }, { PROC_LINKS(open_long_braces_break, 0), false, "open_long_braces_break", 22, "At the cursor, insert a '{' and '}break;' separated by a blank line.", 68, "w:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 62 }, { PROC_LINKS(open_long_braces_semicolon, 0), false, "open_long_braces_semicolon", 26, "At the cursor, insert a '{' and '};' separated by a blank line.", 63, "w:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 54 }, -{ PROC_LINKS(open_matching_file_cpp, 0), false, "open_matching_file_cpp", 22, "If the current file is a *.cpp or *.h, attempts to open the corresponding *.h or *.cpp file in the other view.", 110, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1584 }, +{ PROC_LINKS(open_matching_file_cpp, 0), false, "open_matching_file_cpp", 22, "If the current file is a *.cpp or *.h, attempts to open the corresponding *.h or *.cpp file in the other view.", 110, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1586 }, { PROC_LINKS(open_panel_hsplit, 0), false, "open_panel_hsplit", 17, "Create a new panel by horizontally splitting the active panel.", 62, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 310 }, { PROC_LINKS(open_panel_vsplit, 0), false, "open_panel_vsplit", 17, "Create a new panel by vertically splitting the active panel.", 60, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 300 }, { PROC_LINKS(page_down, 0), false, "page_down", 9, "Scrolls the view down one view height and moves the cursor down one view height.", 80, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 383 }, @@ -416,27 +416,27 @@ static Command_Metadata fcoder_metacmd_table[238] = { { PROC_LINKS(project_command_lister, 0), false, "project_command_lister", 22, "Open a lister of all commands in the currently loaded project.", 62, "w:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 1290 }, { PROC_LINKS(project_fkey_command, 0), false, "project_fkey_command", 20, "Run an 'fkey command' configured in a project.4coder file. Determines the index of the 'fkey command' by which function key or numeric key was pressed to trigger the command.", 175, "w:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 871 }, { PROC_LINKS(project_go_to_root_directory, 0), false, "project_go_to_root_directory", 28, "Changes 4coder's hot directory to the root directory of the currently loaded project. With no loaded project nothing hapepns.", 125, "w:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 897 }, -{ PROC_LINKS(query_replace, 0), false, "query_replace", 13, "Queries the user for two strings, and incrementally replaces every occurence of the first string with the second string.", 120, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1243 }, -{ PROC_LINKS(query_replace_identifier, 0), false, "query_replace_identifier", 24, "Queries the user for a string, and incrementally replace every occurence of the word or token found at the cursor with the specified string.", 140, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1264 }, -{ PROC_LINKS(query_replace_selection, 0), false, "query_replace_selection", 23, "Queries the user for a string, and incrementally replace every occurence of the string found in the selected range with the specified string.", 141, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1280 }, -{ PROC_LINKS(redo, 0), false, "redo", 4, "Advances forwards through the undo history of the current buffer.", 65, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1722 }, -{ PROC_LINKS(redo_all_buffers, 0), false, "redo_all_buffers", 16, "Advances forward through the undo history in the buffer containing the most recent regular edit.", 96, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1807 }, -{ PROC_LINKS(rename_file_query, 0), false, "rename_file_query", 17, "Queries the user for a new name and renames the file of the current buffer, altering the buffer's name too.", 107, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1392 }, -{ PROC_LINKS(reopen, 0), false, "reopen", 6, "Reopen the current buffer from the hard drive.", 46, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1651 }, -{ PROC_LINKS(replace_in_all_buffers, 0), false, "replace_in_all_buffers", 22, "Queries the user for a needle and string. Replaces all occurences of needle with string in all editable buffers.", 112, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1153 }, -{ PROC_LINKS(replace_in_buffer, 0), false, "replace_in_buffer", 17, "Queries the user for a needle and string. Replaces all occurences of needle with string in the active buffer.", 109, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1144 }, -{ PROC_LINKS(replace_in_range, 0), false, "replace_in_range", 16, "Queries the user for a needle and string. Replaces all occurences of needle with string in the range between cursor and the mark in the active buffer.", 150, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1135 }, -{ PROC_LINKS(reverse_search, 0), false, "reverse_search", 14, "Begins an incremental search up through the current buffer for a user specified string.", 87, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1076 }, -{ PROC_LINKS(reverse_search_identifier, 0), false, "reverse_search_identifier", 25, "Begins an incremental search up through the current buffer for the word or token under the cursor.", 98, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1088 }, -{ PROC_LINKS(save, 0), false, "save", 4, "Saves the current buffer.", 25, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1641 }, +{ PROC_LINKS(query_replace, 0), false, "query_replace", 13, "Queries the user for two strings, and incrementally replaces every occurence of the first string with the second string.", 120, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1245 }, +{ PROC_LINKS(query_replace_identifier, 0), false, "query_replace_identifier", 24, "Queries the user for a string, and incrementally replace every occurence of the word or token found at the cursor with the specified string.", 140, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1266 }, +{ PROC_LINKS(query_replace_selection, 0), false, "query_replace_selection", 23, "Queries the user for a string, and incrementally replace every occurence of the string found in the selected range with the specified string.", 141, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1282 }, +{ PROC_LINKS(redo, 0), false, "redo", 4, "Advances forwards through the undo history of the current buffer.", 65, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1724 }, +{ PROC_LINKS(redo_all_buffers, 0), false, "redo_all_buffers", 16, "Advances forward through the undo history in the buffer containing the most recent regular edit.", 96, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1809 }, +{ PROC_LINKS(rename_file_query, 0), false, "rename_file_query", 17, "Queries the user for a new name and renames the file of the current buffer, altering the buffer's name too.", 107, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1394 }, +{ PROC_LINKS(reopen, 0), false, "reopen", 6, "Reopen the current buffer from the hard drive.", 46, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1653 }, +{ PROC_LINKS(replace_in_all_buffers, 0), false, "replace_in_all_buffers", 22, "Queries the user for a needle and string. Replaces all occurences of needle with string in all editable buffers.", 112, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1155 }, +{ PROC_LINKS(replace_in_buffer, 0), false, "replace_in_buffer", 17, "Queries the user for a needle and string. Replaces all occurences of needle with string in the active buffer.", 109, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1146 }, +{ PROC_LINKS(replace_in_range, 0), false, "replace_in_range", 16, "Queries the user for a needle and string. Replaces all occurences of needle with string in the range between cursor and the mark in the active buffer.", 150, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1137 }, +{ PROC_LINKS(reverse_search, 0), false, "reverse_search", 14, "Begins an incremental search up through the current buffer for a user specified string.", 87, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1078 }, +{ PROC_LINKS(reverse_search_identifier, 0), false, "reverse_search_identifier", 25, "Begins an incremental search up through the current buffer for the word or token under the cursor.", 98, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1090 }, +{ PROC_LINKS(save, 0), false, "save", 4, "Saves the current buffer.", 25, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1643 }, { PROC_LINKS(save_all_dirty_buffers, 0), false, "save_all_dirty_buffers", 22, "Saves all buffers marked dirty (showing the '*' indicator).", 59, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 382 }, -{ PROC_LINKS(save_to_query, 0), false, "save_to_query", 13, "Queries the user for a file name and saves the contents of the current buffer, altering the buffer's name too.", 110, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1359 }, -{ PROC_LINKS(search, 0), false, "search", 6, "Begins an incremental search down through the current buffer for a user specified string.", 89, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1070 }, -{ PROC_LINKS(search_identifier, 0), false, "search_identifier", 17, "Begins an incremental search down through the current buffer for the word or token under the cursor.", 100, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1082 }, -{ PROC_LINKS(seek_beginning_of_line, 0), false, "seek_beginning_of_line", 22, "Seeks the cursor to the beginning of the visual line.", 53, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2186 }, -{ PROC_LINKS(seek_beginning_of_textual_line, 0), false, "seek_beginning_of_textual_line", 30, "Seeks the cursor to the beginning of the line across all text.", 62, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2174 }, -{ PROC_LINKS(seek_end_of_line, 0), false, "seek_end_of_line", 16, "Seeks the cursor to the end of the visual line.", 47, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2192 }, -{ PROC_LINKS(seek_end_of_textual_line, 0), false, "seek_end_of_textual_line", 24, "Seeks the cursor to the end of the line across all text.", 56, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2180 }, +{ PROC_LINKS(save_to_query, 0), false, "save_to_query", 13, "Queries the user for a file name and saves the contents of the current buffer, altering the buffer's name too.", 110, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1361 }, +{ PROC_LINKS(search, 0), false, "search", 6, "Begins an incremental search down through the current buffer for a user specified string.", 89, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1072 }, +{ PROC_LINKS(search_identifier, 0), false, "search_identifier", 17, "Begins an incremental search down through the current buffer for the word or token under the cursor.", 100, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1084 }, +{ PROC_LINKS(seek_beginning_of_line, 0), false, "seek_beginning_of_line", 22, "Seeks the cursor to the beginning of the visual line.", 53, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2189 }, +{ PROC_LINKS(seek_beginning_of_textual_line, 0), false, "seek_beginning_of_textual_line", 30, "Seeks the cursor to the beginning of the line across all text.", 62, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2177 }, +{ PROC_LINKS(seek_end_of_line, 0), false, "seek_end_of_line", 16, "Seeks the cursor to the end of the visual line.", 47, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2195 }, +{ PROC_LINKS(seek_end_of_textual_line, 0), false, "seek_end_of_textual_line", 24, "Seeks the cursor to the end of the line across all text.", 56, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2183 }, { PROC_LINKS(select_all, 0), false, "select_all", 10, "Puts the cursor at the top of the file, and the mark at the bottom of the file.", 79, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 548 }, { PROC_LINKS(select_next_scope_absolute, 0), false, "select_next_scope_absolute", 26, "Finds the first scope started by '{' after the cursor and puts the cursor and mark on the '{' and '}'.", 102, "w:\\4ed\\code\\custom\\4coder_scope_commands.cpp", 44, 57 }, { PROC_LINKS(select_next_scope_after_current, 0), false, "select_next_scope_after_current", 31, "If a scope is selected, find first scope that starts after the selected scope. Otherwise find the first scope that starts after the cursor.", 139, "w:\\4ed\\code\\custom\\4coder_scope_commands.cpp", 44, 66 }, @@ -448,8 +448,8 @@ static Command_Metadata fcoder_metacmd_table[238] = { { PROC_LINKS(set_eol_mode_to_binary, 0), false, "set_eol_mode_to_binary", 22, "Puts the buffer in bin line ending mode.", 40, "w:\\4ed\\code\\custom\\4coder_eol.cpp", 33, 112 }, { PROC_LINKS(set_eol_mode_to_crlf, 0), false, "set_eol_mode_to_crlf", 20, "Puts the buffer in crlf line ending mode.", 41, "w:\\4ed\\code\\custom\\4coder_eol.cpp", 33, 86 }, { PROC_LINKS(set_eol_mode_to_lf, 0), false, "set_eol_mode_to_lf", 18, "Puts the buffer in lf line ending mode.", 39, "w:\\4ed\\code\\custom\\4coder_eol.cpp", 33, 99 }, -{ PROC_LINKS(set_face_size, 0), false, "set_face_size", 13, "Set face size of the face used by the current buffer.", 53, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 716 }, -{ PROC_LINKS(set_face_size_this_buffer, 0), false, "set_face_size_this_buffer", 25, "Set face size of the face used by the current buffer; if any other buffers are using the same face a new face is created so that only this buffer is effected", 157, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 758 }, +{ PROC_LINKS(set_face_size, 0), false, "set_face_size", 13, "Set face size of the face used by the current buffer.", 53, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 718 }, +{ PROC_LINKS(set_face_size_this_buffer, 0), false, "set_face_size_this_buffer", 25, "Set face size of the face used by the current buffer; if any other buffers are using the same face a new face is created so that only this buffer is effected", 157, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 760 }, { PROC_LINKS(set_mark, 0), false, "set_mark", 8, "Sets the mark to the current position of the cursor.", 52, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 126 }, { PROC_LINKS(set_mode_to_notepad_like, 0), false, "set_mode_to_notepad_like", 24, "Sets the edit mode to Notepad like.", 35, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 427 }, { PROC_LINKS(set_mode_to_original, 0), false, "set_mode_to_original", 20, "Sets the edit mode to 4coder original.", 38, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 421 }, @@ -457,35 +457,35 @@ static Command_Metadata fcoder_metacmd_table[238] = { { PROC_LINKS(setup_build_bat_and_sh, 0), false, "setup_build_bat_and_sh", 22, "Queries the user for several configuration options and initializes a new build batch script.", 92, "w:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 1250 }, { PROC_LINKS(setup_build_sh, 0), false, "setup_build_sh", 14, "Queries the user for several configuration options and initializes a new build shell script.", 92, "w:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 1244 }, { PROC_LINKS(setup_new_project, 0), false, "setup_new_project", 17, "Queries the user for several configuration options and initializes a new 4coder project with build scripts for every OS.", 120, "w:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 1231 }, -{ PROC_LINKS(show_filebar, 0), false, "show_filebar", 12, "Sets the current view to show it's filebar.", 43, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 687 }, -{ PROC_LINKS(show_scrollbar, 0), false, "show_scrollbar", 14, "Sets the current view to show it's scrollbar.", 45, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 673 }, +{ PROC_LINKS(show_filebar, 0), false, "show_filebar", 12, "Sets the current view to show it's filebar.", 43, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 689 }, +{ PROC_LINKS(show_scrollbar, 0), false, "show_scrollbar", 14, "Sets the current view to show it's scrollbar.", 45, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 675 }, { PROC_LINKS(show_the_log_graph, 0), true, "show_the_log_graph", 18, "Parses *log* and displays the 'log graph' UI", 44, "w:\\4ed\\code\\custom\\4coder_log_parser.cpp", 40, 994 }, { PROC_LINKS(snipe_backward_whitespace_or_token_boundary, 0), false, "snipe_backward_whitespace_or_token_boundary", 43, "Delete a single, whole token on or to the left of the cursor and post it to the clipboard.", 90, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 190 }, { PROC_LINKS(snipe_forward_whitespace_or_token_boundary, 0), false, "snipe_forward_whitespace_or_token_boundary", 42, "Delete a single, whole token on or to the right of the cursor and post it to the clipboard.", 91, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 198 }, { PROC_LINKS(snippet_lister, 0), true, "snippet_lister", 14, "Opens a snippet lister for inserting whole pre-written snippets of text.", 72, "w:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 237 }, { PROC_LINKS(suppress_mouse, 0), false, "suppress_mouse", 14, "Hides the mouse and causes all mosue input (clicks, position, wheel) to be ignored.", 83, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 403 }, -{ PROC_LINKS(swap_panels, 0), false, "swap_panels", 11, "Swaps the active panel with it's sibling.", 41, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1609 }, +{ PROC_LINKS(swap_panels, 0), false, "swap_panels", 11, "Swaps the active panel with it's sibling.", 41, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1611 }, { PROC_LINKS(test_double_backspace, 0), false, "test_double_backspace", 21, "Made for testing purposes (I should have deleted this if you are reading it let me know)", 88, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 115 }, { PROC_LINKS(theme_lister, 0), true, "theme_lister", 12, "Opens an interactive list of all registered themes.", 51, "w:\\4ed\\code\\custom\\4coder_lists.cpp", 35, 785 }, { PROC_LINKS(to_lowercase, 0), false, "to_lowercase", 12, "Converts all ascii text in the range between the cursor and the mark to lowercase.", 82, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 574 }, { PROC_LINKS(to_uppercase, 0), false, "to_uppercase", 12, "Converts all ascii text in the range between the cursor and the mark to uppercase.", 82, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 561 }, -{ PROC_LINKS(toggle_filebar, 0), false, "toggle_filebar", 14, "Toggles the visibility status of the current view's filebar.", 60, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 701 }, -{ PROC_LINKS(toggle_fps_meter, 0), false, "toggle_fps_meter", 16, "Toggles the visibility of the FPS performance meter", 51, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 710 }, +{ PROC_LINKS(toggle_filebar, 0), false, "toggle_filebar", 14, "Toggles the visibility status of the current view's filebar.", 60, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 703 }, +{ PROC_LINKS(toggle_fps_meter, 0), false, "toggle_fps_meter", 16, "Toggles the visibility of the FPS performance meter", 51, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 712 }, { PROC_LINKS(toggle_fullscreen, 0), false, "toggle_fullscreen", 17, "Toggle fullscreen mode on or off. The change(s) do not take effect until the next frame.", 89, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 451 }, { PROC_LINKS(toggle_highlight_enclosing_scopes, 0), false, "toggle_highlight_enclosing_scopes", 33, "In code files scopes surrounding the cursor are highlighted with distinguishing colors.", 87, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 439 }, { PROC_LINKS(toggle_highlight_line_at_cursor, 0), false, "toggle_highlight_line_at_cursor", 31, "Toggles the line highlight at the cursor.", 41, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 433 }, -{ PROC_LINKS(toggle_line_numbers, 0), false, "toggle_line_numbers", 19, "Toggles the left margin line numbers.", 37, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 815 }, -{ PROC_LINKS(toggle_line_wrap, 0), false, "toggle_line_wrap", 16, "Toggles the line wrap setting on this buffer.", 45, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 821 }, +{ PROC_LINKS(toggle_line_numbers, 0), false, "toggle_line_numbers", 19, "Toggles the left margin line numbers.", 37, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 817 }, +{ PROC_LINKS(toggle_line_wrap, 0), false, "toggle_line_wrap", 16, "Toggles the line wrap setting on this buffer.", 45, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 823 }, { PROC_LINKS(toggle_mouse, 0), false, "toggle_mouse", 12, "Toggles the mouse suppression mode, see suppress_mouse and allow_mouse.", 71, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 415 }, { PROC_LINKS(toggle_paren_matching_helper, 0), false, "toggle_paren_matching_helper", 28, "In code files matching parentheses pairs are colored with distinguishing colors.", 80, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 445 }, -{ PROC_LINKS(toggle_show_whitespace, 0), false, "toggle_show_whitespace", 22, "Toggles the current buffer's whitespace visibility status.", 58, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 806 }, +{ PROC_LINKS(toggle_show_whitespace, 0), false, "toggle_show_whitespace", 22, "Toggles the current buffer's whitespace visibility status.", 58, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 808 }, { PROC_LINKS(toggle_virtual_whitespace, 0), false, "toggle_virtual_whitespace", 25, "Toggles virtual whitespace for all files.", 41, "w:\\4ed\\code\\custom\\4coder_code_index.cpp", 40, 1175 }, { PROC_LINKS(tutorial_maximize, 0), false, "tutorial_maximize", 17, "Expand the tutorial window", 26, "w:\\4ed\\code\\custom\\4coder_tutorial.cpp", 38, 20 }, { PROC_LINKS(tutorial_minimize, 0), false, "tutorial_minimize", 17, "Shrink the tutorial window", 26, "w:\\4ed\\code\\custom\\4coder_tutorial.cpp", 38, 34 }, { PROC_LINKS(uncomment_line, 0), false, "uncomment_line", 14, "If present, delete '//' at the beginning of the line after leading whitespace.", 78, "w:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 137 }, -{ PROC_LINKS(undo, 0), false, "undo", 4, "Advances backwards through the undo history of the current buffer.", 66, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1709 }, -{ PROC_LINKS(undo_all_buffers, 0), false, "undo_all_buffers", 16, "Advances backward through the undo history in the buffer containing the most recent regular edit.", 97, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1736 }, -{ PROC_LINKS(view_buffer_other_panel, 0), false, "view_buffer_other_panel", 23, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1597 }, +{ PROC_LINKS(undo, 0), false, "undo", 4, "Advances backwards through the undo history of the current buffer.", 66, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1711 }, +{ PROC_LINKS(undo_all_buffers, 0), false, "undo_all_buffers", 16, "Advances backward through the undo history in the buffer containing the most recent regular edit.", 97, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1738 }, +{ PROC_LINKS(view_buffer_other_panel, 0), false, "view_buffer_other_panel", 23, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1599 }, { PROC_LINKS(view_jump_list_with_lister, 0), false, "view_jump_list_with_lister", 26, "When executed on a buffer with jumps, creates a persistent lister for all the jumps", 83, "w:\\4ed\\code\\custom\\4coder_jump_lister.cpp", 41, 59 }, { PROC_LINKS(word_complete, 0), false, "word_complete", 13, "Iteratively tries completing the word to the left of the cursor with other words in open buffers that have the same prefix string.", 130, "w:\\4ed\\code\\custom\\4coder_search.cpp", 36, 395 }, { PROC_LINKS(word_complete_drop_down, 0), false, "word_complete_drop_down", 23, "Word complete with drop down menu.", 34, "w:\\4ed\\code\\custom\\4coder_search.cpp", 36, 642 }, @@ -493,7 +493,7 @@ static Command_Metadata fcoder_metacmd_table[238] = { { PROC_LINKS(write_hack, 0), false, "write_hack", 10, "At the cursor, insert a '// HACK' comment, includes user name if it was specified in config.4coder.", 99, "w:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 82 }, { PROC_LINKS(write_note, 0), false, "write_note", 10, "At the cursor, insert a '// NOTE' comment, includes user name if it was specified in config.4coder.", 99, "w:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 88 }, { PROC_LINKS(write_space, 0), false, "write_space", 11, "Inserts a space.", 16, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 67 }, -{ PROC_LINKS(write_text_and_auto_indent, 0), false, "write_text_and_auto_indent", 26, "Inserts text and auto-indents the line on which the cursor sits if any of the text contains 'layout punctuation' such as ;:{}()[]# and new lines.", 145, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 427 }, +{ PROC_LINKS(write_text_and_auto_indent, 0), false, "write_text_and_auto_indent", 26, "Inserts text and auto-indents the line on which the cursor sits if any of the text contains 'layout punctuation' such as ;:{}()[]# and new lines.", 145, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 433 }, { PROC_LINKS(write_text_input, 0), false, "write_text_input", 16, "Inserts whatever text was used to trigger this command.", 55, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 59 }, { PROC_LINKS(write_todo, 0), false, "write_todo", 10, "At the cursor, insert a '// TODO' comment, includes user name if it was specified in config.4coder.", 99, "w:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 76 }, { PROC_LINKS(write_underscore, 0), false, "write_underscore", 16, "Inserts an underscore.", 22, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 73 }, diff --git a/custom/generated/custom_api.cpp b/custom/generated/custom_api.cpp index b8e5f6b3..1435f471 100644 --- a/custom/generated/custom_api.cpp +++ b/custom/generated/custom_api.cpp @@ -154,6 +154,8 @@ vtable->set_hot_directory = set_hot_directory; vtable->send_exit_signal = send_exit_signal; vtable->hard_exit = hard_exit; vtable->set_window_title = set_window_title; +vtable->acquire_global_frame_mutex = acquire_global_frame_mutex; +vtable->release_global_frame_mutex = release_global_frame_mutex; vtable->draw_string_oriented = draw_string_oriented; vtable->get_string_advance = get_string_advance; vtable->draw_rectangle = draw_rectangle; @@ -332,6 +334,8 @@ set_hot_directory = vtable->set_hot_directory; send_exit_signal = vtable->send_exit_signal; hard_exit = vtable->hard_exit; set_window_title = vtable->set_window_title; +acquire_global_frame_mutex = vtable->acquire_global_frame_mutex; +release_global_frame_mutex = vtable->release_global_frame_mutex; draw_string_oriented = vtable->draw_string_oriented; get_string_advance = vtable->get_string_advance; draw_rectangle = vtable->draw_rectangle; diff --git a/custom/generated/custom_api.h b/custom/generated/custom_api.h index f89bcad5..3526d681 100644 --- a/custom/generated/custom_api.h +++ b/custom/generated/custom_api.h @@ -152,6 +152,8 @@ #define custom_send_exit_signal_sig() void custom_send_exit_signal(Application_Links* app) #define custom_hard_exit_sig() void custom_hard_exit(Application_Links* app) #define custom_set_window_title_sig() void custom_set_window_title(Application_Links* app, String_Const_u8 title) +#define custom_acquire_global_frame_mutex_sig() void custom_acquire_global_frame_mutex(Application_Links* app) +#define custom_release_global_frame_mutex_sig() void custom_release_global_frame_mutex(Application_Links* app) #define custom_draw_string_oriented_sig() Vec2_f32 custom_draw_string_oriented(Application_Links* app, Face_ID font_id, ARGB_Color color, String_Const_u8 str, Vec2_f32 point, u32 flags, Vec2_f32 delta) #define custom_get_string_advance_sig() f32 custom_get_string_advance(Application_Links* app, Face_ID font_id, String_Const_u8 str) #define custom_draw_rectangle_sig() void custom_draw_rectangle(Application_Links* app, Rect_f32 rect, f32 roundness, ARGB_Color color) @@ -326,6 +328,8 @@ typedef void custom_set_hot_directory_type(Application_Links* app, String_Const_ typedef void custom_send_exit_signal_type(Application_Links* app); typedef void custom_hard_exit_type(Application_Links* app); typedef void custom_set_window_title_type(Application_Links* app, String_Const_u8 title); +typedef void custom_acquire_global_frame_mutex_type(Application_Links* app); +typedef void custom_release_global_frame_mutex_type(Application_Links* app); typedef Vec2_f32 custom_draw_string_oriented_type(Application_Links* app, Face_ID font_id, ARGB_Color color, String_Const_u8 str, Vec2_f32 point, u32 flags, Vec2_f32 delta); typedef f32 custom_get_string_advance_type(Application_Links* app, Face_ID font_id, String_Const_u8 str); typedef void custom_draw_rectangle_type(Application_Links* app, Rect_f32 rect, f32 roundness, ARGB_Color color); @@ -501,6 +505,8 @@ custom_set_hot_directory_type *set_hot_directory; custom_send_exit_signal_type *send_exit_signal; custom_hard_exit_type *hard_exit; custom_set_window_title_type *set_window_title; +custom_acquire_global_frame_mutex_type *acquire_global_frame_mutex; +custom_release_global_frame_mutex_type *release_global_frame_mutex; custom_draw_string_oriented_type *draw_string_oriented; custom_get_string_advance_type *get_string_advance; custom_draw_rectangle_type *draw_rectangle; @@ -677,6 +683,8 @@ internal void set_hot_directory(Application_Links* app, String_Const_u8 string); internal void send_exit_signal(Application_Links* app); internal void hard_exit(Application_Links* app); internal void set_window_title(Application_Links* app, String_Const_u8 title); +internal void acquire_global_frame_mutex(Application_Links* app); +internal void release_global_frame_mutex(Application_Links* app); internal Vec2_f32 draw_string_oriented(Application_Links* app, Face_ID font_id, ARGB_Color color, String_Const_u8 str, Vec2_f32 point, u32 flags, Vec2_f32 delta); internal f32 get_string_advance(Application_Links* app, Face_ID font_id, String_Const_u8 str); internal void draw_rectangle(Application_Links* app, Rect_f32 rect, f32 roundness, ARGB_Color color); @@ -853,6 +861,8 @@ global custom_set_hot_directory_type *set_hot_directory = 0; global custom_send_exit_signal_type *send_exit_signal = 0; global custom_hard_exit_type *hard_exit = 0; global custom_set_window_title_type *set_window_title = 0; +global custom_acquire_global_frame_mutex_type *acquire_global_frame_mutex = 0; +global custom_release_global_frame_mutex_type *release_global_frame_mutex = 0; global custom_draw_string_oriented_type *draw_string_oriented = 0; global custom_get_string_advance_type *get_string_advance = 0; global custom_draw_rectangle_type *draw_rectangle = 0; diff --git a/custom/generated/custom_api_master_list.h b/custom/generated/custom_api_master_list.h index d65db2f1..d73628f7 100644 --- a/custom/generated/custom_api_master_list.h +++ b/custom/generated/custom_api_master_list.h @@ -152,6 +152,8 @@ api(custom) function void set_hot_directory(Application_Links* app, String_Const api(custom) function void send_exit_signal(Application_Links* app); api(custom) function void hard_exit(Application_Links* app); api(custom) function void set_window_title(Application_Links* app, String_Const_u8 title); +api(custom) function void acquire_global_frame_mutex(Application_Links* app); +api(custom) function void release_global_frame_mutex(Application_Links* app); api(custom) function Vec2_f32 draw_string_oriented(Application_Links* app, Face_ID font_id, ARGB_Color color, String_Const_u8 str, Vec2_f32 point, u32 flags, Vec2_f32 delta); api(custom) function f32 get_string_advance(Application_Links* app, Face_ID font_id, String_Const_u8 str); api(custom) function void draw_rectangle(Application_Links* app, Rect_f32 rect, f32 roundness, ARGB_Color color); diff --git a/platform_mac/mac_4ed_functions.mm b/platform_mac/mac_4ed_functions.mm index 677af480..135a8f10 100644 --- a/platform_mac/mac_4ed_functions.mm +++ b/platform_mac/mac_4ed_functions.mm @@ -9,44 +9,44 @@ function system_get_path_sig(){ String_Const_u8 result = {}; - + switch (path_code){ case SystemPath_CurrentDirectory: { char *working_dir = getcwd(NULL, 0); u64 working_dir_length = cstring_length(working_dir); - + // TODO(yuval): Maybe use push_string_copy instead u8 *out = push_array(arena, u8, working_dir_length); block_copy(out, working_dir, working_dir_length); - + free(working_dir); - + result = SCu8(out, working_dir_length); } break; - + case SystemPath_Binary: { local_persist b32 has_stashed_4ed_path = false; if (!has_stashed_4ed_path){ local_const u32 binary_path_capacity = PATH_MAX; u8 *memory = (u8*)system_memory_allocate(binary_path_capacity, file_name_line_number_lit_u8); - + pid_t pid = getpid(); i32 size = proc_pidpath(pid, memory, binary_path_capacity); Assert(size < binary_path_capacity); - + mac_vars.binary_path = SCu8(memory, size); mac_vars.binary_path = string_remove_last_folder(mac_vars.binary_path); mac_vars.binary_path.str[mac_vars.binary_path.size] = 0; - + has_stashed_4ed_path = true; } - + result = push_string_copy(arena, mac_vars.binary_path); } break; } - + return(result); } @@ -54,14 +54,14 @@ function system_get_canonical_sig(){ NSString *path_ns_str = [[NSString alloc] initWithBytes:name.data length:name.size encoding:NSUTF8StringEncoding]; - + NSString *standardized_path_ns_str = [path_ns_str stringByStandardizingPath]; String_Const_u8 standardized_path = SCu8((u8*)[standardized_path_ns_str UTF8String],[standardized_path_ns_str lengthOfBytesUsingEncoding:NSUTF8StringEncoding]); - + String_Const_u8 result = push_string_copy(arena, standardized_path); - + [path_ns_str release]; - + return(result); } @@ -72,107 +72,107 @@ mac_get_file_attributes(struct stat file_stat) { File_Attributes result; result.size = file_stat.st_size; result.last_write_time = file_stat.st_mtimespec.tv_sec; - + result.flags = 0; if (S_ISDIR(file_stat.st_mode)) { result.flags |= FileAttribute_IsDirectory; } - + return(result); } function inline File_Attributes mac_file_attributes_from_path(char *path) { File_Attributes result = {}; - + struct stat file_stat; if (stat(path, &file_stat) == 0){ result = mac_get_file_attributes(file_stat); } - + return(result); } function inline File_Attributes mac_file_attributes_from_fd(i32 fd) { File_Attributes result = {}; - + struct stat file_stat; if (fstat(fd, &file_stat) == 0){ result = mac_get_file_attributes(file_stat); } - + return(result); } function system_get_file_list_sig(){ File_List result = {}; - + u8 *c_directory = push_array(arena, u8, directory.size + 1); block_copy(c_directory, directory.str, directory.size); c_directory[directory.size] = 0; - + DIR *dir = opendir((char*)c_directory); if (dir){ File_Info* first = 0; File_Info* last = 0; i32 count = 0; - + for (struct dirent *entry = readdir(dir); entry; entry = readdir(dir)){ char *c_file_name = entry->d_name; String_Const_u8 file_name = SCu8(c_file_name); - + if (string_match(file_name, string_u8_litexpr(".")) || string_match(file_name, string_u8_litexpr(".."))){ continue; } - + File_Info *info = push_array(arena, File_Info, 1); sll_queue_push(first, last, info); count += 1; - + info->file_name = push_string_copy(arena, file_name); - + // NOTE(yuval): Get file attributes { Temp_Memory temp = begin_temp(arena); - + b32 append_slash = false; u64 file_path_size = directory.size + file_name.size; if (string_get_character(directory, directory.size - 1) != '/'){ append_slash = true; file_path_size += 1; } - + char *file_path = push_array(arena, char, file_path_size + 1); char *file_path_at = file_path; - + block_copy(file_path_at, directory.str, directory.size); file_path_at += directory.size; - + if (append_slash){ *file_path_at = '/'; file_path_at += 1; } - + block_copy(file_path_at, file_name.str, file_name.size); file_path_at += file_name.size; - + *file_path_at = 0; - + info->attributes = mac_file_attributes_from_path(file_path); - + end_temp(temp); } } - + closedir(dir); - + result.infos = push_array(arena, File_Info*, count); result.count = count; - + i32 index = 0; for (File_Info *node = first; node != 0; @@ -181,22 +181,22 @@ system_get_file_list_sig(){ index += 1; } } - + return(result); } function system_quick_file_attributes_sig(){ Temp_Memory temp = begin_temp(scratch); - + char *c_file_name = push_array(scratch, char, file_name.size + 1); block_copy(c_file_name, file_name.str, file_name.size); c_file_name[file_name.size] = 0; - + File_Attributes result = mac_file_attributes_from_path(c_file_name); - + end_temp(temp); - + return(result); } @@ -215,13 +215,13 @@ mac_to_fd(Plat_Handle handle){ function system_load_handle_sig(){ b32 result = false; - + i32 fd = open(file_name, O_RDONLY); if ((fd != -1) && (fd != 0)) { *out = mac_to_plat_handle(fd); result = true; } - + return(result); } @@ -229,14 +229,14 @@ function system_load_attributes_sig(){ i32 fd = mac_to_fd(handle); File_Attributes result = mac_file_attributes_from_fd(fd); - + return(result); } function system_load_file_sig(){ i32 fd = mac_to_fd(handle); - + do{ ssize_t bytes_read = read(fd, buffer, size); if (bytes_read == -1){ @@ -249,7 +249,7 @@ system_load_file_sig(){ buffer += bytes_read; } } while (size > 0); - + b32 result = (size == 0); return(result); } @@ -257,20 +257,20 @@ system_load_file_sig(){ function system_load_close_sig(){ b32 result = true; - + i32 fd = mac_to_fd(handle); if (close(fd) == -1){ // NOTE(yuval): An error occured while close the file descriptor result = false; } - + return(result); } function system_save_file_sig(){ File_Attributes result = {}; - + i32 fd = open(file_name, O_WRONLY | O_TRUNC | O_CREAT, 00640); if (fd != -1) { do{ @@ -285,14 +285,14 @@ system_save_file_sig(){ data.str += bytes_written; } } while (data.size > 0); - + if (data.size == 0) { result = mac_file_attributes_from_fd(fd); } - + close(fd); } - + return(result); } @@ -313,27 +313,27 @@ mac_to_dl_handle(System_Library system_lib){ function system_load_library_sig(){ b32 result = false; - + void *lib = 0; - + // NOTE(yuval): Open library handle { Temp_Memory temp = begin_temp(scratch); - + char *c_file_name = push_array(scratch, char, file_name.size + 1); block_copy(c_file_name, file_name.str, file_name.size); c_file_name[file_name.size] = 0; - + lib = dlopen(c_file_name, RTLD_LAZY | RTLD_GLOBAL); - + end_temp(temp); } - + if (lib){ *out = mac_to_system_library(lib); result = true; } - + return(result); } @@ -341,7 +341,7 @@ function system_release_library_sig(){ void *lib = mac_to_dl_handle(handle); i32 rc = dlclose(lib); - + b32 result = (rc == 0); return(result); } @@ -350,7 +350,7 @@ function system_get_proc_sig(){ void *lib = mac_to_dl_handle(handle); Void_Func *result = (Void_Func*)dlsym(lib, proc_name); - + return(result); } @@ -359,12 +359,12 @@ system_get_proc_sig(){ function system_now_time_sig(){ u64 now = mach_absolute_time(); - + // NOTE(yuval): Now time nanoseconds conversion f64 now_nano = (f64)((f64)now * ((f64)mac_vars.timebase_info.numer / (f64)mac_vars.timebase_info.denom)); - + // NOTE(yuval): Conversion to useconds u64 result = (u64)(now_nano * 1.0E-3); return(result); @@ -374,9 +374,9 @@ function system_wake_up_timer_create_sig(){ Mac_Object *object = mac_alloc_object(MacObjectKind_Timer); dll_insert(&mac_vars.timer_objects, &object->node); - + object->timer = nil; - + Plat_Handle result = mac_to_plat_handle(object); return(result); } @@ -412,7 +412,7 @@ system_signal_step_sig(){ target:mac_vars.view selector:@selector(request_display) userInfo:nil repeats:NO]; - + mac_vars.step_requested = true; } #else @@ -433,7 +433,7 @@ system_sleep_sig(){ u64 abs_sleep_time = (u64)((f64)nanoseconds * ((f64)mac_vars.timebase_info.denom / (f64)mac_vars.timebase_info.numer)); - + u64 now = mach_absolute_time(); mach_wait_until(now + abs_sleep_time); } @@ -448,7 +448,7 @@ system_post_clipboard_sig(){ } else{ linalloc_clear(arena); } - + mac_vars.clip_post.str = push_array(arena, u8, str.size + 1); if (mac_vars.clip_post.str != 0){ block_copy(mac_vars.clip_post.str, str.str, str.size); @@ -464,50 +464,50 @@ system_post_clipboard_sig(){ function system_cli_call_sig(){ b32 result = false; - + int pipe_fds[2]; if (pipe(pipe_fds) == -1){ perror("system_cli_call: pipe"); return(false); } - + pid_t child_pid = fork(); if (child_pid == -1){ perror("system_cli_call: fork"); return(false); } - + enum { PIPE_FD_READ, PIPE_FD_WRITE }; - + if (child_pid == 0){ // NOTE(yuval): Child Process close(pipe_fds[PIPE_FD_READ]); dup2(pipe_fds[PIPE_FD_WRITE], STDOUT_FILENO); dup2(pipe_fds[PIPE_FD_WRITE], STDERR_FILENO); - + if (chdir(path) == -1){ perror("system_cli_call: chdir"); exit(1); } - + char* argv[] = {"sh", "-c", script, 0}; - + if (execv("/bin/sh", argv) == -1){ perror("system_cli_call: execv"); } - + exit(1); } else{ // NOTE(yuval): Parent Process close(pipe_fds[PIPE_FD_WRITE]); - + *(pid_t*)&cli_out->proc = child_pid; *(int*)&cli_out->out_read = pipe_fds[PIPE_FD_READ]; *(int*)&cli_out->out_write = pipe_fds[PIPE_FD_WRITE]; - + mac_vars.running_cli += 1; } - + return(true); } @@ -519,16 +519,16 @@ system_cli_begin_update_sig(){ function system_cli_update_step_sig(){ int pipe_read_fd = *(int*)&cli->out_read; - + fd_set fds; FD_ZERO(&fds); FD_SET(pipe_read_fd, &fds); - + struct timeval tv = {}; - + size_t space_left = max; char* ptr = dest; - + while (space_left > 0 && (select(pipe_read_fd + 1, &fds, NULL, NULL, &tv) == 1)){ ssize_t num = read(pipe_read_fd, ptr, space_left); if (num == -1){ @@ -541,9 +541,9 @@ system_cli_update_step_sig(){ space_left -= num; } } - + *amount = (ptr - dest); - + b32 result = ((ptr - dest) > 0); return(result); } @@ -551,21 +551,21 @@ system_cli_update_step_sig(){ function system_cli_end_update_sig(){ b32 close_me = false; - + pid_t pid = *(pid_t*)&cli->proc; - + int status; if (pid && (waitpid(pid, &status, WNOHANG) > 0)){ cli->exit = WEXITSTATUS(status); - + close(*(int*)&cli->out_read); close(*(int*)&cli->out_write); - + mac_vars.running_cli -= 1; - + close_me = true; } - + return(close_me); } @@ -589,16 +589,16 @@ mac_thread_wrapper(void *ptr){ Mac_Object *object = (Mac_Object*)ptr; Thread_Function *proc = object->thread.proc; void *object_ptr = object->thread.ptr; - + pthread_mutex_lock(&mac_vars.thread_launch_mutex); { mac_vars.waiting_for_launch = false; pthread_cond_signal(&mac_vars.thread_launch_cv); } pthread_mutex_unlock(&mac_vars.thread_launch_mutex); - + proc(object_ptr); - + return(0); } @@ -607,18 +607,18 @@ system_thread_launch_sig(){ Mac_Object *object = mac_alloc_object(MacObjectKind_Thread); object->thread.proc = proc; object->thread.ptr = ptr; - + pthread_mutex_lock(&mac_vars.thread_launch_mutex); { mac_vars.waiting_for_launch = true; pthread_create(&object->thread.thread, 0, mac_thread_wrapper, object); - + while (mac_vars.waiting_for_launch){ pthread_cond_wait(&mac_vars.thread_launch_cv, &mac_vars.thread_launch_mutex); } } pthread_mutex_unlock(&mac_vars.thread_launch_mutex); - + System_Thread result = mac_to_plat_handle(object); return(result); } @@ -650,7 +650,7 @@ function system_mutex_make_sig(){ Mac_Object *object = mac_alloc_object(MacObjectKind_Mutex); mac_init_recursive_mutex(&object->mutex); - + System_Mutex result = mac_to_plat_handle(object); return(result); } @@ -682,14 +682,16 @@ system_mutex_free_sig(){ function system_acquire_global_frame_mutex_sig(){ - if (tctx->kind == ThreadKind_AsyncTasks){ + if (tctx->kind == ThreadKind_AsyncTasks || + tctx->kind == ThreadKind_MainCoroutine){ system_mutex_acquire(mac_vars.global_frame_mutex); } } function system_release_global_frame_mutex_sig(){ - if (tctx->kind == ThreadKind_AsyncTasks){ + if (tctx->kind == ThreadKind_AsyncTasks || + tctx->kind == ThreadKind_MainCoroutine){ system_mutex_release(mac_vars.global_frame_mutex); } } @@ -698,7 +700,7 @@ function system_condition_variable_make_sig(){ Mac_Object *object = mac_alloc_object(MacObjectKind_CV); pthread_cond_init(&object->cv, 0); - + System_Condition_Variable result = mac_to_plat_handle(object); return(result); } @@ -754,19 +756,19 @@ mac_memory_allocate_extended(void *base, u64 size, String_Const_u8 location){ u64 adjusted_size = size + ALLOCATION_SIZE_ADJUSTMENT; void *memory = mmap(base, adjusted_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); Assert(memory != MAP_FAILED); - + Memory_Annotation_Tracker_Node *node = (Memory_Annotation_Tracker_Node*)memory; - + pthread_mutex_lock(&memory_tracker_mutex); { zdll_push_back(memory_tracker.first, memory_tracker.last, node); memory_tracker.count += 1; } pthread_mutex_unlock(&memory_tracker_mutex); - + node->location = location; node->size = size; - + void* result = (node + 1); return(result); } @@ -775,14 +777,14 @@ function void mac_memory_free_extended(void *ptr){ Memory_Annotation_Tracker_Node *node = (Memory_Annotation_Tracker_Node*)ptr; node -= 1; - + pthread_mutex_lock(&memory_tracker_mutex); { zdll_remove(memory_tracker.first, memory_tracker.last, node); memory_tracker.count -= 1; } pthread_mutex_unlock(&memory_tracker_mutex); - + munmap(node, node->size + ALLOCATION_SIZE_ADJUSTMENT); } @@ -795,35 +797,35 @@ system_memory_allocate_sig(){ function system_memory_set_protection_sig(){ b32 result = true; - + int protect = 0; switch (flags & 0x7){ case 0: { protect = PROT_NONE; } break; - + case MemProtect_Read: { protect = PROT_READ; } break; - + case MemProtect_Write: case MemProtect_Read | MemProtect_Write: { protect = PROT_READ | PROT_WRITE; } break; - + case MemProtect_Execute: { protect = PROT_EXEC; } break; - + case MemProtect_Execute | MemProtect_Read: { protect = PROT_READ | PROT_EXEC; } break; - + // NOTE(inso): some W^X protection things might be unhappy about this one case MemProtect_Execute | MemProtect_Write: case MemProtect_Execute | MemProtect_Write | MemProtect_Read: @@ -831,14 +833,14 @@ system_memory_set_protection_sig(){ protect = PROT_READ | PROT_WRITE | PROT_EXEC; } break; } - + Memory_Annotation_Tracker_Node *node = (Memory_Annotation_Tracker_Node*)ptr; node -= 1; - + if(mprotect(node, size, protect) == -1){ result = false; } - + return(result); } @@ -850,7 +852,7 @@ system_memory_free_sig(){ function system_memory_annotation_sig(){ Memory_Annotation result = {}; - + pthread_mutex_lock(&memory_tracker_mutex); { for (Memory_Annotation_Tracker_Node *node = memory_tracker.first; @@ -859,15 +861,15 @@ system_memory_annotation_sig(){ Memory_Annotation_Node *r_node = push_array(arena, Memory_Annotation_Node, 1); sll_queue_push(result.first, result.last, r_node); result.count += 1; - + r_node->location = node->location; r_node->address = node + 1; r_node->size = node->size; } - + } pthread_mutex_unlock(&memory_tracker_mutex); - + return(result); } @@ -882,7 +884,7 @@ function system_set_fullscreen_sig(){ // NOTE(yuval): Read comment in system_set_fullscreen_sig in win32_4ed.cpp mac_vars.do_toggle = (mac_vars.full_screen != full_screen); - + b32 success = true; return(success); } diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index f4e5dd9c..cccda51a 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -920,16 +920,24 @@ system_mutex_release_sig(){ } } +global i32 global_frame_mutex_state_ticker = 0; + internal system_acquire_global_frame_mutex_sig(){ - if (tctx->kind == ThreadKind_AsyncTasks){ + if (tctx->kind == ThreadKind_AsyncTasks || + tctx->kind == ThreadKind_Main){ system_mutex_acquire(win32vars.global_frame_mutex); + Assert(global_frame_mutex_state_ticker == 0); + global_frame_mutex_state_ticker = 1; } } internal system_release_global_frame_mutex_sig(){ - if (tctx->kind == ThreadKind_AsyncTasks){ + if (tctx->kind == ThreadKind_AsyncTasks || + tctx->kind == ThreadKind_Main){ + Assert(global_frame_mutex_state_ticker == 1); + global_frame_mutex_state_ticker = 0; system_mutex_release(win32vars.global_frame_mutex); } } @@ -1732,7 +1740,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS ShowWindow(win32vars.window_handle, SW_SHOW); win32vars.global_frame_mutex = system_mutex_make(); - system_mutex_acquire(win32vars.global_frame_mutex); + system_acquire_global_frame_mutex(win32vars.tctx); u64 timer_start = system_now_time(); MSG msg; @@ -1753,7 +1761,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // NOTE(allen): while we're doing this (and possibly sleeping) // we can let async processes get there time in. - system_mutex_release(win32vars.global_frame_mutex); + system_release_global_frame_mutex(win32vars.tctx); b32 get_more_messages = true; do{ @@ -1830,7 +1838,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } }while (get_more_messages); - system_mutex_acquire(win32vars.global_frame_mutex); + system_acquire_global_frame_mutex(win32vars.tctx); } // NOTE(allen): Mouse Out of Window Detection @@ -1955,7 +1963,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } // NOTE(allen): sleep a bit to cool off :) - system_mutex_release(win32vars.global_frame_mutex); + system_release_global_frame_mutex(win32vars.tctx); u64 timer_end = system_now_time(); u64 end_target = timer_start + frame_useconds; @@ -1969,7 +1977,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } timer_start = system_now_time(); - system_mutex_acquire(win32vars.global_frame_mutex); + system_acquire_global_frame_mutex(win32vars.tctx); win32vars.first = false; }