From 7792bb2b811eccbcd9a4ae467b1f97a16b8c5296 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Tue, 2 Apr 2019 13:06:49 -0700 Subject: [PATCH] New insertion buffering; fixed new search bug --- 4coder_api_transition_30_31_helpers.cpp | 5 + 4coder_default_include.cpp | 1 + 4coder_experiments.cpp | 2 +- 4coder_generated/app_functions.h | 7 + 4coder_generated/command_metadata.h | 50 +++--- 4coder_helper.h | 9 -- 4coder_insertion.cpp | 60 ++++++- 4coder_insertion.h | 22 +++ 4coder_search.cpp | 202 +++++++++++++----------- 4coder_search.h | 8 +- 4coder_seek.cpp | 7 +- 4ed_api_implementation.cpp | 47 ++---- 12 files changed, 251 insertions(+), 169 deletions(-) create mode 100644 4coder_insertion.h diff --git a/4coder_api_transition_30_31_helpers.cpp b/4coder_api_transition_30_31_helpers.cpp index 4be22578..e918f195 100644 --- a/4coder_api_transition_30_31_helpers.cpp +++ b/4coder_api_transition_30_31_helpers.cpp @@ -142,6 +142,11 @@ buffer_seek_alphanumeric_or_camel_left(Application_Links *app, Buffer_Summary *b return(buffer==0?0:buffer_seek_alphanumeric_or_camel_left(app, buffer->buffer_id, pos)); } +static i32 +buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ + return(buffer!=0?0:buffer_seek_alpha_numeric_end(app, buffer->buffer_id, pos)); +} + static Cpp_Token_Array buffer_get_all_tokens(Application_Links *app, Partition *part, Buffer_Summary *buffer){ Cpp_Token_Array result = {}; diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 0f1ad45d..50aa9d46 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -27,6 +27,7 @@ #include "4coder_api_transition_30_31.h" #include "4coder_helper.h" +#include "4coder_insertion.h" #include "4coder_fancy.h" #include "4coder_ui_helper.h" #include "4coder_default_framework.h" diff --git a/4coder_experiments.cpp b/4coder_experiments.cpp index 7b8ed883..1985da45 100644 --- a/4coder_experiments.cpp +++ b/4coder_experiments.cpp @@ -741,7 +741,7 @@ replace_all_occurrences_parameters(Application_Links *app, Heap *heap, Partition Replace_Target *new_target = push_array(part, Replace_Target, 1); if (new_target != 0){ - new_target->buffer_id = match.buffer.buffer_id; + new_target->buffer_id = match.buffer; new_target->start_pos = match.start; ++target_count; } diff --git a/4coder_generated/app_functions.h b/4coder_generated/app_functions.h index 4e8fba9b..7b9590ad 100644 --- a/4coder_generated/app_functions.h +++ b/4coder_generated/app_functions.h @@ -51,6 +51,7 @@ struct Application_Links; #define GET_ACTIVE_VIEW_SIG(n) b32 n(Application_Links *app, Access_Flag access, View_ID *view_id_out) #define GET_ACTIVE_PANEL_SIG(n) b32 n(Application_Links *app, Panel_ID *panel_id_out) #define VIEW_GET_BUFFER_SIG(n) b32 n(Application_Links *app, View_ID view_id, Access_Flag access, Buffer_ID *buffer_id_out) +#define VIEW_GET_CURSOR_POS_SIG(n) b32 n(Application_Links *app, View_ID view_id, i32 *pos_out) #define VIEW_GET_PANEL_SIG(n) b32 n(Application_Links *app, View_ID view_id, Panel_ID *panel_id_out) #define PANEL_GET_VIEW_SIG(n) b32 n(Application_Links *app, Panel_ID panel_id, View_ID *view_id_out) #define PANEL_IS_SPLIT_SIG(n) b32 n(Application_Links *app, Panel_ID panel_id) @@ -232,6 +233,7 @@ typedef GET_VIEW_SUMMARY_SIG(Get_View_Summary_Function); typedef GET_ACTIVE_VIEW_SIG(Get_Active_View_Function); typedef GET_ACTIVE_PANEL_SIG(Get_Active_Panel_Function); typedef VIEW_GET_BUFFER_SIG(View_Get_Buffer_Function); +typedef VIEW_GET_CURSOR_POS_SIG(View_Get_Cursor_Pos_Function); typedef VIEW_GET_PANEL_SIG(View_Get_Panel_Function); typedef PANEL_GET_VIEW_SIG(Panel_Get_View_Function); typedef PANEL_IS_SPLIT_SIG(Panel_Is_Split_Function); @@ -415,6 +417,7 @@ Get_View_Summary_Function *get_view_summary; Get_Active_View_Function *get_active_view; Get_Active_Panel_Function *get_active_panel; View_Get_Buffer_Function *view_get_buffer; +View_Get_Cursor_Pos_Function *view_get_cursor_pos; View_Get_Panel_Function *view_get_panel; Panel_Get_View_Function *panel_get_view; Panel_Is_Split_Function *panel_is_split; @@ -597,6 +600,7 @@ Get_View_Summary_Function *get_view_summary_; Get_Active_View_Function *get_active_view_; Get_Active_Panel_Function *get_active_panel_; View_Get_Buffer_Function *view_get_buffer_; +View_Get_Cursor_Pos_Function *view_get_cursor_pos_; View_Get_Panel_Function *view_get_panel_; Panel_Get_View_Function *panel_get_view_; Panel_Is_Split_Function *panel_is_split_; @@ -787,6 +791,7 @@ app_links->get_view_summary_ = Get_View_Summary;\ app_links->get_active_view_ = Get_Active_View;\ app_links->get_active_panel_ = Get_Active_Panel;\ app_links->view_get_buffer_ = View_Get_Buffer;\ +app_links->view_get_cursor_pos_ = View_Get_Cursor_Pos;\ app_links->view_get_panel_ = View_Get_Panel;\ app_links->panel_get_view_ = Panel_Get_View;\ app_links->panel_is_split_ = Panel_Is_Split;\ @@ -969,6 +974,7 @@ static b32 get_view_summary(Application_Links *app, View_ID view_id, Access_Flag static b32 get_active_view(Application_Links *app, Access_Flag access, View_ID *view_id_out){return(app->get_active_view(app, access, view_id_out));} static b32 get_active_panel(Application_Links *app, Panel_ID *panel_id_out){return(app->get_active_panel(app, panel_id_out));} static b32 view_get_buffer(Application_Links *app, View_ID view_id, Access_Flag access, Buffer_ID *buffer_id_out){return(app->view_get_buffer(app, view_id, access, buffer_id_out));} +static b32 view_get_cursor_pos(Application_Links *app, View_ID view_id, i32 *pos_out){return(app->view_get_cursor_pos(app, view_id, pos_out));} static b32 view_get_panel(Application_Links *app, View_ID view_id, Panel_ID *panel_id_out){return(app->view_get_panel(app, view_id, panel_id_out));} static b32 panel_get_view(Application_Links *app, Panel_ID panel_id, View_ID *view_id_out){return(app->panel_get_view(app, panel_id, view_id_out));} static b32 panel_is_split(Application_Links *app, Panel_ID panel_id){return(app->panel_is_split(app, panel_id));} @@ -1151,6 +1157,7 @@ static b32 get_view_summary(Application_Links *app, View_ID view_id, Access_Flag static b32 get_active_view(Application_Links *app, Access_Flag access, View_ID *view_id_out){return(app->get_active_view_(app, access, view_id_out));} static b32 get_active_panel(Application_Links *app, Panel_ID *panel_id_out){return(app->get_active_panel_(app, panel_id_out));} static b32 view_get_buffer(Application_Links *app, View_ID view_id, Access_Flag access, Buffer_ID *buffer_id_out){return(app->view_get_buffer_(app, view_id, access, buffer_id_out));} +static b32 view_get_cursor_pos(Application_Links *app, View_ID view_id, i32 *pos_out){return(app->view_get_cursor_pos_(app, view_id, pos_out));} static b32 view_get_panel(Application_Links *app, View_ID view_id, Panel_ID *panel_id_out){return(app->view_get_panel_(app, view_id, panel_id_out));} static b32 panel_get_view(Application_Links *app, Panel_ID panel_id, View_ID *view_id_out){return(app->panel_get_view_(app, panel_id, view_id_out));} static b32 panel_is_split(Application_Links *app, Panel_ID panel_id){return(app->panel_is_split_(app, panel_id));} diff --git a/4coder_generated/command_metadata.h b/4coder_generated/command_metadata.h index 0f060b10..3faf7f2a 100644 --- a/4coder_generated/command_metadata.h +++ b/4coder_generated/command_metadata.h @@ -260,7 +260,7 @@ static Command_Metadata fcoder_metacmd_table[234] = { { PROC_LINKS(auto_tab_range, 0), "auto_tab_range", 14, "Auto-indents the range between the cursor and the mark.", 55, "c:\\4ed\\code\\4coder_auto_indent.cpp", 34, 640 }, { PROC_LINKS(auto_tab_whole_file, 0), "auto_tab_whole_file", 19, "Audo-indents the entire current buffer.", 39, "c:\\4ed\\code\\4coder_auto_indent.cpp", 34, 619 }, { PROC_LINKS(backspace_char, 0), "backspace_char", 14, "Deletes the character to the left of the cursor.", 48, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 101 }, -{ PROC_LINKS(backspace_word, 0), "backspace_word", 14, "Delete characters between the cursor position and the first alphanumeric boundary to the left.", 94, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1212 }, +{ PROC_LINKS(backspace_word, 0), "backspace_word", 14, "Delete characters between the cursor position and the first alphanumeric boundary to the left.", 94, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1215 }, { PROC_LINKS(basic_change_active_panel, 0), "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, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 510 }, { PROC_LINKS(build_in_build_panel, 0), "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, "c:\\4ed\\code\\4coder_build_commands.cpp", 37, 187 }, { PROC_LINKS(build_search, 0), "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, "c:\\4ed\\code\\4coder_build_commands.cpp", 37, 155 }, @@ -289,7 +289,7 @@ static Command_Metadata fcoder_metacmd_table[234] = { { PROC_LINKS(delete_file_query, 0), "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, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1191 }, { PROC_LINKS(delete_line, 0), "delete_line", 11, "Delete the line the on which the cursor sits.", 45, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1444 }, { PROC_LINKS(delete_range, 0), "delete_range", 12, "Deletes the text in the range between the cursor and the mark.", 62, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 139 }, -{ PROC_LINKS(delete_word, 0), "delete_word", 11, "Delete characters between the cursor position and the first alphanumeric boundary to the right.", 95, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1218 }, +{ PROC_LINKS(delete_word, 0), "delete_word", 11, "Delete characters between the cursor position and the first alphanumeric boundary to the right.", 95, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1221 }, { PROC_LINKS(duplicate_line, 0), "duplicate_line", 14, "Create a copy of the line on which the cursor sits.", 51, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1421 }, { PROC_LINKS(eol_dosify, 0), "eol_dosify", 10, "Puts the buffer in DOS line ending mode.", 40, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 666 }, { PROC_LINKS(eol_nixify, 0), "eol_nixify", 10, "Puts the buffer in NIX line ending mode.", 40, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 674 }, @@ -331,16 +331,16 @@ static Command_Metadata fcoder_metacmd_table[234] = { { PROC_LINKS(list_all_functions_all_buffers_lister, 0), "list_all_functions_all_buffers_lister", 37, "Creates a lister of locations that look like function definitions and declarations all buffers.", 95, "c:\\4ed\\code\\4coder_function_list.cpp", 36, 338 }, { PROC_LINKS(list_all_functions_current_buffer, 0), "list_all_functions_current_buffer", 33, "Creates a jump list of lines of the current buffer that appear to define or declare functions.", 94, "c:\\4ed\\code\\4coder_function_list.cpp", 36, 309 }, { PROC_LINKS(list_all_functions_current_buffer_lister, 0), "list_all_functions_current_buffer_lister", 40, "Creates a lister of locations that look like function definitions and declarations in the buffer.", 97, "c:\\4ed\\code\\4coder_function_list.cpp", 36, 319 }, -{ PROC_LINKS(list_all_locations, 0), "list_all_locations", 18, "Queries the user for a string and lists all exact case-sensitive matches found in all open buffers.", 99, "c:\\4ed\\code\\4coder_search.cpp", 29, 792 }, -{ PROC_LINKS(list_all_locations_case_insensitive, 0), "list_all_locations_case_insensitive", 35, "Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.", 101, "c:\\4ed\\code\\4coder_search.cpp", 29, 806 }, -{ PROC_LINKS(list_all_locations_of_identifier, 0), "list_all_locations_of_identifier", 32, "Reads a token or word under the cursor and lists all exact case-sensitive mathces in all open buffers.", 102, "c:\\4ed\\code\\4coder_search.cpp", 29, 820 }, -{ PROC_LINKS(list_all_locations_of_identifier_case_insensitive, 0), "list_all_locations_of_identifier_case_insensitive", 49, "Reads a token or word under the cursor and lists all exact case-insensitive mathces in all open buffers.", 104, "c:\\4ed\\code\\4coder_search.cpp", 29, 827 }, -{ PROC_LINKS(list_all_locations_of_selection, 0), "list_all_locations_of_selection", 31, "Reads the string in the selected range and lists all exact case-sensitive mathces in all open buffers.", 102, "c:\\4ed\\code\\4coder_search.cpp", 29, 834 }, -{ PROC_LINKS(list_all_locations_of_selection_case_insensitive, 0), "list_all_locations_of_selection_case_insensitive", 48, "Reads the string in the selected range and lists all exact case-insensitive mathces in all open buffers.", 104, "c:\\4ed\\code\\4coder_search.cpp", 29, 841 }, -{ PROC_LINKS(list_all_locations_of_type_definition, 0), "list_all_locations_of_type_definition", 37, "Queries user for string, lists all locations of strings that appear to define a type whose name matches the input string.", 121, "c:\\4ed\\code\\4coder_search.cpp", 29, 848 }, -{ PROC_LINKS(list_all_locations_of_type_definition_of_identifier, 0), "list_all_locations_of_type_definition_of_identifier", 51, "Reads a token or word under the cursor and lists all locations of strings that appear to define a type whose name matches it.", 125, "c:\\4ed\\code\\4coder_search.cpp", 29, 859 }, -{ PROC_LINKS(list_all_substring_locations, 0), "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "c:\\4ed\\code\\4coder_search.cpp", 29, 799 }, -{ PROC_LINKS(list_all_substring_locations_case_insensitive, 0), "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "c:\\4ed\\code\\4coder_search.cpp", 29, 813 }, +{ PROC_LINKS(list_all_locations, 0), "list_all_locations", 18, "Queries the user for a string and lists all exact case-sensitive matches found in all open buffers.", 99, "c:\\4ed\\code\\4coder_search.cpp", 29, 810 }, +{ PROC_LINKS(list_all_locations_case_insensitive, 0), "list_all_locations_case_insensitive", 35, "Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.", 101, "c:\\4ed\\code\\4coder_search.cpp", 29, 824 }, +{ PROC_LINKS(list_all_locations_of_identifier, 0), "list_all_locations_of_identifier", 32, "Reads a token or word under the cursor and lists all exact case-sensitive mathces in all open buffers.", 102, "c:\\4ed\\code\\4coder_search.cpp", 29, 838 }, +{ PROC_LINKS(list_all_locations_of_identifier_case_insensitive, 0), "list_all_locations_of_identifier_case_insensitive", 49, "Reads a token or word under the cursor and lists all exact case-insensitive mathces in all open buffers.", 104, "c:\\4ed\\code\\4coder_search.cpp", 29, 845 }, +{ PROC_LINKS(list_all_locations_of_selection, 0), "list_all_locations_of_selection", 31, "Reads the string in the selected range and lists all exact case-sensitive mathces in all open buffers.", 102, "c:\\4ed\\code\\4coder_search.cpp", 29, 852 }, +{ PROC_LINKS(list_all_locations_of_selection_case_insensitive, 0), "list_all_locations_of_selection_case_insensitive", 48, "Reads the string in the selected range and lists all exact case-insensitive mathces in all open buffers.", 104, "c:\\4ed\\code\\4coder_search.cpp", 29, 859 }, +{ PROC_LINKS(list_all_locations_of_type_definition, 0), "list_all_locations_of_type_definition", 37, "Queries user for string, lists all locations of strings that appear to define a type whose name matches the input string.", 121, "c:\\4ed\\code\\4coder_search.cpp", 29, 866 }, +{ PROC_LINKS(list_all_locations_of_type_definition_of_identifier, 0), "list_all_locations_of_type_definition_of_identifier", 51, "Reads a token or word under the cursor and lists all locations of strings that appear to define a type whose name matches it.", 125, "c:\\4ed\\code\\4coder_search.cpp", 29, 877 }, +{ PROC_LINKS(list_all_substring_locations, 0), "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "c:\\4ed\\code\\4coder_search.cpp", 29, 817 }, +{ PROC_LINKS(list_all_substring_locations_case_insensitive, 0), "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "c:\\4ed\\code\\4coder_search.cpp", 29, 831 }, { PROC_LINKS(lister__activate, 0), "lister__activate", 16, "A lister mode command that activates the list's action on the highlighted item.", 79, "c:\\4ed\\code\\4coder_lists.cpp", 28, 15 }, { PROC_LINKS(lister__backspace_text_field, 0), "lister__backspace_text_field", 28, "A lister mode command that dispatches to the lister's backspace text field handler.", 83, "c:\\4ed\\code\\4coder_lists.cpp", 28, 41 }, { PROC_LINKS(lister__backspace_text_field__default, 0), "lister__backspace_text_field__default", 37, "A lister mode command that backspaces one character from the text field.", 72, "c:\\4ed\\code\\4coder_lists.cpp", 28, 145 }, @@ -421,22 +421,22 @@ static Command_Metadata fcoder_metacmd_table[234] = { { PROC_LINKS(scope_absorb_down, 0), "scope_absorb_down", 17, "If a scope is currently selected, and a statement or block statement is present below the current scope, the statement is moved into the scope.", 143, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 751 }, { PROC_LINKS(search, 0), "search", 6, "Begins an incremental search down through the current buffer for a user specified string.", 89, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 912 }, { PROC_LINKS(search_identifier, 0), "search_identifier", 17, "Begins an incremental search down through the current buffer for the word or token under the cursor.", 100, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 926 }, -{ PROC_LINKS(seek_alphanumeric_left, 0), "seek_alphanumeric_left", 22, "Seek left for boundary between alphanumeric characters and non-alphanumeric characters.", 87, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1192 }, -{ PROC_LINKS(seek_alphanumeric_or_camel_left, 0), "seek_alphanumeric_or_camel_left", 31, "Seek left for boundary between alphanumeric characters or camel case word and non-alphanumeric characters.", 106, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1204 }, -{ PROC_LINKS(seek_alphanumeric_or_camel_right, 0), "seek_alphanumeric_or_camel_right", 32, "Seek right for boundary between alphanumeric characters or camel case word and non-alphanumeric characters.", 107, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1198 }, -{ PROC_LINKS(seek_alphanumeric_right, 0), "seek_alphanumeric_right", 23, "Seek right for boundary between alphanumeric characters and non-alphanumeric characters.", 88, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1186 }, +{ PROC_LINKS(seek_alphanumeric_left, 0), "seek_alphanumeric_left", 22, "Seek left for boundary between alphanumeric characters and non-alphanumeric characters.", 87, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1195 }, +{ PROC_LINKS(seek_alphanumeric_or_camel_left, 0), "seek_alphanumeric_or_camel_left", 31, "Seek left for boundary between alphanumeric characters or camel case word and non-alphanumeric characters.", 106, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1207 }, +{ PROC_LINKS(seek_alphanumeric_or_camel_right, 0), "seek_alphanumeric_or_camel_right", 32, "Seek right for boundary between alphanumeric characters or camel case word and non-alphanumeric characters.", 107, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1201 }, +{ PROC_LINKS(seek_alphanumeric_right, 0), "seek_alphanumeric_right", 23, "Seek right for boundary between alphanumeric characters and non-alphanumeric characters.", 88, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1189 }, { PROC_LINKS(seek_beginning_of_line, 0), "seek_beginning_of_line", 22, "Seeks the cursor to the beginning of the visual line.", 53, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1083 }, { PROC_LINKS(seek_beginning_of_textual_line, 0), "seek_beginning_of_textual_line", 30, "Seeks the cursor to the beginning of the line across all text.", 62, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1061 }, { PROC_LINKS(seek_end_of_line, 0), "seek_end_of_line", 16, "Seeks the cursor to the end of the visual line.", 47, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1095 }, { PROC_LINKS(seek_end_of_textual_line, 0), "seek_end_of_textual_line", 24, "Seeks the cursor to the end of the line across all text.", 56, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1072 }, -{ PROC_LINKS(seek_token_left, 0), "seek_token_left", 15, "Seek left for the next beginning of a token.", 44, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1168 }, -{ PROC_LINKS(seek_token_right, 0), "seek_token_right", 16, "Seek right for the next end of a token.", 39, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1162 }, -{ PROC_LINKS(seek_white_or_token_left, 0), "seek_white_or_token_left", 24, "Seek left for the next end of a token or boundary between whitespace and non-whitespace.", 88, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1180 }, -{ PROC_LINKS(seek_white_or_token_right, 0), "seek_white_or_token_right", 25, "Seek right for the next end of a token or boundary between whitespace and non-whitespace.", 89, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1174 }, +{ PROC_LINKS(seek_token_left, 0), "seek_token_left", 15, "Seek left for the next beginning of a token.", 44, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1171 }, +{ PROC_LINKS(seek_token_right, 0), "seek_token_right", 16, "Seek right for the next end of a token.", 39, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1165 }, +{ PROC_LINKS(seek_white_or_token_left, 0), "seek_white_or_token_left", 24, "Seek left for the next end of a token or boundary between whitespace and non-whitespace.", 88, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1183 }, +{ PROC_LINKS(seek_white_or_token_right, 0), "seek_white_or_token_right", 25, "Seek right for the next end of a token or boundary between whitespace and non-whitespace.", 89, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1177 }, { PROC_LINKS(seek_whitespace_down, 0), "seek_whitespace_down", 20, "Seeks the cursor down to the next blank line.", 45, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1050 }, { PROC_LINKS(seek_whitespace_down_end_line, 0), "seek_whitespace_down_end_line", 29, "Seeks the cursor down to the next blank line and places it at the end of the line.", 82, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1119 }, -{ PROC_LINKS(seek_whitespace_left, 0), "seek_whitespace_left", 20, "Seek left for the next boundary between whitespace and non-whitespace.", 70, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1156 }, -{ PROC_LINKS(seek_whitespace_right, 0), "seek_whitespace_right", 21, "Seek right for the next boundary between whitespace and non-whitespace.", 71, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1150 }, +{ PROC_LINKS(seek_whitespace_left, 0), "seek_whitespace_left", 20, "Seek left for the next boundary between whitespace and non-whitespace.", 70, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1159 }, +{ PROC_LINKS(seek_whitespace_right, 0), "seek_whitespace_right", 21, "Seek right for the next boundary between whitespace and non-whitespace.", 71, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1153 }, { PROC_LINKS(seek_whitespace_up, 0), "seek_whitespace_up", 18, "Seeks the cursor up to the next blank line.", 43, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1039 }, { PROC_LINKS(seek_whitespace_up_end_line, 0), "seek_whitespace_up_end_line", 27, "Seeks the cursor up to the next blank line and places it at the end of the line.", 80, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1107 }, { PROC_LINKS(select_all, 0), "select_all", 10, "Puts the cursor at the top of the file, and the mark at the bottom of the file.", 79, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 389 }, @@ -455,8 +455,8 @@ static Command_Metadata fcoder_metacmd_table[234] = { { PROC_LINKS(setup_new_project, 0), "setup_new_project", 17, "Queries the user for several configuration options and initializes a new 4coder project with build scripts for every OS.", 120, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1491 }, { PROC_LINKS(show_filebar, 0), "show_filebar", 12, "Sets the current view to show it's filebar.", 43, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 541 }, { PROC_LINKS(show_scrollbar, 0), "show_scrollbar", 14, "Sets the current view to show it's scrollbar.", 45, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 527 }, -{ PROC_LINKS(snipe_token_or_word, 0), "snipe_token_or_word", 19, "Delete a single, whole token on or to the left of the cursor and post it to the clipboard.", 90, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1224 }, -{ PROC_LINKS(snipe_token_or_word_right, 0), "snipe_token_or_word_right", 25, "Delete a single, whole token on or to the right of the cursor and post it to the clipboard.", 91, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1230 }, +{ PROC_LINKS(snipe_token_or_word, 0), "snipe_token_or_word", 19, "Delete a single, whole token on or to the left of the cursor and post it to the clipboard.", 90, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1227 }, +{ PROC_LINKS(snipe_token_or_word_right, 0), "snipe_token_or_word_right", 25, "Delete a single, whole token on or to the right of the cursor and post it to the clipboard.", 91, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1233 }, { PROC_LINKS(snippet_lister, 0), "snippet_lister", 14, "Opens a snippet lister for inserting whole pre-written snippets of text.", 72, "c:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 248 }, { PROC_LINKS(suppress_mouse, 0), "suppress_mouse", 14, "Hides the mouse and causes all mosue input (clicks, position, wheel) to be ignored.", 83, "c:\\4ed\\code\\4coder_default_framework.cpp", 40, 325 }, { PROC_LINKS(swap_buffers_between_panels, 0), "swap_buffers_between_panels", 27, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1592 }, @@ -478,7 +478,7 @@ static Command_Metadata fcoder_metacmd_table[234] = { { PROC_LINKS(undo_this_buffer, 0), "undo_this_buffer", 16, "Advances backwards through the undo history of the current buffer.", 66, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1702 }, { PROC_LINKS(view_buffer_other_panel, 0), "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, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1582 }, { PROC_LINKS(view_jump_list_with_lister, 0), "view_jump_list_with_lister", 26, "When executed on a buffer with jumps, creates a persistent lister for all the jumps", 83, "c:\\4ed\\code\\4coder_jump_lister.cpp", 34, 106 }, -{ PROC_LINKS(word_complete, 0), "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, "c:\\4ed\\code\\4coder_search.cpp", 29, 879 }, +{ PROC_LINKS(word_complete, 0), "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, "c:\\4ed\\code\\4coder_search.cpp", 29, 897 }, { PROC_LINKS(write_and_auto_tab, 0), "write_and_auto_tab", 18, "Inserts a character and auto-indents the line on which the cursor sits.", 71, "c:\\4ed\\code\\4coder_auto_indent.cpp", 34, 652 }, { PROC_LINKS(write_block, 0), "write_block", 11, "At the cursor, insert a block comment.", 38, "c:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 103 }, { PROC_LINKS(write_character, 0), "write_character", 15, "Inserts whatever character was used to trigger this command.", 60, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 67 }, diff --git a/4coder_helper.h b/4coder_helper.h index c1126050..c8a06f32 100644 --- a/4coder_helper.h +++ b/4coder_helper.h @@ -102,15 +102,6 @@ struct Sort_Pair_i32{ i32 key; }; -//////////////////////////////// - -struct Buffer_Insertion -{ - Application_Links *app; - Buffer_ID buffer; - i32 at; -}; - #endif // BOTTOM diff --git a/4coder_insertion.cpp b/4coder_insertion.cpp index ac0e103a..15ca5263 100644 --- a/4coder_insertion.cpp +++ b/4coder_insertion.cpp @@ -13,26 +13,77 @@ begin_buffer_insertion_at(Application_Links *app, Buffer_ID buffer_id, i32 at){ return(result); } +static Buffer_Insertion +begin_buffer_insertion_at_buffered(Application_Links *app, Buffer_ID buffer_id, i32 at, Partition *part){ + Buffer_Insertion result = begin_buffer_insertion_at(app, buffer_id, at); + result.buffering = true; + result.part = part; + result.temp = begin_temp_memory(part); + return(result); +} + +#if 0 static Buffer_Summary get_active_buffer(Application_Links *app, Access_Flag access){ View_Summary view = get_active_view(app, access); Buffer_Summary result = get_buffer(app, view.buffer_id, access); return(result); } +#endif static Buffer_Insertion begin_buffer_insertion(Application_Links *app){ - View_Summary view = get_active_view(app, AccessAll); - Buffer_Insertion result = begin_buffer_insertion_at(app, view.buffer_id, view.cursor.pos); + View_ID view = 0; + get_active_view(app, AccessAll, &view); + Buffer_ID buffer = 0; + view_get_buffer(app, view, AccessAll, &buffer); + i32 cursor_pos = 0; + view_get_cursor_pos(app, view, &cursor_pos); + Buffer_Insertion result = begin_buffer_insertion_at(app, buffer, cursor_pos); return(result); } static void -insert_string(Buffer_Insertion *insertion, String string){ +insert_string__no_buffering(Buffer_Insertion *insertion, String string){ buffer_replace_range(insertion->app, insertion->buffer, insertion->at, insertion->at, string); insertion->at += string.size; } +static void +insert__flush(Buffer_Insertion *insertion){ + Partition *part = insertion->part; + i32 pos = insertion->temp.pos; + String string = make_string(part->base + pos, part->pos - pos); + insert_string__no_buffering(insertion, string); + end_temp_memory(insertion->temp); +} + +static char* +insert__reserve(Buffer_Insertion *insertion, i32 size){ + char *space = push_array(insertion->part, char, size); + if (space == 0){ + insert__flush(insertion); + space = push_array(insertion->part, char, size); + } + return(space); +} + +static void +insert_string(Buffer_Insertion *insertion, String string){ + if (!insertion->buffering){ + insert_string__no_buffering(insertion, string); + } + else{ + char *space = insert__reserve(insertion, string.size); + if (space != 0){ + memcpy(space, string.str, string.size); + } + else{ + insert_string__no_buffering(insertion, string); + } + } +} + static i32 insertf(Buffer_Insertion *insertion, char *format, ...){ Arena *arena = context_get_arena(insertion->app); @@ -48,8 +99,7 @@ insertf(Buffer_Insertion *insertion, char *format, ...){ static void insertc(Buffer_Insertion *insertion, char C){ - buffer_replace_range(insertion->app, insertion->buffer, insertion->at, insertion->at, make_string(&C, 1)); - insertion->at += 1; + insert_string(insertion, make_string(&C, 1)); } static b32 diff --git a/4coder_insertion.h b/4coder_insertion.h new file mode 100644 index 00000000..ec8b9cf6 --- /dev/null +++ b/4coder_insertion.h @@ -0,0 +1,22 @@ +/* + * Serial inserts helpers + */ + +// TOP + +#if !defined(FRED_INSERTION_H) +#define FRED_INSERTION_H + +struct Buffer_Insertion{ + Application_Links *app; + Buffer_ID buffer; + i32 at; + b32 buffering; + Partition *part; + Temp_Memory temp; +}; + +#endif + +// BOTTOM + diff --git a/4coder_search.cpp b/4coder_search.cpp index 9dd4dd46..d0ed218c 100644 --- a/4coder_search.cpp +++ b/4coder_search.cpp @@ -168,7 +168,7 @@ seek_potential_match(Application_Links *app, Search_Range *range, Search_Key key Buffer_Seek_String_Flags flags = 0 | OptFlag(case_insensitive, BufferSeekString_CaseInsensitive) | OptFlag(!forward, BufferSeekString_Backward); - result->buffer = get_buffer(app, range->buffer, AccessAll); + result->buffer = range->buffer; int32_t best_pos = -1; if (forward){ @@ -178,7 +178,7 @@ seek_potential_match(Application_Links *app, Search_Range *range, Search_Key key for (int32_t i = 0; i < key.count; ++i){ String word = key.words[i]; int32_t new_pos = -1; - buffer_seek_string(app, result->buffer.buffer_id, start_pos, end_pos, range->start, word.str, word.size, &new_pos, flags); + buffer_seek_string(app, result->buffer, start_pos, end_pos, range->start, word.str, word.size, &new_pos, flags); if (new_pos >= 0){ if (forward){ @@ -197,11 +197,11 @@ seek_potential_match(Application_Links *app, Search_Range *range, Search_Key key result->start = best_pos; } -static int32_t -buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ +static i32 +buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_ID buffer_id, int32_t pos){ char space[1024]; Stream_Chunk chunk = {}; - if (init_stream_chunk(&chunk, app, buffer->buffer_id, pos, space, sizeof(space))){ + if (init_stream_chunk(&chunk, app, buffer_id, pos, space, sizeof(space))){ int32_t still_looping = true; do{ for (; pos < chunk.end; ++pos){ @@ -234,7 +234,7 @@ match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Ma { char prev = ' '; if (char_is_alpha_numeric_utf8(word.str[0])){ - prev = buffer_get_char(app, result.buffer.buffer_id, result.start - 1); + prev = buffer_get_char(app, result.buffer, result.start - 1); } if (!char_is_alpha_numeric_utf8(prev)){ @@ -242,7 +242,7 @@ match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Ma if (result.end <= end_pos){ char next = ' '; if (char_is_alpha_numeric_utf8(word.str[word.size-1])){ - next = buffer_get_char(app, result.buffer.buffer_id, result.end); + next = buffer_get_char(app, result.buffer, result.end); } if (!char_is_alpha_numeric_utf8(next)){ @@ -258,11 +258,9 @@ match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Ma case SearchFlag_MatchWordPrefix: { - char prev = buffer_get_char(app, result.buffer.buffer_id, result.start - 1); + char prev = buffer_get_char(app, result.buffer, result.start - 1); if (!char_is_alpha_numeric_utf8(prev)){ - result.end = - buffer_seek_alpha_numeric_end(app, &result.buffer, result.start); - + result.end = buffer_seek_alpha_numeric_end(app, result.buffer, result.start); if (result.end <= end_pos){ result.found_match = true; found_match = FindResult_FoundMatch; @@ -484,42 +482,44 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){ // static void -initialize_generic_search_all_buffers(Application_Links *app, Heap *heap, String *strings, int32_t count, Search_Range_Flag match_flags, int32_t *skip_buffers, int32_t skip_buffer_count, Search_Set *set, Search_Iter *iter){ +initialize_generic_search_all_buffers(Application_Links *app, Heap *heap, String *strings, i32 count, Search_Range_Flag match_flags, Buffer_ID *skip_buffers, i32 skip_buffer_count, Search_Set *set, Search_Iter *iter){ memset(set, 0, sizeof(*set)); memset(iter, 0, sizeof(*iter)); Search_Key key = {}; - int32_t sizes[ArrayCount(key.words)]; + i32 sizes[ArrayCount(key.words)]; memset(sizes, 0, sizeof(sizes)); if (count > ArrayCount(key.words)){ count = ArrayCount(key.words); } - for (int32_t i = 0; i < count; ++i){ + for (i32 i = 0; i < count; ++i){ sizes[i] = strings[i].size; } // TODO(allen): Why on earth am I allocating these separately in this case? Upgrade to just use the string array on the stack! search_key_alloc(heap, &key, sizes, count); - for (int32_t i = 0; i < count; ++i){ + for (i32 i = 0; i < count; ++i){ copy(&key.words[i], strings[i]); } search_iter_init(iter, key); - int32_t buffer_count = get_buffer_count(app); + i32 buffer_count = get_buffer_count(app); search_set_init(heap, set, buffer_count); Search_Range *ranges = set->ranges; - View_Summary view = get_active_view(app, AccessProtected); - Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected); + View_ID view = 0; + get_active_view(app, AccessProtected, &view); + Buffer_ID buffer = 0; + view_get_buffer(app, view, AccessProtected, &buffer); - int32_t j = 0; - if (buffer.exists){ + i32 j = 0; + if (buffer_exists(app, buffer)){ b32 skip = false; - for (int32_t i = 0; i < skip_buffer_count; ++i){ - if (buffer.buffer_id == skip_buffers[i]){ + for (i32 i = 0; i < skip_buffer_count; ++i){ + if (buffer == skip_buffers[i]){ skip = true; break; } @@ -528,35 +528,39 @@ initialize_generic_search_all_buffers(Application_Links *app, Heap *heap, String if (!skip){ ranges[j].type = SearchRange_FrontToBack; ranges[j].flags = match_flags; - ranges[j].buffer = buffer.buffer_id; + ranges[j].buffer = buffer; ranges[j].start = 0; - ranges[j].size = buffer.size; + buffer_get_size(app, buffer, &ranges[j].size); ++j; } } - for (Buffer_Summary buffer_it = get_buffer_first(app, AccessAll); - buffer_it.exists; - get_buffer_next(app, &buffer_it, AccessAll)){ - if (buffer_it.buffer_id == buffer.buffer_id){ + Buffer_ID buffer_it = 0; + for (get_buffer_next(app, 0, AccessAll, &buffer_it); + buffer_exists(app, buffer_it); + get_buffer_next(app, buffer_it, AccessAll, &buffer_it)){ + if (buffer_it == buffer){ continue; } b32 skip = false; - for (int32_t i = 0; i < skip_buffer_count; ++i){ - if (buffer_it.buffer_id == skip_buffers[i]){ + for (i32 i = 0; i < skip_buffer_count; ++i){ + if (buffer_it == skip_buffers[i]){ skip = true; break; } } if (!skip){ - if (buffer_it.buffer_name[0] != '*'){ + char first_char = 0; + String str = make_string_cap(&first_char, 0, 1); + buffer_get_unique_buffer_name(app, buffer_it, &str, 0); + if (first_char != '*'){ ranges[j].type = SearchRange_FrontToBack; ranges[j].flags = match_flags; - ranges[j].buffer = buffer_it.buffer_id; + ranges[j].buffer = buffer_it; ranges[j].start = 0; - ranges[j].size = buffer_it.size; + buffer_get_size(app, buffer_it, &ranges[j].size); ++j; } } @@ -568,22 +572,42 @@ initialize_generic_search_all_buffers(Application_Links *app, Heap *heap, String //////////////////////////////// +static String search_name = make_lit_string("*search*"); + +// TODO(allen): can this get merged with the insertion stuff??? +struct Buffered_Printing{ + Partition *part; + Temp_Memory temp; + Buffer_ID buffer; + i32 pos; +}; + +static Buffered_Printing +make_buffered_print(Application_Links *app, Partition *part, Buffer_ID buffer){ + Buffered_Printing buffered_print = {}; + buffered_print.part = part; + buffered_print.temp = begin_temp_memory(part); + buffered_print.buffer = buffer; + buffer_get_size(app, buffer, &buffered_print.pos); + return(buffered_print); +} + static void -buffered_print_flush(Application_Links *app, Partition *part, Temp_Memory temp, Buffer_Summary *output_buffer){ - int32_t size = output_buffer->size; - int32_t write_size = part->pos - temp.pos; - char *str = part->base + temp.pos; - buffer_replace_range(app, output_buffer, size, size, str, write_size); +buffered_print_flush(Application_Links *app, Buffered_Printing *out){ + i32 write_size = out->part->pos - out->temp.pos; + char *str = out->part->base + out->temp.pos; + buffer_replace_range(app, out->buffer, out->pos, out->pos, make_string(str, write_size)); + out->pos += write_size; + end_temp_memory(out->temp); } static char* -buffered_memory_reserve(Application_Links *app, Partition *part, Temp_Memory temp, Buffer_Summary *output_buffer, int32_t length, b32 *did_flush){ - char *mem = push_array(part, char, length); +buffered_memory_reserve(Application_Links *app, Buffered_Printing *out, i32 length, b32 *did_flush){ + char *mem = push_array(out->part, char, length); *did_flush = false; if (mem == 0){ - buffered_print_flush(app, part, temp, output_buffer); - end_temp_memory(temp); - mem = push_array(part, char, length); + buffered_print_flush(app, out); + mem = push_array(out->part, char, length); *did_flush = true; } Assert(mem != 0); @@ -591,73 +615,70 @@ buffered_memory_reserve(Application_Links *app, Partition *part, Temp_Memory tem } static char* -buffered_memory_reserve(Application_Links *app, Partition *part, Temp_Memory temp, Buffer_Summary *output_buffer, int32_t length){ +buffered_memory_reserve(Application_Links *app, Buffered_Printing *out, i32 length){ b32 ignore; - return(buffered_memory_reserve(app, part, temp, output_buffer, length, &ignore)); + return(buffered_memory_reserve(app, out, length, &ignore)); } -static int32_t -buffered_print_buffer_length(Partition *part, Temp_Memory temp){ - return(part->pos - temp.pos); +static i32 +buffered_print_buffer_length(Buffered_Printing *out){ + return(out->part->pos - out->temp.pos); } -static String search_name = make_lit_string("*search*"); - static void list__parameters_buffer(Application_Links *app, Heap *heap, Partition *scratch, - String *strings, int32_t count, Search_Range_Flag match_flags, + String *strings, i32 count, Search_Range_Flag match_flags, Buffer_ID search_buffer_id){ - Buffer_Summary search_buffer = get_buffer(app, search_buffer_id, AccessAll); - // Setup the search buffer for 'init' mode - buffer_set_setting(app, &search_buffer, BufferSetting_ReadOnly, true); - buffer_set_setting(app, &search_buffer, BufferSetting_RecordsHistory, false); + buffer_set_setting(app, search_buffer_id, BufferSetting_ReadOnly, true); + buffer_set_setting(app, search_buffer_id, BufferSetting_RecordsHistory, false); // Initialize a generic search all buffers Search_Set set = {}; Search_Iter iter = {}; - initialize_generic_search_all_buffers(app, heap, strings, count, match_flags, &search_buffer.buffer_id, 1, &set, &iter); + initialize_generic_search_all_buffers(app, heap, strings, count, match_flags, &search_buffer_id, 1, &set, &iter); // List all locations into search buffer Temp_Memory all_temp = begin_temp_memory(scratch); Partition line_part = part_sub_part(scratch, (4 << 10)); - Temp_Memory temp = begin_temp_memory(scratch); + // Setup buffered output + Buffered_Printing out = make_buffered_print(app, scratch, search_buffer_id); + Buffer_ID prev_match_id = 0; b32 no_matches = true; for (Search_Match match = search_next_match(app, &set, &iter); match.found_match; match = search_next_match(app, &set, &iter)){ Partial_Cursor word_pos = {}; - if (buffer_compute_cursor(app, &match.buffer, seek_pos(match.start), &word_pos)){ - if (prev_match_id != match.buffer.buffer_id){ + if (buffer_compute_cursor(app, match.buffer, seek_pos(match.start), &word_pos)){ + if (prev_match_id != match.buffer){ if (prev_match_id != 0){ - char *newline = buffered_memory_reserve(app, scratch, temp, &search_buffer, 1); + char *newline = buffered_memory_reserve(app, &out, 1); *newline = '\n'; } - prev_match_id = match.buffer.buffer_id; + prev_match_id = match.buffer; } - char *file_name = match.buffer.buffer_name; - int32_t file_len = match.buffer.buffer_name_len; + char file_name_space[256]; + String file_name = make_fixed_width_string(file_name_space); + buffer_get_file_name(app, match.buffer, &file_name, 0); - int32_t line_num_len = int_to_str_size(word_pos.line); - int32_t column_num_len = int_to_str_size(word_pos.character); + i32 line_num_len = int_to_str_size(word_pos.line); + i32 column_num_len = int_to_str_size(word_pos.character); Temp_Memory line_temp = begin_temp_memory(&line_part); Partial_Cursor line_start_cursor = {}; Partial_Cursor line_one_past_last_cursor = {}; String full_line_str = {}; - if (read_line(app, &line_part, match.buffer.buffer_id, word_pos.line, &full_line_str, &line_start_cursor, &line_one_past_last_cursor)){ + if (read_line(app, &line_part, match.buffer, word_pos.line, &full_line_str, &line_start_cursor, &line_one_past_last_cursor)){ String line_str = skip_chop_whitespace(full_line_str); - b32 flushed = false; - int32_t str_len = file_len + 1 + line_num_len + 1 + column_num_len + 1 + 1 + line_str.size + 1; - char *spare = buffered_memory_reserve(app, scratch, temp, &search_buffer, str_len, &flushed); + i32 str_len = file_name.size + 1 + line_num_len + 1 + column_num_len + 1 + 1 + line_str.size + 1; + char *spare = buffered_memory_reserve(app, &out, str_len); - search_buffer = get_buffer(app, search_buffer_id, AccessAll); String out_line = make_string_cap(spare, 0, str_len); - append_ss(&out_line, make_string(file_name, file_len)); + append_ss(&out_line, file_name); append_s_char(&out_line, ':'); append_int_to_str(&out_line, word_pos.line); append_s_char(&out_line, ':'); @@ -676,12 +697,12 @@ list__parameters_buffer(Application_Links *app, Heap *heap, Partition *scratch, if (no_matches){ char no_matches_message[] = "no matches\n"; - int32_t no_matches_message_length = sizeof(no_matches_message) - 1; - char *no_matches_message_out = buffered_memory_reserve(app, scratch, temp, &search_buffer, no_matches_message_length); + i32 no_matches_message_length = sizeof(no_matches_message) - 1; + char *no_matches_message_out = buffered_memory_reserve(app, &out, no_matches_message_length); memcpy(no_matches_message_out, no_matches_message, no_matches_message_length); } - buffered_print_flush(app, scratch, temp, &search_buffer); + buffered_print_flush(app, &out); end_temp_memory(all_temp); @@ -690,7 +711,7 @@ list__parameters_buffer(Application_Links *app, Heap *heap, Partition *scratch, } static void -list__parameters(Application_Links *app, Heap *heap, Partition *scratch, String *strings, int32_t count, +list__parameters(Application_Links *app, Heap *heap, Partition *scratch, String *strings, i32 count, Search_Range_Flag match_flags, View_Summary default_target_view){ // Open the search buffer Buffer_ID search_buffer_id = create_or_switch_to_buffer_by_name(app, search_name.str, search_name.size, default_target_view); @@ -721,8 +742,7 @@ list_query__parameters(Application_Links *app, Heap *heap, Partition *scratch, char space[1024]; String str = get_query_string(app, "List Locations For: ", space, sizeof(space)); if (str.size > 0){ - list_single__parameters(app, heap, scratch, str, substrings, case_insensitive, - default_target_view); + list_single__parameters(app, heap, scratch, str, substrings, case_insensitive, default_target_view); } } @@ -736,8 +756,7 @@ list_identifier__parameters(Application_Links *app, Heap *heap, Partition *scrat char space[512]; String str = get_token_or_word_under_pos(app, &buffer, view.cursor.pos, space, sizeof(space)); if (str.size > 0){ - list_single__parameters(app, heap, scratch, str, substrings, case_insensitive, - default_target_view); + list_single__parameters(app, heap, scratch, str, substrings, case_insensitive, default_target_view); } } @@ -749,8 +768,7 @@ list_selected_range__parameters(Application_Links *app, Heap *heap, Partition *s Temp_Memory temp = begin_temp_memory(scratch); String str = get_string_in_view_range(app, scratch, &view); if (str.size > 0){ - list_single__parameters(app, heap, scratch, str, substrings, case_insensitive, - default_target_view); + list_single__parameters(app, heap, scratch, str, substrings, case_insensitive, default_target_view); } end_temp_memory(temp); } @@ -762,7 +780,7 @@ list_type_definition__parameters(Application_Links *app, Heap *heap, Partition * Temp_Memory temp = begin_temp_memory(scratch); String match_strings[9]; - int32_t i = 0; + i32 i = 0; match_strings[i++] = string_push_f(scratch, "struct %.*s{" , str.size, str.str); match_strings[i++] = string_push_f(scratch, "struct %.*s\n{", str.size, str.str); match_strings[i++] = string_push_f(scratch, "struct %.*s {" , str.size, str.str); @@ -885,7 +903,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with // NOTE(allen): I just do this because this command is a lot of work // and there is no point in doing any of it if nothing will happen anyway. if (buffer.exists){ - int32_t do_init = false; + i32 do_init = false; Managed_Scope scope = view_get_managed_scope(app, view.view_id); @@ -899,10 +917,10 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with do_init = true; } - int32_t word_end = 0; - int32_t word_start = 0; - int32_t cursor_pos = 0; - int32_t size = 0; + i32 word_end = 0; + i32 word_start = 0; + i32 cursor_pos = 0; + i32 size = 0; if (do_init){ // NOTE(allen): Get the range where the @@ -914,7 +932,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with char space[1024]; Stream_Chunk chunk = {}; if (init_stream_chunk(&chunk, app, buffer.buffer_id, cursor_pos, space, sizeof(space))){ - int32_t still_looping = true; + i32 still_looping = true; do{ for (; cursor_pos >= chunk.start; --cursor_pos){ char c = chunk.data[cursor_pos]; @@ -947,7 +965,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with search_iter_init(&complete_state.iter, key); // NOTE(allen): Initialize the set of ranges to be searched. - int32_t buffer_count = get_buffer_count(app); + i32 buffer_count = get_buffer_count(app); search_set_init(&global_heap, &complete_state.set, buffer_count); Search_Range *ranges = complete_state.set.ranges; @@ -959,7 +977,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with ranges[0].mid_start = word_start; ranges[0].mid_size = size; - int32_t j = 1; + i32 j = 1; for (Buffer_Summary buffer_it = get_buffer_first(app, AccessAll); buffer_it.exists; get_buffer_next(app, &buffer_it, AccessAll)){ @@ -991,7 +1009,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with // NOTE(allen): Iterate through matches. if (size > 0){ for (;;){ - int32_t match_size = 0; + i32 match_size = 0; Search_Match match = search_next_match(app, &complete_state.set, &complete_state.iter); if (match.found_match){ @@ -999,7 +1017,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with Temp_Memory temp = begin_temp_memory(&global_part); char *spare = push_array(&global_part, char, match_size); - buffer_read_range(app, &match.buffer, match.start, match.end, spare); + buffer_read_range(app, match.buffer, match.start, match.end, spare); if (search_hit_add(&global_heap, &complete_state.hits, &complete_state.str, spare, match_size)){ buffer_replace_range(app, &buffer, word_start, word_end, spare, match_size); diff --git a/4coder_search.h b/4coder_search.h index 2d8d5b91..d8fb14ba 100644 --- a/4coder_search.h +++ b/4coder_search.h @@ -36,9 +36,9 @@ enum{ }; struct Search_Range{ - i32 type; - u32 flags; - i32 buffer; + Search_Range_Type type; + Search_Range_Flag flags; + Buffer_ID buffer; i32 start; i32 size; i32 mid_start; @@ -68,7 +68,7 @@ struct Search_Iter{ }; struct Search_Match{ - Buffer_Summary buffer; + Buffer_ID buffer; i32 start; i32 end; i32 match_word_index; diff --git a/4coder_seek.cpp b/4coder_seek.cpp index 52c849e0..9e59e82f 100644 --- a/4coder_seek.cpp +++ b/4coder_seek.cpp @@ -1140,8 +1140,11 @@ CUSTOM_COMMAND_SIG(goto_end_of_file) CUSTOM_DOC("Sets the cursor to the end of the file.") { View_Summary view = get_active_view(app, AccessProtected); - Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected); - view_set_cursor(app, &view, seek_pos(buffer.size), true); + Buffer_ID buffer_id = 0; + view_get_buffer(app, view.view_id, AccessProtected, &buffer_id); + i32 size = 0; + buffer_get_size(app, buffer_id, &size); + view_set_cursor(app, &view, seek_pos(size), true); no_mark_snap_to_cursor_if_shift(app, view.view_id); } diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index ceec5016..a5dcbbd1 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -623,7 +623,6 @@ This call begins a loop across all the buffers. If the buffer returned does not exist, the loop is finished. Buffers should not be killed durring a buffer loop. ) -DOC_SEE(Buffer_Summary) DOC_SEE(Access_Flag) DOC_SEE(get_buffer_next) */{ @@ -645,16 +644,15 @@ DOC_SEE(get_buffer_next) API_EXPORT b32 Get_Buffer_Next(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_ID *buffer_id_out) /* -DOC_PARAM(buffer, The Buffer_Summary pointed to by buffer is iterated to the next buffer or to a null summary if this is the last buffer.) +DOC_PARAM(buffer, The pointed to by buffer is iterated to the next buffer or to a null summary if this is the last buffer.) DOC_PARAM(access, The access parameter determines what levels of protection this call can access. The buffer outputted will be the next buffer that is accessible.) DOC( -This call steps a Buffer_Summary to the next buffer in the global buffer order. +This call steps a to the next buffer in the global buffer order. The global buffer order is kept roughly in the order of most recently used to least recently used. If the buffer outputted does not exist, the loop is finished. Buffers should not be killed or created durring a buffer loop. ) -DOC_SEE(Buffer_Summary) DOC_SEE(Access_Flag) DOC_SEE(get_buffer_first) */{ @@ -676,30 +674,6 @@ DOC_SEE(get_buffer_first) return(result); } -#if 0 -// TODO(allen): redocument -//API_EXPORT b32 -Get_Buffer_Summary(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_Summary *buffer_summary_out) -/* -DOC_PARAM(buffer_id, The parameter buffer_id specifies which buffer to try to get.) -DOC_PARAM(access, The access parameter determines what levels of protection this call can access.) -DOC_RETURN(This call returns a summary that describes the indicated buffer if it exists and is accessible.) -DOC_SEE(Buffer_Summary) -DOC_SEE(Access_Flag) -DOC_SEE(Buffer_ID) -*/{ - Models *models = (Models*)app->cmd_context; - Working_Set *working_set = &models->working_set; - Editing_File *file = working_set_get_active_file(working_set, buffer_id); - b32 result = false; - if (buffer_api_check_file(file, access)){ - fill_buffer_summary(buffer_summary_out, file, working_set); - result = true; - } - return(result); -} -#endif - // TODO(allen): redocument API_EXPORT b32 Get_Buffer_By_Name(Application_Links *app, String name, Access_Flag access, Buffer_ID *buffer_id_out) @@ -712,7 +686,6 @@ DOC_RETURN(This call returns a summary that describes the indicated buffer if it DOC(This call searches the buffers by their buffer name. The buffer name is the short name in the file bar. The name must match exactly including any alterations put on the buffer name to avoid duplicates.) DOC_SEE(get_buffer_by_file_name) -DOC_SEE(Buffer_Summary) DOC_SEE(Access_Flag) */{ Models *models = (Models*)app->cmd_context; @@ -738,7 +711,6 @@ DOC_RETURN(This call returns a summary that describes the indicated buffer if it DOC(This call searches the buffers by their canonicalized file names. Not all buffers have file names, only buffers that are tied to files. For instance *scratch* does not have a file name. Every file has one canonicalized file name. For instance on windows this involves converting w:/a/b into W:\a\b. If the name passed is not canonicalized a canonicalized copy is made first. This includes turning relative paths to files that exist into full paths. So the passed in name can be relative to the working directory.) DOC_SEE(get_buffer_by_name) -DOC_SEE(Buffer_Summary) DOC_SEE(Access_Flag) */ { @@ -1953,6 +1925,19 @@ View_Get_Buffer(Application_Links *app, View_ID view_id, Access_Flag access, Buf return(result); } +API_EXPORT b32 +View_Get_Cursor_Pos(Application_Links *app, View_ID view_id, i32 *pos_out){ + Models *models = (Models*)app->cmd_context; + View *view = imp_get_view(models, view_id); + b32 result = false; + if (view_api_check_view(view)){ + File_Edit_Positions edit_pos = view_get_edit_pos(view); + *pos_out = edit_pos.cursor_pos; + result = true; + } + return(result); +} + API_EXPORT b32 View_Get_Panel(Application_Links *app, View_ID view_id, Panel_ID *panel_id_out){ Models *models = (Models*)app->cmd_context; @@ -4007,7 +3992,7 @@ API_EXPORT b32 Get_Face_ID(Application_Links *app, Buffer_ID buffer_id, Face_ID *face_id_out) /* DOC_PARAM(buffer, The buffer from which to get a face id. If NULL gets global face id.) -DOC(Retrieves a face id if buffer is a valid Buffer_Summary. If buffer is set to NULL, the parameter is ignored and the global default face is returned.) +DOC(Retrieves a face id if buffer is a valid If buffer is set to NULL, the parameter is ignored and the global default face is returned.) DOC_RETURN(On success a valid Face_ID, otherwise returns zero.) */ {