upgrade to indent rule for handling comment spacing
This commit is contained in:
parent
c8d881c1b5
commit
71147d1624
|
@ -1295,38 +1295,38 @@ CUSTOM_COMMAND_SIG(if0_off){
|
||||||
CUSTOM_COMMAND_SIG(backspace_word){
|
CUSTOM_COMMAND_SIG(backspace_word){
|
||||||
unsigned int access = AccessOpen;
|
unsigned int access = AccessOpen;
|
||||||
|
|
||||||
View_Summary view;
|
View_Summary view = app->get_active_view(app, access);
|
||||||
Buffer_Summary buffer;
|
Buffer_Summary buffer = app->get_buffer(app, view.buffer_id, access);
|
||||||
int pos2, pos1;
|
|
||||||
|
|
||||||
view = app->get_active_view(app, access);
|
if (buffer.exists){
|
||||||
|
int pos2 = 0, pos1 = 0;
|
||||||
|
|
||||||
pos2 = view.cursor.pos;
|
pos2 = view.cursor.pos;
|
||||||
exec_command(app, seek_alphanumeric_left);
|
exec_command(app, seek_alphanumeric_left);
|
||||||
refresh_view(app, &view);
|
refresh_view(app, &view);
|
||||||
pos1 = view.cursor.pos;
|
pos1 = view.cursor.pos;
|
||||||
|
|
||||||
buffer = app->get_buffer(app, view.buffer_id, access);
|
|
||||||
app->buffer_replace_range(app, &buffer, pos1, pos2, 0, 0);
|
app->buffer_replace_range(app, &buffer, pos1, pos2, 0, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CUSTOM_COMMAND_SIG(delete_word){
|
CUSTOM_COMMAND_SIG(delete_word){
|
||||||
unsigned int access = AccessOpen;
|
unsigned int access = AccessOpen;
|
||||||
|
|
||||||
View_Summary view;
|
View_Summary view = app->get_active_view(app, access);
|
||||||
Buffer_Summary buffer;
|
Buffer_Summary buffer = app->get_buffer(app, view.buffer_id, access);
|
||||||
int pos2, pos1;
|
|
||||||
|
|
||||||
view = app->get_active_view(app, access);
|
if (buffer.exists){
|
||||||
|
int pos2 = 0, pos1 = 0;
|
||||||
|
|
||||||
pos1 = view.cursor.pos;
|
pos1 = view.cursor.pos;
|
||||||
exec_command(app, seek_alphanumeric_right);
|
exec_command(app, seek_alphanumeric_right);
|
||||||
refresh_view(app, &view);
|
refresh_view(app, &view);
|
||||||
pos2 = view.cursor.pos;
|
pos2 = view.cursor.pos;
|
||||||
|
|
||||||
buffer = app->get_buffer(app, view.buffer_id, access);
|
|
||||||
app->buffer_replace_range(app, &buffer, pos1, pos2, 0, 0);
|
app->buffer_replace_range(app, &buffer, pos1, pos2, 0, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CUSTOM_COMMAND_SIG(snipe_token_or_word){
|
CUSTOM_COMMAND_SIG(snipe_token_or_word){
|
||||||
unsigned int access = AccessOpen;
|
unsigned int access = AccessOpen;
|
||||||
|
|
|
@ -2674,6 +2674,7 @@ struct Indent_Parse_State{
|
||||||
i32 previous_line_indent;
|
i32 previous_line_indent;
|
||||||
i32 paren_nesting;
|
i32 paren_nesting;
|
||||||
i32 paren_anchor_indent[16];
|
i32 paren_anchor_indent[16];
|
||||||
|
i32 comment_shift;
|
||||||
};
|
};
|
||||||
|
|
||||||
internal i32
|
internal i32
|
||||||
|
@ -2693,13 +2694,27 @@ compute_this_indent(Buffer *buffer, Indent_Parse_State indent,
|
||||||
next_line_start = buffer_size(buffer);
|
next_line_start = buffer_size(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((prev_token.type == CPP_TOKEN_COMMENT ||
|
b32 did_special_behavior = false;
|
||||||
prev_token.type == CPP_TOKEN_STRING_CONSTANT) &&
|
|
||||||
prev_token.start <= this_line_start &&
|
if (prev_token.start <= this_line_start &&
|
||||||
prev_token.start + prev_token.size > this_line_start){
|
prev_token.start + prev_token.size > this_line_start){
|
||||||
this_indent = previous_indent;
|
if (prev_token.type == CPP_TOKEN_COMMENT){
|
||||||
|
Hard_Start_Result hard_start = buffer_find_hard_start(buffer, this_line_start, tab_width);
|
||||||
|
i32 line_pos = hard_start.char_pos - this_line_start;
|
||||||
|
this_indent = line_pos + indent.comment_shift;
|
||||||
|
if (this_indent < 0){
|
||||||
|
this_indent = 0;
|
||||||
}
|
}
|
||||||
else{
|
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;
|
this_indent = indent.current_indent;
|
||||||
if (T.start < next_line_start){
|
if (T.start < next_line_start){
|
||||||
if (T.flags & CPP_TFLAG_PP_DIRECTIVE){
|
if (T.flags & CPP_TFLAG_PP_DIRECTIVE){
|
||||||
|
@ -2898,6 +2913,14 @@ get_line_indentation_marks(Partition *part, Buffer *buffer, Cpp_Token_Stack toke
|
||||||
case CPP_TOKEN_BRACE_OPEN: 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_BRACE_CLOSE: indent.current_indent -= 4; break;
|
||||||
|
|
||||||
|
case CPP_TOKEN_COMMENT:
|
||||||
|
{
|
||||||
|
i32 line = buffer_get_line_index(buffer, T.start);
|
||||||
|
i32 start = buffer->line_starts[line];
|
||||||
|
|
||||||
|
indent.comment_shift = (indent.current_indent - (T.start - start));
|
||||||
|
}break;
|
||||||
|
|
||||||
case CPP_TOKEN_PARENTHESE_OPEN:
|
case CPP_TOKEN_PARENTHESE_OPEN:
|
||||||
if (!(T.flags & CPP_TFLAG_PP_BODY)){
|
if (!(T.flags & CPP_TFLAG_PP_BODY)){
|
||||||
if (indent.paren_nesting < ArrayCount(indent.paren_anchor_indent)){
|
if (indent.paren_nesting < ArrayCount(indent.paren_anchor_indent)){
|
||||||
|
|
Loading…
Reference in New Issue