diff --git a/4coder_custom.cpp b/4coder_custom.cpp index 9205d4d9..99ca7c7c 100644 --- a/4coder_custom.cpp +++ b/4coder_custom.cpp @@ -9,6 +9,9 @@ // to decide whether you want macro translations, without them you will // have to manipulate the command and parameter stack through // "app->" which may be more or less clear depending on your use. +// +// I suggest you try disabling macro translation and getting your code working +// that way, because I'll be removing it entirely sometime soon #define DisableMacroTranslations 0 #include "4coder_custom.h" @@ -52,25 +55,30 @@ bool str_match(const char *a, int len_a, const char *b, int len_b){ } HOOK_SIG(my_file_settings){ - Buffer_Summary buffer = get_active_buffer(cmd_context); + Buffer_Summary buffer = app->get_active_buffer(cmd_context); - int treat_as_code = 0; + // NOTE(allen|a3.4.2): Whenever you ask for a buffer, you should check that the + // exists flag is set to true before using it. Reasons why the buffer might not exist: + // -The active panel does not contain a buffer and get_active_buffer was used + // -The index provided to get_buffer was out of range [0,max) or that index is associated to a dummy buffer + // -The name provided to get_buffer_by_name did not match any of the existing buffers + if (buffer.exists){ + int treat_as_code = 0; - // NOTE(allen|a3.1): This checks buffer.file_name just in case get_active_buffer returns back - // a null buffer (where every member is 0). - if (buffer.file_name && buffer.size < (16 << 20)){ - int extension_len; - char *extension = get_extension(buffer.file_name, buffer.file_name_len, &extension_len); - if (str_match(extension, extension_len, literal("cpp"))) treat_as_code = 1; - else if (str_match(extension, extension_len, literal("h"))) treat_as_code = 1; - else if (str_match(extension, extension_len, literal("c"))) treat_as_code = 1; - else if (str_match(extension, extension_len, literal("hpp"))) treat_as_code = 1; - } + if (buffer.file_name && buffer.size < (16 << 20)){ + int extension_len; + char *extension = get_extension(buffer.file_name, buffer.file_name_len, &extension_len); + if (str_match(extension, extension_len, literal("cpp"))) treat_as_code = 1; + else if (str_match(extension, extension_len, literal("h"))) treat_as_code = 1; + else if (str_match(extension, extension_len, literal("c"))) treat_as_code = 1; + else if (str_match(extension, extension_len, literal("hpp"))) treat_as_code = 1; + } - push_parameter(app, cmd_context, par_lex_as_cpp_file, treat_as_code); - push_parameter(app, cmd_context, par_wrap_lines, !treat_as_code); - push_parameter(app, cmd_context, par_key_mapid, (treat_as_code)?(my_code_map):(mapid_file)); - exec_command(cmd_context, cmdid_set_settings); + push_parameter(app, cmd_context, par_lex_as_cpp_file, treat_as_code); + push_parameter(app, cmd_context, par_wrap_lines, !treat_as_code); + push_parameter(app, cmd_context, par_key_mapid, (treat_as_code)?(my_code_map):(mapid_file)); + exec_command(cmd_context, cmdid_set_settings); + } } CUSTOM_COMMAND_SIG(open_in_other){ diff --git a/4coder_custom.h b/4coder_custom.h index 600ac374..c5c5cc0b 100644 --- a/4coder_custom.h +++ b/4coder_custom.h @@ -220,7 +220,8 @@ struct Buffer_Summary{ // NOTE(allen): None of these members nor any of the data pointed to // by these members should be modified, I would have made them const... // but that actually causes problems for C++ reasons. - int found_buffer; + int exists; + int ready; int file_id; int size; diff --git a/4coder_helper.h b/4coder_helper.h index 9236ec77..90c65aa6 100644 --- a/4coder_helper.h +++ b/4coder_helper.h @@ -258,7 +258,6 @@ exec_command_(Application_Links *app, void *cmd_context, Custom_Command_Function #define exec_command_keep_stack app->exec_command_keep_stack #define clear_parameters app->clear_parameters -#define get_active_buffer app->get_active_buffer #define exec_command(cmd_context, cmd) exec_command_(app, cmd_context, cmd) diff --git a/4ed.cpp b/4ed.cpp index 8fa55f1a..e3b66cc5 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -541,7 +541,7 @@ COMMAND_DECL(word_complete){ file_ptr = working_set->files; for (i = 0, j = 2; i < buffer_count; ++i, ++file_ptr){ - if (file_ptr != file && !file_ptr->state.is_dummy && file_is_ready(file_ptr)){ + if (file_ptr != file && !file_ptr->state.is_dummy){ ranges[j].buffer = &file_ptr->state.buffer; ranges[j].start = 0; ranges[j].size = buffer_size(ranges[j].buffer); @@ -2011,7 +2011,8 @@ globalvar Command_Function command_table[cmdid_count]; internal void fill_buffer_summary(Buffer_Summary *buffer, Editing_File *file, Working_Set *working_set){ - buffer->found_buffer = 1; + buffer->exists = 1; + buffer->exists = file_is_ready(file); buffer->file_id = (int)(file - working_set->files); buffer->size = file->state.buffer.size; buffer->file_cursor_pos = file->state.cursor_pos; @@ -2085,7 +2086,7 @@ extern "C"{ if (index >= 0 && index < max){ file = working_set->files + index; - if (!file->state.is_dummy && file_is_ready(file)){ + if (!file->state.is_dummy){ #if BUFFER_EXPERIMENT_SCALPEL <= 0 fill_buffer_summary(&buffer, file, working_set); #endif @@ -2107,7 +2108,7 @@ extern "C"{ file = view->file; working_set = cmd->working_set; - if (file && !file->state.is_dummy && file_is_ready(file)){ + if (file && !file->state.is_dummy){ #if BUFFER_EXPERIMENT_SCALPEL <= 0 fill_buffer_summary(&buffer, file, working_set); #endif diff --git a/vc120.pdb b/vc120.pdb index 8c19adbf..042e4c9a 100644 Binary files a/vc120.pdb and b/vc120.pdb differ diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 5ae2cf8c..326189c3 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -1789,6 +1789,9 @@ main(int argc, char **argv){ system_acquire_lock(FRAME_LOCK); + SetForegroundWindow(window_handle); + SetActiveWindow(window_handle); + ResumeThread(win32vars.update_loop_thread); MSG msg;