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

AutoIndent_UseTab = 0x2
If AutoIndent_UseTab is set, then when putting in leading whitespace to align code, as many tabs will be used as possible until the fine grained control of spaces - is needed to finish the alignment.


§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 + is needed to finish the alignment.

AutoIndent_ExactAlignBlock = 0x4
If AutoIndent_ExactAlignBlock is set, then block comments are indented by putting + the first non-whitespace character of the line in line with the beginning of the comment.

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 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 diff --git a/4coder_auto_indent.cpp b/4coder_auto_indent.cpp index a98397e9..64189ec4 100644 --- a/4coder_auto_indent.cpp +++ b/4coder_auto_indent.cpp @@ -91,25 +91,36 @@ make_batch_from_indent_marks(Application_Links *app, Partition *part, Buffer_Sum buffer_find_hard_start(app, buffer, line_start, opts.tab_width); int32_t correct_indentation = indent_marks[line_i]; - if (hard_start.all_whitespace && opts.empty_blank_lines) correct_indentation = 0; - if (correct_indentation == -1) correct_indentation = hard_start.indent_pos; + if (hard_start.all_whitespace && opts.empty_blank_lines){ + correct_indentation = 0; + } + if (correct_indentation == -1){ + correct_indentation = hard_start.indent_pos; + } // TODO(allen): Only replace spaces if we are using space based indentation. - // TODO(allen): See if the first clause can just be removed because it's dumb. if (!hard_start.all_space || correct_indentation != hard_start.indent_pos){ Buffer_Edit new_edit; new_edit.str_start = str_size; str_size += correct_indentation; char *str = push_array(part, char, correct_indentation); int32_t j = 0; + if (opts.use_tabs){ int32_t i = 0; - for (; i + opts.tab_width <= correct_indentation; i += opts.tab_width) str[j++] = '\t'; - for (; i < correct_indentation; ++i) str[j++] = ' '; + for (; i + opts.tab_width <= correct_indentation; i += opts.tab_width){ + str[j++] = '\t'; + } + for (; i < correct_indentation; ++i){ + str[j++] = ' '; + } } else{ - for (; j < correct_indentation; ++j) str[j] = ' '; + for (; j < correct_indentation; ++j){ + str[j] = ' '; + } } + new_edit.len = j; new_edit.start = line_start; new_edit.end = hard_start.char_pos; @@ -258,13 +269,15 @@ struct Indent_Parse_State{ int32_t paren_nesting; int32_t paren_anchor_indent[16]; int32_t comment_shift; + int32_t previous_comment_indent; }; static int32_t -compute_this_indent(Application_Links *app, Buffer_Summary *buffer, Indent_Parse_State indent, - Cpp_Token T, Cpp_Token prev_token, int32_t line_i, int32_t tab_width){ +compute_this_indent(Application_Links *app, Buffer_Summary *buffer, Indent_Parse_State *indent, + Cpp_Token T, Cpp_Token prev_token, int32_t line_i, bool32 this_line_gets_indented, + bool32 exact_align, int32_t tab_width){ - int32_t previous_indent = indent.previous_line_indent; + int32_t previous_indent = indent->previous_line_indent; int32_t this_indent = 0; int32_t this_line_start = buffer_get_line_start(app, buffer, line_i); @@ -277,18 +290,32 @@ compute_this_indent(Application_Links *app, Buffer_Summary *buffer, Indent_Parse if (prev_token.type == CPP_TOKEN_COMMENT){ Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, this_line_start, tab_width); - if (hard_start.all_whitespace){ - this_indent = previous_indent; - did_special_behavior = true; + 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; + } } - did_special_behavior = true; } + + if (!hard_start.all_whitespace){ + if (this_line_gets_indented){ + indent->previous_comment_indent = this_indent; + } + 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; @@ -296,9 +323,8 @@ compute_this_indent(Application_Links *app, Buffer_Summary *buffer, Indent_Parse } } - if (!did_special_behavior){ - this_indent = indent.current_indent; + this_indent = indent->current_indent; if (T.start < next_line_start){ if (T.flags & CPP_TFLAG_PP_DIRECTIVE){ this_indent = 0; @@ -310,9 +336,9 @@ compute_this_indent(Application_Links *app, Buffer_Summary *buffer, Indent_Parse 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)){ + 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: @@ -328,21 +354,23 @@ compute_this_indent(Application_Links *app, Buffer_Summary *buffer, Indent_Parse if (this_indent < 0) this_indent = 0; } - if (indent.paren_nesting > 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; + 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]; + this_indent = indent->paren_anchor_indent[level]; } } + return(this_indent); } static int32_t* get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, - Cpp_Token_Array tokens, int32_t line_start, int32_t line_end, int32_t tab_width){ + Cpp_Token_Array tokens, int32_t line_start, int32_t line_end, + bool32 exact_align, int32_t tab_width){ int32_t indent_mark_count = line_end - line_start; int32_t *indent_marks = push_array(part, int32_t, indent_mark_count); @@ -372,8 +400,7 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b indent.previous_line_indent = indent.current_indent; for (;line_index < line_end;){ - Cpp_Token prev_token = *token_ptr; - Cpp_Token token; + Cpp_Token prev_token = *token_ptr, token = {0}; ++token_ptr; if (token_ptr < tokens.tokens + tokens.count){ @@ -388,8 +415,12 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b for (;token.start >= next_line_start_pos && line_index < line_end;){ next_line_start_pos = buffer_get_line_start(app, buffer, line_index+1); + // TODO(allen): Flatten this function back in, as it is no longer + // leaving the indent state unchanged and it's only called here. int32_t this_indent = - compute_this_indent(app, buffer, indent, token, prev_token, line_index, tab_width); + compute_this_indent(app, buffer, &indent, token, prev_token, + line_index, line_index >= line_start, + exact_align, tab_width); // NOTE(allen): Rebase the paren anchor if the first token // after an open paren is on the next line. @@ -424,6 +455,7 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b 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; case CPP_TOKEN_PARENTHESE_OPEN: @@ -527,10 +559,8 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buff // Stage 2: Decide where the first and last lines are. // The lines in the range [line_start,line_end) will be indented. - int32_t do_whole_tokens = 1; - int32_t line_start = 0, line_end = 0; - if (do_whole_tokens){ + if (flags & AutoIndent_FullTokens){ get_indent_lines_whole_tokens(app, buffer, tokens, start, end, &line_start, &line_end); } else{ @@ -541,7 +571,8 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buff // Get an array representing how much each line in // the range [line_start,line_end) should be indented. int32_t *indent_marks = - get_indentation_marks(app, part, buffer, tokens, line_start, line_end, tab_width); + get_indentation_marks(app, part, buffer, tokens, line_start, line_end, + (flags & AutoIndent_ExactAlignBlock), tab_width); // Stage 4: Set the Line Indents Indent_Options opts = {0}; diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 7869cad3..83740601 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -960,7 +960,7 @@ CUSTOM_COMMAND_SIG(auto_tab_line_at_cursor){ buffer_auto_indent(app, &buffer, view.cursor.pos, view.cursor.pos, DEF_TAB_WIDTH, - DEFAULT_INDENT_FLAGS); + DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); move_past_lead_whitespace(app, &view, &buffer); } @@ -972,7 +972,7 @@ CUSTOM_COMMAND_SIG(auto_tab_whole_file){ buffer_auto_indent(app, &buffer, 0, buffer.size, DEF_TAB_WIDTH, - DEFAULT_INDENT_FLAGS); + DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); } CUSTOM_COMMAND_SIG(auto_tab_range){ @@ -984,13 +984,22 @@ CUSTOM_COMMAND_SIG(auto_tab_range){ buffer_auto_indent(app, &buffer, range.min, range.max, DEF_TAB_WIDTH, - DEFAULT_INDENT_FLAGS); + DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); move_past_lead_whitespace(app, &view, &buffer); } CUSTOM_COMMAND_SIG(write_and_auto_tab){ exec_command(app, write_character); - exec_command(app, auto_tab_line_at_cursor); + + uint32_t access = AccessOpen; + View_Summary view = app->get_active_view(app, access); + Buffer_Summary buffer = app->get_buffer(app, view.buffer_id, access); + + buffer_auto_indent(app, &buffer, + view.cursor.pos, view.cursor.pos, + DEF_TAB_WIDTH, + DEFAULT_INDENT_FLAGS | AutoIndent_ExactAlignBlock); + move_past_lead_whitespace(app, &view, &buffer); } CUSTOM_COMMAND_SIG(clean_all_lines){ @@ -1847,7 +1856,7 @@ long_braces(Application_Links *app, char *text, int32_t size){ buffer_auto_indent(app, &buffer, pos, pos + size, DEF_TAB_WIDTH, - DEFAULT_INDENT_FLAGS); + DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); move_past_lead_whitespace(app, &view, &buffer); } @@ -1921,7 +1930,7 @@ CUSTOM_COMMAND_SIG(if0_off){ buffer_auto_indent(app, &buffer, range.min, range.max, DEF_TAB_WIDTH, - DEFAULT_INDENT_FLAGS); + DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); move_past_lead_whitespace(app, &view, &buffer); } } diff --git a/4coder_types.h b/4coder_types.h index af566a86..bcc1fe48 100644 --- a/4coder_types.h +++ b/4coder_types.h @@ -268,7 +268,13 @@ ENUM(uint32_t, Auto_Indent_Flag){ /* DOC(If AutoIndent_UseTab is set, then when putting in leading whitespace to align code, as many tabs will be used as possible until the fine grained control of spaces is needed to finish the alignment.) */ - AutoIndent_UseTab = 0x2 + AutoIndent_UseTab = 0x2, + /* DOC(If AutoIndent_ExactAlignBlock is set, then block comments are indented by putting + the first non-whitespace character of the line in line with the beginning of the comment.) */ + AutoIndent_ExactAlignBlock = 0x4, + /* DOC(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.) */ + AutoIndent_FullTokens = 0x8, }; /* DOC(A Set_Buffer_Flag field specifies the behavior of an operation that sets the buffer of a view.) */ diff --git a/4ed.cpp b/4ed.cpp index a4a06428..64c5cfff 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -1072,6 +1072,45 @@ app_hardcode_styles(Models *models){ style->main.file_info_style = file_info_style; ++style; + ///////////////// + style_set_name(style, make_lit_string("Strange")); + + style->main.back_color = 0xFF161616; + style->main.margin_color = 0xFF606590; + style->main.margin_hover_color = 0xFF606590; + style->main.margin_active_color = 0xFF9a99e7; + style->main.cursor_color = 0xFFd96e26; + style->main.at_cursor_color = style->main.back_color; + style->main.mark_color = 0xFF808080; + style->main.highlight_color = 0xFF703419; + style->main.at_highlight_color = 0xFFCDAA7D; + style->main.default_color = 0xFFFFFFFF; + style->main.comment_color = 0xFF505f89; + style->main.keyword_color = 0xFFaa8da7; + style->main.str_constant_color = 0xFF9a99e7; + style->main.char_constant_color = style->main.str_constant_color; + style->main.int_constant_color = style->main.str_constant_color; + style->main.float_constant_color = style->main.str_constant_color; + style->main.bool_constant_color = style->main.str_constant_color; + style->main.include_color = 0xFF9a99e7; + style->main.preproc_color = 0xFF606590; + style->main.special_character_color = 0xFFFF0000; + + style->main.paste_color = 0xFFFFBB00; + style->main.undo_color = 0xFF80005D; + + style->main.highlight_junk_color = 0xFF3A0000; + style->main.highlight_white_color = 0xFF003A3A; + + file_info_style.bar_color = 0xFF9a99e7; + file_info_style.bar_active_color = 0xFF9a99e7; + file_info_style.base_color = 0xFF000000; + file_info_style.pop1_color = 0xFF03CF0C; + file_info_style.pop2_color = 0xFFFF0000; + style->main.file_info_style = file_info_style; + ++style; + + ///////////////// models->styles.count = (i32)(style - styles); models->styles.max = ArrayCount(models->styles.styles); style_copy(main_style(models), models->styles.styles + 1); diff --git a/TODO.txt b/TODO.txt index 1b792d3a..051199f5 100644 --- a/TODO.txt +++ b/TODO.txt @@ -87,11 +87,12 @@ ; BEFORE I SHIP ; +; [X] use strange theme ; [X] tokens in the custom API ; [X] token seeking on custom side ; [X] auto indent on the custom side ; [X] indent whole comments -; [] inserting lines at end of block comment +; [X] inserting lines at end of block comment ; [] clean up and comment the auto indent code to allow for customizations ; [] more built in options for auto indenting ; [] occasionally missing the (!) mark on files on windows diff --git a/thing.txt b/thing.txt deleted file mode 100644 index 3fa82cdb..00000000 --- a/thing.txt +++ /dev/null @@ -1,21 +0,0 @@ - -// - -Theme_Color ThemeColors[] = { - {Stag_Bar, 0x9a99e7}, - {Stag_Bar_Active, 0x9a99e7}, - {Stag_Margin, 0x606590}, - {Stag_Margin_Hover, 0x9a99e7}, - {Stag_Margin_Active, 0x9a99e7}, - {Stag_Comment, 0x505f89}, - {Stag_Keyword, 0xaa8da7}, - {Stag_Default, 0xffffff}, - {Stag_Cursor, 0xd96e26}, - {Stag_Int_Constant, 0x9a99e7}, - {Stag_Float_Constant, 0x9a99e7}, - {Stag_Bool_Constant, 0x9a99e7}, - {Stag_Str_Constant, 0x9a99e7}, - {Stag_Char_Constant, 0x9a99e7}, - {Stag_Preproc, 0x606590}, - {Stag_Include, 0x9a99e7}, -};