Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
Now adds semicolon after lambda unless the lambda is a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
eidheim committed Sep 13, 2016
1 parent 16eb16b commit 43eaad0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
36 changes: 36 additions & 0 deletions src/source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1592,8 +1592,44 @@ bool Source::View::on_key_press_event_bracket_language(GdkEventKey* key) {
if(iter.backward_char())
token=get_token(get_tabs_end_iter(get_buffer()->get_iter_at_line(iter.get_line())));
}
//Add semicolon after class or struct
if(token=="class" || token=="struct")
add_semicolon=true;
//Add semicolon after lambda unless it's a parameter
else if(!open_non_curly_bracket_iter_found) {
auto it=previous_iter;
long para_count=0;
long square_count=0;
bool square_found=false;
while(it.backward_char()) {
if(*it==']' && is_code_iter(it)) {
--square_count;
square_found=true;
}
else if(*it=='[' && is_code_iter(it))
++square_count;
else if(*it==')' && is_code_iter(it))
--para_count;
else if(*it=='(' && is_code_iter(it))
++para_count;

if(square_found && square_count==0 && para_count==0) {
add_semicolon=true;
break;
}
if(it==start_iter)
break;
if(!square_found && square_count==0 && para_count==0) {
if((*it>='A' && *it<='Z') || (*it>='a' && *it<='z') || (*it>='0' && *it<='9') || *it=='_' ||
*it=='-' || *it==' ' || *it=='\t' || *it=='<' || *it=='>' || *it=='(' || *it==':' ||
*it=='*' || *it=='&' || *it=='/' || it.ends_line() || !is_code_iter(it)) {
continue;
}
else
break;
}
}
}
}
get_buffer()->insert_at_cursor("\n"+tabs+tab+"\n"+tabs+(add_semicolon?"};":"}"));
auto insert_it = get_buffer()->get_insert()->get_iter();
Expand Down
21 changes: 19 additions & 2 deletions src/source_spellcheck.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,25 @@ bool Source::SpellCheckView::is_code_iter(const Gtk::TextIter &iter) {
return true;
return false;
}
if(comment_tag && ((iter.has_tag(comment_tag) && !iter.begins_tag(comment_tag)) || iter.ends_tag(comment_tag)))
return false;
if(comment_tag) {
if(iter.has_tag(comment_tag) && !iter.begins_tag(comment_tag))
return false;
//Exception at the end of /**/
else if(iter.ends_tag(comment_tag)) {
auto previous_iter=iter;
if(previous_iter.backward_char() && *previous_iter=='/') {
auto previous_previous_iter=previous_iter;
if(previous_previous_iter.backward_char() && *previous_previous_iter=='*') {
auto it=previous_iter;
while(!it.begins_tag(comment_tag) && it.backward_to_tag_toggle(comment_tag)) {}
auto next_iter=it;
if(it.begins_tag(comment_tag) && next_iter.forward_char() && *it=='/' && *next_iter=='*' && previous_iter!=it)
return true;
}
}
return false;
}
}
if(string_tag) {
if(iter.has_tag(string_tag)) {
if(!iter.begins_tag(string_tag))
Expand Down

0 comments on commit 43eaad0

Please sign in to comment.