diff --git a/4coder_API.html b/4coder_API.html index bd27eb17..2751c6c2 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -147,7 +147,7 @@ beginning or end of different types of words.

AutoIndent_FullTokens = 0x8
If AutoIndent_FullTokens is set, then the set of lines that are indented is automatically expanded so that any token spanning multiple lines gets entirely indented.


§3.4.21: Set_Buffer_Flag

enum Set_Buffer_Flag;
Description
A Set_Buffer_Flag field specifies the behavior of an operation that sets the buffer of a view.

Values
SetBuffer_KeepOriginalGUI = 0x1
If SetBuffer_KeepOriginalGUI then when the file is set, the view will not switch to it if some other GUI was currently up, otherwise any GUI that is up is closed and the view - switches to the file.


§3.4.22: Input_Type_Flag

enum Input_Type_Flag;
Description
A Input_Type_Flag field specifies a set of input event types.

Values
EventOnAnyKey = 0x1
If EventOnAnyKey is set, all keyboard events are included in the set.

EventOnEsc = 0x2
If EventOnEsc is set, any press of the escape key is included in the set.

EventOnLeftButton = 0x4
If EventOnLeftButton is set, left clicks are included in the set.

EventOnRightButton = 0x8
If EventOnRightButton is set, right clicks are included in the set.

EventOnWheel = 0x10
If EventOnWheel is set, any wheel movement is included in the set.

EventOnButton = (EventOnLeftButton | EventOnRightButton | EventOnWheel)
If EventOnButton is set, all mouse button events are included in the set.

EventOnMouseMove = 0x20
This is not totally implemented yet.

EventOnMouse = (EventOnButton | EventOnMouseMove)
This is not totally implemented yet.

EventAll = 0xFF
EventAll is a catch all name for including all possible events in the set.


§3.4.23: Mouse_Cursor_Show_Type

enum Mouse_Cursor_Show_Type;
Description
A Mouse_Cursor_Show_Type value specifes a mode for 4coder to handle the mouse cursor.

Values
MouseCursorShow_Never
The MouseCursorShow_Never mode never shows the cursor.

MouseCursorShow_Always
The MouseCursorShow_Never mode always shows the cursor.


§3.4.24: Buffer_Seek_Type

enum Buffer_Seek_Type;
Description
The Buffer_Seek_Type is is used in a Buffer_Seek to identify which + switches to the file.


§3.4.22: Input_Type_Flag

enum Input_Type_Flag;
Description
A Input_Type_Flag field specifies a set of input event types.

Values
EventOnAnyKey = 0x1
If EventOnAnyKey is set, all keyboard events are included in the set.

EventOnEsc = 0x2
If EventOnEsc is set, any press of the escape key is included in the set.

EventOnLeftButton = 0x4
If EventOnLeftButton is set, left clicks are included in the set.

EventOnRightButton = 0x8
If EventOnRightButton is set, right clicks are included in the set.

EventOnWheel = 0x10
If EventOnWheel is set, any wheel movement is included in the set.

EventOnMouseMove = 0x20
This is not totally implemented yet.

EventOnButton = (EventOnLeftButton | EventOnRightButton | EventOnWheel)
If EventOnButton is set, all mouse button events are included in the set.

EventOnMouse = (EventOnButton | EventOnMouseMove)
This is not totally implemented yet.

EventAll = 0xFF
EventAll is a catch all name for including all possible events in the set.


§3.4.23: Mouse_Cursor_Show_Type

enum Mouse_Cursor_Show_Type;
Description
A Mouse_Cursor_Show_Type value specifes a mode for 4coder to handle the mouse cursor.

Values
MouseCursorShow_Never
The MouseCursorShow_Never mode never shows the cursor.

MouseCursorShow_Always
The MouseCursorShow_Never mode always shows the cursor.


§3.4.24: Buffer_Seek_Type

enum Buffer_Seek_Type;
Description
The Buffer_Seek_Type is is used in a Buffer_Seek to identify which coordinates are suppose to be used for the seek.

Values
buffer_seek_pos
This value indicates absolute positioning where positions are measured as the number of bytes from the start of the file.

buffer_seek_wrapped_xy
This value indicates xy positioning with wrapped lines where the x and y values are in pixels.

buffer_seek_unwrapped_xy
This value indicates xy positioning with unwrapped lines where the x and y values are in pixels.

buffer_seek_line_char
This value indicates line-character, or line-column positioning. These coordinates are 1 based to match standard line numbering.

See Also
Buffer_Seek
4coder_Buffer_Positioning_System

§3.4.25: View_Split_Position

enum View_Split_Position;
Description
A View_Split_Position specifies where a new view should be placed as a result of a view split operation.

Values
ViewSplit_Top
This value indicates that the new view should be above the existing view.

ViewSplit_Bottom
This value indicates that the new view should be below the existing view.

ViewSplit_Left
This value indicates that the new view should be left of the existing view.

ViewSplit_Right
This value indicates that the new view should be right of the existing view.


§3.4.26: Generic_Command

union Generic_Command {
Command_ID cmdid;
Custom_Command_Function * command;
};
Description
Generic_Command acts as a name for a command, and can name an internal command or a custom command.

Fields
cmdid
If this Generic_Command represents an internal command the cmdid field diff --git a/4coder_auto_indent.cpp b/4coder_auto_indent.cpp index a81e6b44..a3248568 100644 --- a/4coder_auto_indent.cpp +++ b/4coder_auto_indent.cpp @@ -183,78 +183,87 @@ find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Arra int32_t line_start, int32_t tab_width, int32_t *current_indent_out){ Cpp_Token *token = get_first_token_at_line(app, buffer, tokens, line_start); - if (token != tokens.tokens){ - --token; - for (; token > tokens.tokens; --token){ - if (!(token->flags & CPP_TFLAG_PP_BODY)){ - switch(token->type){ - case CPP_TOKEN_BRACE_OPEN: - case CPP_TOKEN_BRACE_CLOSE: - goto out_of_loop; + if (token == 0 && tokens.count == 0){ + // In this case just let the null token pointer be returned. + } + else{ + if (token == 0){ + token = tokens.tokens + (tokens.count - 1); + } + + if (token != tokens.tokens){ + --token; + for (; token > tokens.tokens; --token){ + if (!(token->flags & CPP_TFLAG_PP_BODY)){ + switch(token->type){ + case CPP_TOKEN_BRACE_OPEN: + case CPP_TOKEN_BRACE_CLOSE: + goto out_of_loop; + } } } + out_of_loop:; } - out_of_loop:; - } - - int32_t current_indent = 0; - int32_t found_safe_start_position = 0; - do{ - int32_t line = buffer_get_line_index(app, buffer, token->start); - int32_t start = buffer_get_line_start(app, buffer, line); - Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, start, tab_width); - current_indent = hard_start.indent_pos; - - Cpp_Token *start_token = get_first_token_at_line(app, buffer, tokens, line); - Cpp_Token *brace_token = token; - - if (start_token->type == CPP_TOKEN_PARENTHESE_OPEN){ - if (start_token == tokens.tokens){ - found_safe_start_position = 1; + int32_t current_indent = 0; + int32_t found_safe_start_position = 0; + do{ + int32_t line = buffer_get_line_index(app, buffer, token->start); + int32_t start = buffer_get_line_start(app, buffer, line); + + Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, start, tab_width); + current_indent = hard_start.indent_pos; + + Cpp_Token *start_token = get_first_token_at_line(app, buffer, tokens, line); + Cpp_Token *brace_token = token; + + if (start_token->type == CPP_TOKEN_PARENTHESE_OPEN){ + if (start_token == tokens.tokens){ + found_safe_start_position = 1; + } + else{ + token = start_token-1; + } } else{ - token = start_token-1; - } - } - else{ - int32_t close = 0; - - for (token = brace_token; token > start_token; --token){ - switch(token->type){ + int32_t close = 0; + + for (token = brace_token; token > start_token; --token){ + switch(token->type){ + case CPP_TOKEN_PARENTHESE_CLOSE: + case CPP_TOKEN_BRACKET_CLOSE: + case CPP_TOKEN_BRACE_CLOSE: + close = token->type; + goto out_of_loop2; + } + } + out_of_loop2:; + + switch (close){ + case 0: token = start_token; found_safe_start_position = 1; break; + case CPP_TOKEN_PARENTHESE_CLOSE: + token = seek_matching_token_backwards(tokens, token-1, + CPP_TOKEN_PARENTHESE_OPEN, + CPP_TOKEN_PARENTHESE_CLOSE); + break; + case CPP_TOKEN_BRACKET_CLOSE: + token = seek_matching_token_backwards(tokens, token-1, + CPP_TOKEN_BRACKET_OPEN, + CPP_TOKEN_BRACKET_CLOSE); + break; + case CPP_TOKEN_BRACE_CLOSE: - close = token->type; - goto out_of_loop2; + token = seek_matching_token_backwards(tokens, token-1, + CPP_TOKEN_BRACE_OPEN, + CPP_TOKEN_BRACE_CLOSE); + break; } } - out_of_loop2:; - - switch (close){ - case 0: token = start_token; found_safe_start_position = 1; break; - - case CPP_TOKEN_PARENTHESE_CLOSE: - token = seek_matching_token_backwards(tokens, token-1, - CPP_TOKEN_PARENTHESE_OPEN, - CPP_TOKEN_PARENTHESE_CLOSE); - break; - - case CPP_TOKEN_BRACKET_CLOSE: - token = seek_matching_token_backwards(tokens, token-1, - CPP_TOKEN_BRACKET_OPEN, - CPP_TOKEN_BRACKET_CLOSE); - break; - - case CPP_TOKEN_BRACE_CLOSE: - token = seek_matching_token_backwards(tokens, token-1, - CPP_TOKEN_BRACE_OPEN, - CPP_TOKEN_BRACE_CLOSE); - break; - } - } - } while(found_safe_start_position == 0); - *current_indent_out = current_indent; + } while(found_safe_start_position == 0); + *current_indent_out = current_indent; + } return(token); } @@ -288,186 +297,193 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b Cpp_Token *token_ptr = find_anchor_token(app, buffer, tokens, line_start, tab_width, &indent.current_indent); - int32_t line_index = buffer_get_line_index(app, buffer, token_ptr->start); - - if (line_index > line_start){ - line_index = line_start; - } - - int32_t next_line_start_pos = buffer_get_line_start(app, buffer, line_index+1); - - switch (token_ptr->type){ - case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += tab_width; break; - case CPP_TOKEN_BRACE_OPEN: indent.current_indent += tab_width; break; - case CPP_TOKEN_PARENTHESE_OPEN: indent.current_indent += tab_width; break; - } - - indent.previous_line_indent = indent.current_indent; - - for (;line_index < line_end;){ - Cpp_Token prev_token = *token_ptr, token = {0}; - - ++token_ptr; - if (token_ptr < tokens.tokens + tokens.count){ - token = *token_ptr; + if (token_ptr == 0){ + for (int32_t line_index = line_start; line_index < line_end; ++line_index){ + indent_marks[line_index] = 0; } - else{ - token.type = CPP_TOKEN_EOF; - token.start = buffer->size; - token.flags = 0; + } + else{ + int32_t line_index = buffer_get_line_index(app, buffer, token_ptr->start); + + if (line_index > line_start){ + line_index = line_start; } - for (;token.start >= next_line_start_pos && line_index < line_end;){ - next_line_start_pos = buffer_get_line_start(app, buffer, line_index+1); + int32_t next_line_start_pos = buffer_get_line_start(app, buffer, line_index+1); + + switch (token_ptr->type){ + case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += tab_width; break; + case CPP_TOKEN_BRACE_OPEN: indent.current_indent += tab_width; break; + case CPP_TOKEN_PARENTHESE_OPEN: indent.current_indent += tab_width; break; + } + + indent.previous_line_indent = indent.current_indent; + + for (;line_index < line_end;){ + Cpp_Token prev_token = *token_ptr, token = {0}; - int32_t this_indent = 0; - { - int32_t previous_indent = indent.previous_line_indent; + ++token_ptr; + if (token_ptr < tokens.tokens + tokens.count){ + token = *token_ptr; + } + else{ + token.type = CPP_TOKEN_EOF; + token.start = buffer->size; + token.flags = 0; + } + + for (;token.start >= next_line_start_pos && line_index < line_end;){ + next_line_start_pos = buffer_get_line_start(app, buffer, line_index+1); - int32_t this_line_start = buffer_get_line_start(app, buffer, line_index); - int32_t next_line_start = buffer_get_line_start(app, buffer, line_index+1); - - bool32 did_special_behavior = false; - - if (prev_token.start <= this_line_start && prev_token.start + prev_token.size > this_line_start){ - if (prev_token.type == CPP_TOKEN_COMMENT){ - Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, this_line_start, tab_width); - - if (exact_align){ - this_indent = indent.previous_comment_indent; - } - else{ - if (hard_start.all_whitespace){ - this_indent = previous_indent; + int32_t this_indent = 0; + { + int32_t previous_indent = indent.previous_line_indent; + + int32_t this_line_start = buffer_get_line_start(app, buffer, line_index); + int32_t next_line_start = buffer_get_line_start(app, buffer, line_index+1); + + bool32 did_special_behavior = false; + + if (prev_token.start <= this_line_start && prev_token.start + prev_token.size > this_line_start){ + if (prev_token.type == CPP_TOKEN_COMMENT){ + Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, this_line_start, tab_width); + + if (exact_align){ + this_indent = indent.previous_comment_indent; } else{ - int32_t line_pos = hard_start.char_pos - this_line_start; - this_indent = line_pos + indent.comment_shift; - if (this_indent < 0){ - this_indent = 0; + if (hard_start.all_whitespace){ + this_indent = previous_indent; + } + else{ + int32_t line_pos = hard_start.char_pos - this_line_start; + this_indent = line_pos + indent.comment_shift; + if (this_indent < 0){ + this_indent = 0; + } } } + + if (!hard_start.all_whitespace){ + if (line_index >= line_start){ + indent.previous_comment_indent = this_indent; + } + else{ + indent.previous_comment_indent = hard_start.indent_pos; + } + } + + did_special_behavior = true; } - - if (!hard_start.all_whitespace){ - if (line_index >= line_start){ - indent.previous_comment_indent = this_indent; + else if (prev_token.type == CPP_TOKEN_STRING_CONSTANT){ + this_indent = previous_indent; + did_special_behavior = true; + } + } + + if (!did_special_behavior){ + this_indent = indent.current_indent; + if (token.start < next_line_start){ + if (token.flags & CPP_TFLAG_PP_DIRECTIVE){ + this_indent = 0; } else{ - indent.previous_comment_indent = hard_start.indent_pos; - } - } - - did_special_behavior = true; - } - else if (prev_token.type == CPP_TOKEN_STRING_CONSTANT){ - this_indent = previous_indent; - did_special_behavior = true; - } - } - - if (!did_special_behavior){ - this_indent = indent.current_indent; - if (token.start < next_line_start){ - if (token.flags & CPP_TFLAG_PP_DIRECTIVE){ - this_indent = 0; - } - else{ - switch (token.type){ - case CPP_TOKEN_BRACKET_CLOSE: this_indent -= tab_width; break; - case CPP_TOKEN_BRACE_CLOSE: this_indent -= tab_width; break; - case CPP_TOKEN_BRACE_OPEN: break; - - default: - if (indent.current_indent > 0){ - if (!(prev_token.flags & CPP_TFLAG_PP_BODY) && - !(prev_token.flags & CPP_TFLAG_PP_DIRECTIVE)){ - switch (prev_token.type){ - case CPP_TOKEN_BRACKET_OPEN: - case CPP_TOKEN_BRACE_OPEN: case CPP_TOKEN_BRACE_CLOSE: - case CPP_TOKEN_SEMICOLON: case CPP_TOKEN_COLON: - case CPP_TOKEN_COMMA: case CPP_TOKEN_COMMENT: break; - default: this_indent += tab_width; + switch (token.type){ + case CPP_TOKEN_BRACKET_CLOSE: this_indent -= tab_width; break; + case CPP_TOKEN_BRACE_CLOSE: this_indent -= tab_width; break; + case CPP_TOKEN_BRACE_OPEN: break; + + default: + if (indent.current_indent > 0){ + if (!(prev_token.flags & CPP_TFLAG_PP_BODY) && + !(prev_token.flags & CPP_TFLAG_PP_DIRECTIVE)){ + switch (prev_token.type){ + case CPP_TOKEN_BRACKET_OPEN: + case CPP_TOKEN_BRACE_OPEN: case CPP_TOKEN_BRACE_CLOSE: + case CPP_TOKEN_SEMICOLON: case CPP_TOKEN_COLON: + case CPP_TOKEN_COMMA: case CPP_TOKEN_COMMENT: break; + default: this_indent += tab_width; + } } } } } } + if (this_indent < 0) this_indent = 0; + } + + if (indent.paren_nesting > 0){ + if (prev_token.type != CPP_TOKEN_PARENTHESE_OPEN){ + int32_t level = indent.paren_nesting-1; + if (level >= ArrayCount(indent.paren_anchor_indent)){ + level = ArrayCount(indent.paren_anchor_indent)-1; + } + this_indent = indent.paren_anchor_indent[level]; + } } - if (this_indent < 0) this_indent = 0; } + // Rebase the paren anchor if the first token + // after the open paren is on the next line. if (indent.paren_nesting > 0){ - if (prev_token.type != CPP_TOKEN_PARENTHESE_OPEN){ + if (prev_token.type == CPP_TOKEN_PARENTHESE_OPEN){ int32_t level = indent.paren_nesting-1; if (level >= ArrayCount(indent.paren_anchor_indent)){ level = ArrayCount(indent.paren_anchor_indent)-1; } - this_indent = indent.paren_anchor_indent[level]; + indent.paren_anchor_indent[level] = this_indent; } } - } - - // Rebase the paren anchor if the first token - // after the open paren is on the next line. - if (indent.paren_nesting > 0){ - if (prev_token.type == CPP_TOKEN_PARENTHESE_OPEN){ - int32_t level = indent.paren_nesting-1; - if (level >= ArrayCount(indent.paren_anchor_indent)){ - level = ArrayCount(indent.paren_anchor_indent)-1; - } - indent.paren_anchor_indent[level] = this_indent; - } - } - - if (line_index >= line_start){ - indent_marks[line_index] = this_indent; - } - ++line_index; - - indent.previous_line_indent = this_indent; - } - - // Update indent state. - switch (token.type){ - case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += 4; break; - case CPP_TOKEN_BRACKET_CLOSE: indent.current_indent -= 4; break; - case CPP_TOKEN_BRACE_OPEN: indent.current_indent += 4; break; - case CPP_TOKEN_BRACE_CLOSE: indent.current_indent -= 4; break; - - case CPP_TOKEN_COMMENT: - { - int32_t line = buffer_get_line_index(app, buffer, token.start); - int32_t start = buffer_get_line_start(app, buffer, line); - indent.comment_shift = (indent.current_indent - (token.start - start)); - indent.previous_comment_indent = (token.start - start); - }break; + if (line_index >= line_start){ + indent_marks[line_index] = this_indent; + } + ++line_index; + + indent.previous_line_indent = this_indent; + } - case CPP_TOKEN_PARENTHESE_OPEN: - if (!(token.flags & CPP_TFLAG_PP_BODY)){ - if (indent.paren_nesting < ArrayCount(indent.paren_anchor_indent)){ + // Update indent state. + switch (token.type){ + case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += 4; break; + case CPP_TOKEN_BRACKET_CLOSE: indent.current_indent -= 4; break; + case CPP_TOKEN_BRACE_OPEN: indent.current_indent += 4; break; + case CPP_TOKEN_BRACE_CLOSE: indent.current_indent -= 4; break; + + case CPP_TOKEN_COMMENT: + { int32_t line = buffer_get_line_index(app, buffer, token.start); int32_t start = buffer_get_line_start(app, buffer, line); - int32_t char_pos = token.start - start; - Hard_Start_Result hard_start = - buffer_find_hard_start(app, buffer, start, tab_width); - - int32_t line_pos = hard_start.char_pos - start; - - indent.paren_anchor_indent[indent.paren_nesting] = - char_pos - line_pos + indent.previous_line_indent + 1; + indent.comment_shift = (indent.current_indent - (token.start - start)); + indent.previous_comment_indent = (token.start - start); + }break; + + case CPP_TOKEN_PARENTHESE_OPEN: + if (!(token.flags & CPP_TFLAG_PP_BODY)){ + if (indent.paren_nesting < ArrayCount(indent.paren_anchor_indent)){ + int32_t line = buffer_get_line_index(app, buffer, token.start); + int32_t start = buffer_get_line_start(app, buffer, line); + int32_t char_pos = token.start - start; + + Hard_Start_Result hard_start = + buffer_find_hard_start(app, buffer, start, tab_width); + + int32_t line_pos = hard_start.char_pos - start; + + indent.paren_anchor_indent[indent.paren_nesting] = + char_pos - line_pos + indent.previous_line_indent + 1; + } + ++indent.paren_nesting; } - ++indent.paren_nesting; + break; + + case CPP_TOKEN_PARENTHESE_CLOSE: + if (!(token.flags & CPP_TFLAG_PP_BODY)){ + --indent.paren_nesting; + } + break; } - break; - - case CPP_TOKEN_PARENTHESE_CLOSE: - if (!(token.flags & CPP_TFLAG_PP_BODY)){ - --indent.paren_nesting; - } - break; } } diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 83740601..fa60fd3b 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -556,7 +556,7 @@ static int32_t buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, int32_t line){ Partial_Cursor partial_cursor; int32_t result = buffer->size; - if (line < buffer->line_count){ + if (line <= buffer->line_count){ app->buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &partial_cursor); result = partial_cursor.pos; } @@ -1676,7 +1676,7 @@ seek_token_left(Cpp_Token_Array *tokens, int32_t pos){ --token; } - return token->start; + return(token->start); } static int32_t @@ -1690,27 +1690,45 @@ seek_token_right(Cpp_Token_Array *tokens, int32_t pos){ } Cpp_Token *token = tokens->tokens + get.token_index; - return token->start + token->size; + return(token->start + token->size); +} + +static Cpp_Token_Array +buffer_get_all_tokens(Application_Links *app, Partition *part, Buffer_Summary *buffer){ + Cpp_Token_Array array = {0}; + + if (buffer->exists && buffer->is_lexed){ + array.count = app->buffer_token_count(app, buffer); + array.max_count = array.count; + array.tokens = push_array(part, Cpp_Token, array.count); + app->buffer_read_tokens(app, buffer, 0, array.count, array.tokens); + } + + return(array); } static int32_t -buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, - bool32 seek_forward, Seek_Boundary_Flag flags)/* +buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Partition *part, + int32_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags)/* DOC_PARAM(buffer, The buffer parameter specifies the buffer through which to seek.) DOC_PARAM(start_pos, The beginning position of the seek is specified by start_pos measured in absolute position.) DOC_PARAM(seek_forward, If this parameter is non-zero it indicates that the seek should move foward through the buffer.) DOC_PARAM(flags, This field specifies the types of boundaries at which the seek should stop.) + DOC_RETURN(This call returns the absolute position where the seek stopped. If the seek goes below 0 the returned value is -1. If the seek goes past the end the returned value is the size of the buffer.) + DOC_SEE(Seek_Boundary_Flag) DOC_SEE(4coder_Buffer_Positioning_System) */{ int32_t result = 0; + + // TODO(allen): reduce duplication? + Temp_Memory temp = begin_temp_memory(part); if (buffer->exists){ - // TODO(allen): reduce duplication? + int32_t pos[4]; int32_t size = buffer->size; - int32_t pos[4] = {0}; int32_t new_pos = 0; if (start_pos < 0){ @@ -1721,16 +1739,17 @@ DOC_SEE(4coder_Buffer_Positioning_System) } if (seek_forward){ - for (int32_t i = 0; i < ArrayCount(pos); ++i) pos[i] = size; + for (int32_t i = 0; i < ArrayCount(pos); ++i){ + pos[i] = size; + } - if (flags & (1)){ + if (flags & BoundaryWhitespace){ pos[0] = buffer_seek_whitespace_right(app, buffer, start_pos); } - if (flags & (1 << 1)){ + if (flags & BoundaryToken){ if (buffer->tokens_are_ready){ - Cpp_Token_Array array; - // TODO(allen): Fill this array. + Cpp_Token_Array array = buffer_get_all_tokens(app, part, buffer); pos[1] = seek_token_right(&array, start_pos); } else{ @@ -1738,32 +1757,37 @@ DOC_SEE(4coder_Buffer_Positioning_System) } } - if (flags & (1 << 2)){ + if (flags & BoundaryAlphanumeric){ pos[2] = buffer_seek_alphanumeric_right(app, buffer, start_pos); - if (flags & (1 << 3)){ + if (flags & BoundaryCamelCase){ pos[3] = buffer_seek_range_camel_right(app, buffer, start_pos, pos[2]); } } else{ - if (flags & (1 << 3)){ + if (flags & BoundaryCamelCase){ pos[3] = buffer_seek_alphanumeric_or_camel_right(app, buffer, start_pos); } } new_pos = size; for (int32_t i = 0; i < ArrayCount(pos); ++i){ - if (pos[i] < new_pos) new_pos = pos[i]; + if (pos[i] < new_pos){ + new_pos = pos[i]; + } } } else{ - if (flags & (1)){ + for (int32_t i = 0; i < ArrayCount(pos); ++i){ + pos[i] = 0; + } + + if (flags & BoundaryWhitespace){ pos[0] = buffer_seek_whitespace_left(app, buffer, start_pos); } - if (flags & (1 << 1)){ + if (flags & BoundaryToken){ if (buffer->tokens_are_ready){ - Cpp_Token_Array array; - // TODO(allen): Fill this array. + Cpp_Token_Array array = buffer_get_all_tokens(app, part, buffer); pos[1] = seek_token_left(&array, start_pos); } else{ @@ -1771,29 +1795,39 @@ DOC_SEE(4coder_Buffer_Positioning_System) } } - if (flags & (1 << 2)){ + if (flags & BoundaryAlphanumeric){ pos[2] = buffer_seek_alphanumeric_left(app, buffer, start_pos); - if (flags & (1 << 3)){ + if (flags & BoundaryCamelCase){ pos[3] = buffer_seek_range_camel_left(app, buffer, start_pos, pos[2]); } } else{ - if (flags & (1 << 3)){ + if (flags & BoundaryCamelCase){ pos[3] = buffer_seek_alphanumeric_or_camel_left(app, buffer, start_pos); } } new_pos = 0; for (int32_t i = 0; i < ArrayCount(pos); ++i){ - if (pos[i] > new_pos) new_pos = pos[i]; + if (pos[i] > new_pos){ + new_pos = pos[i]; + } } } result = new_pos; } + end_temp_memory(temp); return(result); } +static int32_t +buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, + int32_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags){ + int32_t result = buffer_boundary_seek(app, buffer, &global_part, start_pos, seek_forward, flags); + return(result); +} + static void basic_seek(Application_Links *app, int32_t seek_type, uint32_t flags){ uint32_t access = AccessProtected; diff --git a/4coder_types.h b/4coder_types.h index bcc1fe48..e415814b 100644 --- a/4coder_types.h +++ b/4coder_types.h @@ -297,11 +297,11 @@ ENUM(uint32_t, Input_Type_Flag){ EventOnRightButton = 0x8, /* DOC(If EventOnWheel is set, any wheel movement is included in the set.) */ EventOnWheel = 0x10, - /* DOC(If EventOnButton is set, all mouse button events are included in the set.) */ - EventOnButton = (EventOnLeftButton | EventOnRightButton | EventOnWheel), - /* DOC(This is not totally implemented yet.) */ EventOnMouseMove = 0x20, + + /* DOC(If EventOnButton is set, all mouse button events are included in the set.) */ + EventOnButton = (EventOnLeftButton | EventOnRightButton | EventOnWheel), /* DOC(This is not totally implemented yet.) */ EventOnMouse = (EventOnButton | EventOnMouseMove), @@ -587,21 +587,15 @@ struct Buffer_Edit{ DOC_SEE(Access_Flag) DOC_SEE(Dirty_State) */ struct Buffer_Summary{ - /* DOC( - This field indicates whether the Buffer_Summary describes a buffer that is open in 4coder. - When this field is false the summary is referred to as a "null summary". - ) */ + /* DOC(This field indicates whether the Buffer_Summary describes a buffer that is open in 4coder. + When this field is false the summary is referred to as a "null summary".) */ bool32 exists; /* DOC(If this is not a null summary, this field indicates whether the buffer has finished loading.) */ bool32 ready; - /* DOC( - If this is not a null summary this field is the id of the associated buffer. - If this is a null summary then buffer_id is 0. - ) */ + /* DOC(If this is not a null summary this field is the id of the associated buffer. + If this is a null summary then buffer_id is 0.) */ int32_t buffer_id; - /* - DOC(If this is not a null summary, this field contains flags describing the protection status of the buffer.) - */ + /*DOC(If this is not a null summary, this field contains flags describing the protection status of the buffer.)*/ Access_Flag lock_flags; /* DOC(If this is not a null summary, this field specifies the size of the text in the buffer.) */ diff --git a/4cpp_lexer.h b/4cpp_lexer.h index 7409dfec..be0057a7 100644 --- a/4cpp_lexer.h +++ b/4cpp_lexer.h @@ -288,7 +288,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t siz int32_t token_i = token_array_out->count; int32_t max_token_i = token_array_out->max_count; - char c = 0; + uint8_t c = 0; int32_t end_pos = size + S.chunk_pos; chunk -= S.chunk_pos; @@ -330,8 +330,8 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t siz S.fsm = null_lex_fsm; for(;;){ { - unsigned short *eq_classes = get_eq_classes[S.pp_state]; - unsigned char *fsm_table = get_table[S.pp_state]; + uint16_t *eq_classes = get_eq_classes[S.pp_state]; + uint8_t *fsm_table = get_table[S.pp_state]; for (; S.fsm.state < LS_count && S.pos < end_pos;){ c = chunk[S.pos++]; @@ -489,7 +489,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t siz String_And_Flag data = preprops[sub_match]; S.token.type = (Cpp_Token_Type)data.flags; S.token.flags = CPP_TFLAG_PP_DIRECTIVE; - S.pp_state = (unsigned char)cpp_pp_directive_to_state(S.token.type); + S.pp_state = (uint8_t)cpp_pp_directive_to_state(S.token.type); } else{ S.token.type = CPP_TOKEN_JUNK; diff --git a/internal_4coder_tests.cpp b/internal_4coder_tests.cpp index 8ca0fa52..764c3839 100644 --- a/internal_4coder_tests.cpp +++ b/internal_4coder_tests.cpp @@ -77,12 +77,6 @@ CUSTOM_COMMAND_SIG(reopen_test){ //TEST_TIME_E(); } -CUSTOM_COMMAND_SIG(run_all_tests){ - exec_command(app, load_lots_of_files); - exec_command(app, reopen_test); -} - -#if 0 CUSTOM_COMMAND_SIG(generate_stop_spots_test_data){ Buffer_Summary buffer = app->create_buffer(app, literal(LOTS_OF_FILES "/4ed.cpp"), 0); View_Summary view = app->get_active_view(app, AccessAll); @@ -97,6 +91,18 @@ CUSTOM_COMMAND_SIG(generate_stop_spots_test_data){ app->buffer_compute_cursor(app, &buffer, seek_line_char(316, 29), &curs); fwrite(&curs.pos, 4, 1, file); + for (int32_t i = 0; i < 10; ++i){ + Query_Bar bar = {0}; + bar.prompt = make_lit_string("Do something to continue the test"); + if (app->start_query_bar(app, &bar, 0)){ + app->get_user_input(app, EventAll, EventAll); + } + refresh_buffer(app, &buffer); + if (buffer.tokens_are_ready){ + break; + } + } + static Seek_Boundary_Flag flag_set[] = { BoundaryWhitespace, BoundaryToken, @@ -111,7 +117,7 @@ CUSTOM_COMMAND_SIG(generate_stop_spots_test_data){ for (int32_t seek_forward = 0; seek_forward <= 1; ++seek_forward){ pos = curs.pos; for (int32_t i = 0; i < 100; ++i){ - pos = app->buffer_boundary_seek(app, &buffer, pos, seek_forward, flag_set[flag_i]); + pos = buffer_boundary_seek(app, &buffer, pos, seek_forward, flag_set[flag_i]); fwrite(&pos, 4, 1, file); } } @@ -120,7 +126,6 @@ CUSTOM_COMMAND_SIG(generate_stop_spots_test_data){ fclose(file); } } -#endif static void fcheck(int32_t x, FILE *file){ @@ -143,6 +148,18 @@ CUSTOM_COMMAND_SIG(stop_spots_test){ app->buffer_compute_cursor(app, &buffer, seek_line_char(316, 29), &curs); fcheck(curs.pos, file); + for (int32_t i = 0; i < 10; ++i){ + Query_Bar bar = {0}; + bar.prompt = make_lit_string("Do something to continue the test"); + if (app->start_query_bar(app, &bar, 0)){ + app->get_user_input(app, EventAll, EventAll); + } + refresh_buffer(app, &buffer); + if (buffer.tokens_are_ready){ + break; + } + } + static Seek_Boundary_Flag flag_set[] = { BoundaryWhitespace, BoundaryToken, @@ -167,13 +184,25 @@ CUSTOM_COMMAND_SIG(stop_spots_test){ } } +CUSTOM_COMMAND_SIG(load_unicode_file){ + Buffer_Summary buffer = app->create_buffer(app, literal(TEST_FILES "/mod_markov.c"), 0); + View_Summary view = app->get_active_view(app, AccessAll); + app->view_set_buffer(app, &view, buffer.buffer_id, 0); + + app->view_set_cursor(app, &view, seek_line_char(230, 25), 1); +} + +CUSTOM_COMMAND_SIG(run_all_tests){ + exec_command(app, load_lots_of_files); + exec_command(app, reopen_test); + exec_command(app, stop_spots_test); + exec_command(app, load_unicode_file); +} + static void test_get_bindings(Bind_Helper *context){ begin_map(context, mapid_global); - - //bind(context, key_f3, MDFR_NONE, run_all_tests); - bind(context, key_f3, MDFR_NONE, stop_spots_test); - + bind(context, key_f3, MDFR_NONE, run_all_tests); end_map(context); }