120 lines
3.4 KiB
C++
120 lines
3.4 KiB
C++
/*
|
|
4coder_combined_write_commands.cpp - Commands for writing text specialized for particular
|
|
contexts.
|
|
*/
|
|
|
|
// TOP
|
|
|
|
static void
|
|
write_string(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, String string){
|
|
buffer_replace_range(app, buffer, view->cursor.pos, view->cursor.pos, string.str, string.size);
|
|
view_set_cursor(app, view, seek_pos(view->cursor.pos + string.size), 1);
|
|
}
|
|
|
|
static void
|
|
write_string(Application_Links *app, String string){
|
|
uint32_t access = AccessOpen;
|
|
View_Summary view = get_active_view(app, access);
|
|
Buffer_Summary buffer = get_buffer(app, view.buffer_id, access);
|
|
write_string(app, &view, &buffer, string);
|
|
}
|
|
|
|
static void
|
|
write_named_comment_string(Application_Links *app, char *type_string){
|
|
char space[512];
|
|
String str = make_fixed_width_string(space);
|
|
|
|
String name = global_config.user_name;
|
|
if (name.size > 0){
|
|
append(&str, "// ");
|
|
append(&str, type_string);
|
|
append(&str, "(");
|
|
append(&str, name);
|
|
append(&str, "): ");
|
|
}
|
|
else{
|
|
append(&str, "// ");
|
|
append(&str, type_string);
|
|
append(&str, ": ");
|
|
}
|
|
|
|
write_string(app, str);
|
|
}
|
|
|
|
static void
|
|
long_braces(Application_Links *app, char *text, int32_t size){
|
|
uint32_t access = AccessOpen;
|
|
View_Summary view = get_active_view(app, access);
|
|
Buffer_Summary buffer = get_buffer(app, view.buffer_id, access);
|
|
int32_t pos = view.cursor.pos;
|
|
|
|
buffer_replace_range(app, &buffer, pos, pos, text, size);
|
|
view_set_cursor(app, &view, seek_pos(pos + 2), true);
|
|
|
|
buffer_auto_indent(app, &global_part, &buffer, pos, pos + size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens);
|
|
move_past_lead_whitespace(app, &view, &buffer);
|
|
}
|
|
|
|
CUSTOM_COMMAND_SIG(open_long_braces)
|
|
CUSTOM_DOC("At the cursor, insert a '{' and '}' separated by a blank line.")
|
|
{
|
|
char text[] = "{\n\n}";
|
|
int32_t size = sizeof(text) - 1;
|
|
long_braces(app, text, size);
|
|
}
|
|
|
|
CUSTOM_COMMAND_SIG(open_long_braces_semicolon)
|
|
CUSTOM_DOC("At the cursor, insert a '{' and '};' separated by a blank line.")
|
|
{
|
|
char text[] = "{\n\n};";
|
|
int32_t size = sizeof(text) - 1;
|
|
long_braces(app, text, size);
|
|
}
|
|
|
|
CUSTOM_COMMAND_SIG(open_long_braces_break)
|
|
CUSTOM_DOC("At the cursor, insert a '{' and '}break;' separated by a blank line.")
|
|
{
|
|
char text[] = "{\n\n}break;";
|
|
int32_t size = sizeof(text) - 1;
|
|
long_braces(app, text, size);
|
|
}
|
|
|
|
CUSTOM_COMMAND_SIG(if0_off)
|
|
CUSTOM_DOC("Surround the range between the cursor and mark with an '#if 0' and an '#endif'")
|
|
{
|
|
place_begin_and_end_on_own_lines(app, &global_part, "#if 0", "#endif");
|
|
}
|
|
|
|
CUSTOM_COMMAND_SIG(write_todo)
|
|
CUSTOM_DOC("At the cursor, insert a '// TODO' comment, includes user name if it was specified in config.4coder.")
|
|
{
|
|
write_named_comment_string(app, "TODO");
|
|
}
|
|
|
|
CUSTOM_COMMAND_SIG(write_hack)
|
|
CUSTOM_DOC("At the cursor, insert a '// HACK' comment, includes user name if it was specified in config.4coder.")
|
|
{
|
|
write_named_comment_string(app, "HACK");
|
|
}
|
|
|
|
CUSTOM_COMMAND_SIG(write_note)
|
|
CUSTOM_DOC("At the cursor, insert a '// NOTE' comment, includes user name if it was specified in config.4coder.")
|
|
{
|
|
write_named_comment_string(app, "NOTE");
|
|
}
|
|
|
|
CUSTOM_COMMAND_SIG(write_block)
|
|
CUSTOM_DOC("At the cursor, insert a block comment.")
|
|
{
|
|
write_string(app, make_lit_string("/* */"));
|
|
}
|
|
|
|
CUSTOM_COMMAND_SIG(write_zero_struct)
|
|
CUSTOM_DOC("At the cursor, insert a ' = {0};'.")
|
|
{
|
|
write_string(app, make_lit_string(" = {0};"));
|
|
}
|
|
|
|
// BOTTOM
|
|
|