From 4e593305a8ce81b0110ed9dfcfbfcd9a44feed8b Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 14 May 2021 20:10:22 -0700 Subject: [PATCH] make sure CR does not appear in result from push_buffer_line --- custom/4coder_helper.cpp | 19 +++++++++++++++---- custom/generated/command_metadata.h | 12 ++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/custom/4coder_helper.cpp b/custom/4coder_helper.cpp index 395721b9..f8a5ac63 100644 --- a/custom/4coder_helper.cpp +++ b/custom/4coder_helper.cpp @@ -373,7 +373,7 @@ get_line_start_pos(Application_Links *app, Buffer_ID buffer, i64 line_number){ return(get_line_side_pos(app, buffer, line_number, Side_Min)); } -// NOTE(allen): The position returned has the index of the terminating newline character, +// NOTE(allen): The position returned has the index of the terminating LF. // not one past the newline character. function Buffer_Cursor get_line_end(Application_Links *app, Buffer_ID buffer, i64 line_number){ @@ -384,7 +384,7 @@ get_line_end_pos(Application_Links *app, Buffer_ID buffer, i64 line_number){ return(get_line_side_pos(app, buffer, line_number, Side_Max)); } -// NOTE(allen): The range returned does not include the terminating newline character +// NOTE(allen): The range returned does not include the terminating LF or CRLF function Range_Cursor get_line_range(Application_Links *app, Buffer_ID buffer, i64 line_number){ b32 success = false; @@ -402,7 +402,7 @@ get_line_range(Application_Links *app, Buffer_ID buffer, i64 line_number){ return(result); } -// NOTE(allen): The range returned does not include the terminating newline character +// NOTE(allen): The range returned does not include the terminating LF or CRLF function Range_i64 get_line_pos_range(Application_Links *app, Buffer_ID buffer, i64 line_number){ Range_Cursor range = get_line_range(app, buffer, line_number); @@ -1025,7 +1025,18 @@ push_token_lexeme(Application_Links *app, Arena *arena, Buffer_ID buffer, Token function 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))); + // NOTE(allen): 4coder flaw + // The system for dealing with CRLF vs LF is too sloppy. There is no way to + // avoid returning the CR from this function by adjusting the more + // fundamental position getter functions without risking breaking some of + // the users of those functions. It seems okay to just chop the CR + // off here - but it's clearly sloppy. Oh well - we're in duct tape mode + // these days anyways. + String_Const_u8 string = push_buffer_range(app, arena, buffer, get_line_pos_range(app, buffer, line_number)); + for (;string.size > 0 && string.str[string.size - 1] == '\r';){ + string.size -= 1; + } + return(string); } function String_Const_u8 diff --git a/custom/generated/command_metadata.h b/custom/generated/command_metadata.h index 0fe9cc68..cc26015d 100644 --- a/custom/generated/command_metadata.h +++ b/custom/generated/command_metadata.h @@ -343,8 +343,8 @@ static Command_Metadata fcoder_metacmd_table[268] = { { 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, 846 }, { PROC_LINKS(go_to_user_directory, 0), false, "go_to_user_directory", 20, "Go to the 4coder user directory", 31, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1653 }, -{ 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, 2247 }, -{ 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, 2255 }, +{ 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, 2258 }, +{ 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, 2266 }, { 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 }, @@ -493,10 +493,10 @@ static Command_Metadata fcoder_metacmd_table[268] = { { 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, 1427 }, { 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, 1109 }, { 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, 1121 }, -{ 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, 2235 }, -{ 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, 2223 }, -{ 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, 2241 }, -{ 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, 2229 }, +{ 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, 2246 }, +{ 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, 2234 }, +{ 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, 2252 }, +{ 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, 2240 }, { 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, 541 }, { 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 },