From 23d9e9af61990dd92fe0ab9e61c601a8f74d148e Mon Sep 17 00:00:00 2001 From: Carl-Anton Ingmarsson Date: Thu, 4 Oct 2012 01:17:09 +0200 Subject: [PATCH] indentation-c-style: When removing opening bracket also remove the closing one. ...if the closing one is right next to the opening bracket. https://bugzilla.gnome.org/show_bug.cgi?id=687216 --- plugins/indentation-c-style/indentation.c | 40 +++++++++++++++++++++++++++++++ plugins/indentation-c-style/indentation.h | 9 +++++++ plugins/indentation-c-style/plugin.c | 7 ++++++ 3 files changed, 56 insertions(+) diff --git a/plugins/indentation-c-style/indentation.c b/plugins/indentation-c-style/indentation.c index 177bb975d..0cade3632 100644 --- a/plugins/indentation-c-style/indentation.c +++ b/plugins/indentation-c-style/indentation.c @@ -1353,6 +1353,46 @@ cpp_java_indentation_char_added (IAnjutaEditor *editor, g_object_unref (iter); } +static void +erase_editor_blocked (IAnjutaEditor* editor, + IAnjutaIterable* start, + IAnjutaIterable* end, + IndentCPlugin* plugin) +{ + g_signal_handlers_block_by_func (editor, cpp_java_indentation_changed, plugin); + ianjuta_editor_erase (editor, start, end, NULL); + g_signal_handlers_unblock_by_func (editor, cpp_java_indentation_changed, plugin); +} + +void +cpp_java_indentation_changed (IAnjutaEditor *editor, + IAnjutaIterable *position, + gboolean added, + gint length, + gint lines, + const gchar *text, + IndentCPlugin* plugin) +{ + /* If autoindent is enabled*/ + if (plugin->smart_indentation) + { + if (g_settings_get_boolean (plugin->settings, PREF_BRACE_AUTOCOMPLETION)) + { + if (!added && length == 1 && (*text == '[' || *text == '(')) + { + IAnjutaIterable *next; + gchar *next_char; + + next = ianjuta_iterable_clone (position, NULL); + ianjuta_iterable_next (next, NULL); + next_char = ianjuta_editor_get_text (editor, position, next, NULL); + if ((*text == '[' && *next_char == ']') || (*text == '(' && *next_char == ')')) + erase_editor_blocked (editor, position, next, plugin); + } + } + } +} + void cpp_auto_indentation (IAnjutaEditor *editor, IndentCPlugin *lang_plugin, diff --git a/plugins/indentation-c-style/indentation.h b/plugins/indentation-c-style/indentation.h index 38970c118..c3333c245 100644 --- a/plugins/indentation-c-style/indentation.h +++ b/plugins/indentation-c-style/indentation.h @@ -27,6 +27,15 @@ cpp_java_indentation_char_added (IAnjutaEditor *editor, IndentCPlugin *plugin); void +cpp_java_indentation_changed (IAnjutaEditor *editor, + IAnjutaIterable *position, + gboolean added, + gint length, + gint lines, + const gchar *text, + IndentCPlugin* plugin); + +void cpp_auto_indentation (IAnjutaEditor *editor, IndentCPlugin *plugin, IAnjutaIterable *start, diff --git a/plugins/indentation-c-style/plugin.c b/plugins/indentation-c-style/plugin.c index 59eed5b04..08a4551ea 100644 --- a/plugins/indentation-c-style/plugin.c +++ b/plugins/indentation-c-style/plugin.c @@ -356,6 +356,10 @@ install_support (IndentCPlugin *lang_plugin) "char-added", G_CALLBACK (cpp_java_indentation_char_added), lang_plugin); + g_signal_connect (lang_plugin->current_editor, + "changed", + G_CALLBACK (cpp_java_indentation_changed), + lang_plugin); } else { @@ -381,6 +385,9 @@ uninstall_support (IndentCPlugin *lang_plugin) g_signal_handlers_disconnect_by_func (lang_plugin->current_editor, G_CALLBACK (cpp_java_indentation_char_added), lang_plugin); + g_signal_handlers_disconnect_by_func (lang_plugin->current_editor, + G_CALLBACK (cpp_java_indentation_changed), + lang_plugin); } lang_plugin->support_installed = FALSE; -- 2.11.4.GIT