Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
176 lines (149 sloc)
5.54 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // NOTE(sokus): Modified f4_autocomplete_or_indent | |
| CUSTOM_COMMAND_SIG(sq_autocomplete) | |
| CUSTOM_DOC("Tries to autocomplete the word currently being typed.") | |
| { | |
| ProfileScope(app, "[SQ] Word Complete"); | |
| View_ID view = get_active_view(app, Access_ReadWriteVisible); | |
| Buffer_ID buffer = view_get_buffer(app, view, Access_ReadWriteVisible); | |
| if(buffer != 0) | |
| { | |
| Managed_Scope scope = view_get_managed_scope(app, view); | |
| b32 first_completion = false; | |
| Rewrite_Type *rewrite = scope_attachment(app, scope, view_rewrite_loc, Rewrite_Type); | |
| if (*rewrite != Rewrite_WordComplete){ | |
| first_completion = true; | |
| } | |
| set_next_rewrite(app, view, Rewrite_WordComplete); | |
| Word_Complete_Iterator *it = word_complete_get_shared_iter(app); | |
| local_persist b32 initialized = false; | |
| local_persist Range_i64 range = {}; | |
| if(first_completion || !initialized) | |
| { | |
| ProfileScope(app, "[SQ] Word Complete State Init"); | |
| initialized = false; | |
| i64 pos = view_get_cursor_pos(app, view); | |
| Range_i64 needle_range = get_word_complete_needle_range(app, buffer, pos); | |
| if(range_size(needle_range) > 0) | |
| { | |
| initialized = true; | |
| range = needle_range; | |
| word_complete_iter_init(buffer, needle_range, it); | |
| } | |
| } | |
| // NOTE(rjf): Word-Complete | |
| if(initialized) | |
| { | |
| ProfileScope(app, "[SQ] Word Complete Apply"); | |
| word_complete_iter_next(it); | |
| String_Const_u8 str = word_complete_iter_read(it); | |
| buffer_replace_range(app, buffer, range, str); | |
| range.max = range.min + str.size; | |
| view_set_cursor_and_preferred_x(app, view, seek_pos(range.max)); | |
| } | |
| } | |
| } | |
| // NOTE(sokus): Modified f4_unindent. | |
| CUSTOM_COMMAND_SIG(sq_indent) | |
| CUSTOM_DOC("Indent the selected range.") | |
| { | |
| Scratch_Block scratch(app); | |
| View_ID view = get_active_view(app, Access_ReadWrite); | |
| Buffer_ID buffer = view_get_buffer(app, view, Access_ReadWrite); | |
| i64 pos = view_get_cursor_pos(app, view); | |
| i64 mark = view_get_mark_pos(app, view); | |
| Range_i64 pos_range = Ii64(pos, mark); | |
| Range_i64 line_range = F4_LineRangeFromPosRange(app, buffer, pos_range); | |
| History_Group group = history_group_begin(app, buffer); | |
| F4_ReIndentPosRange(app, buffer, Ii64(pos, mark), 1); | |
| F4_AdjustCursorAndMarkForIndentation(app, view, pos, mark, line_range); | |
| history_group_end(group); | |
| no_mark_snap_to_cursor(app, view); | |
| } | |
| // NOTE(sokus): Modified f4_setup_new_project, removed some extensions | |
| // and changed load_paths for linux. | |
| CUSTOM_COMMAND_SIG(sq_setup_new_project) | |
| CUSTOM_DOC("Sets up a blank 4coder project provided some user folder.") | |
| { | |
| Scratch_Block scratch(app); | |
| Query_Bar_Group bar_group(app); | |
| // NOTE(rjf): Query user for project folder. | |
| u8 project_folder_absolute[1024]; | |
| { | |
| Query_Bar path_bar = {}; | |
| path_bar.prompt = string_u8_litexpr("Absolute Path To Project Folder: "); | |
| path_bar.string = SCu8(project_folder_absolute, (u64)0); | |
| path_bar.string_capacity = sizeof(project_folder_absolute); | |
| if(query_user_string(app, &path_bar)) | |
| { | |
| String_Const_u8 full_file_name = push_u8_stringf(scratch, "%.*s/", | |
| string_expand(path_bar.string)); | |
| set_hot_directory(app, full_file_name); | |
| String_Const_u8 project_file_path = push_u8_stringf(scratch, "%.*s/project.4coder", string_expand(path_bar.string)); | |
| FILE *file = fopen((char *)project_file_path.str, "wb"); | |
| if(file) | |
| { | |
| char *string = R"PROJ(version(2); | |
| project_name = "New Project"; | |
| patterns = { | |
| "*.c", | |
| "*.cpp", | |
| "*.h", | |
| "*.m", | |
| "*.bat", | |
| "*.sh", | |
| "*.4coder", | |
| }; | |
| blacklist_patterns = { | |
| ".*", | |
| }; | |
| load_paths_base = { | |
| {".", .relative = true, .recursive = true, }, | |
| }; | |
| load_paths = { | |
| .win = load_paths_base, | |
| .linux = load_paths_base, | |
| }; | |
| commands = { | |
| .build = {.out="*compilation*", .footer_panel = false, .save_dirty_files = true, | |
| .win = "echo No build.bat path specified yet.", | |
| .linux = "echo No build.sh path specified yet.", }, | |
| .run = {.out="*run*", .footer_panel = false, .save_dirty_files = false, | |
| .win = "echo No path to executable specified yet.", | |
| .linux = "echo No path to executable specified yet." }, | |
| }; | |
| fkey_command = { | |
| .F1 = "run", | |
| .F2 = "build", | |
| }; | |
| )PROJ"; | |
| fprintf(file, "%s", string); | |
| fclose(file); | |
| load_project(app); | |
| } | |
| else | |
| { | |
| // TODO(rjf): Error. | |
| } | |
| } | |
| } | |
| load_project(app); | |
| } | |
| internal f32 | |
| sq_get_half_page_jump(Application_Links *app, View_ID view){ | |
| Rect_f32 region = view_get_buffer_region(app, view); | |
| return(rect_height(region)*.45f); | |
| } | |
| CUSTOM_COMMAND_SIG(sq_half_page_up) | |
| CUSTOM_DOC("Scrolls the view up one view height and moves the cursor up one view height.") | |
| { | |
| View_ID view = get_active_view(app, Access_ReadVisible); | |
| f32 page_jump = sq_get_half_page_jump(app, view); | |
| move_vertical_pixels(app, -page_jump); | |
| } | |
| CUSTOM_COMMAND_SIG(sq_half_page_down) | |
| CUSTOM_DOC("Scrolls the view down one view height and moves the cursor down one view height.") | |
| { | |
| View_ID view = get_active_view(app, Access_ReadVisible); | |
| f32 page_jump = sq_get_half_page_jump(app, view); | |
| move_vertical_pixels(app, page_jump); | |
| } |