[anjuta/gnome-3-6] indentation-c-style: be more picky when completing braces.



commit cfa6802a84b4f153d9d90b1626ed9b992057fd37
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date:   Thu Oct 4 00:10:48 2012 +0200

    indentation-c-style: be more picky when completing braces.
    
    We now look at the next character to see if we should autocomplete or not.
    The reason for this is that you often want to enclose an already existing
    expression in brackets. If we then autocomplete you have to remove this extra
    bracket since it's at the wrong place anyways.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687216

 plugins/indentation-c-style/indentation.c |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/plugins/indentation-c-style/indentation.c b/plugins/indentation-c-style/indentation.c
index 7b66045..7b7fee3 100644
--- a/plugins/indentation-c-style/indentation.c
+++ b/plugins/indentation-c-style/indentation.c
@@ -57,6 +57,14 @@
 #define LABEL_INDENT (INDENT_SIZE)
 
 static gboolean
+is_closing_bracket(gchar ch)
+{
+	if (ch == ')' || ch == '}' || ch == ']')
+		return TRUE;
+	return FALSE;
+}
+
+static gboolean
 iter_is_newline (IAnjutaIterable *iter, gchar ch)
 {
 	if (ch == '\n' || ch == '\r')
@@ -1259,15 +1267,25 @@ cpp_indentation (IAnjutaEditor *editor,
 	{
 		if (ch == '[' || ch == '(')
 		            {
-						gchar *prev_char;
-						IAnjutaIterable *previous;
+						gchar *prev_char, *next_char;
+						IAnjutaIterable *previous, *next, *next_end;
 
 						previous = ianjuta_iterable_clone (iter, NULL);
 						ianjuta_iterable_previous (previous, NULL);
 						prev_char = ianjuta_editor_get_text (editor, previous, iter, NULL);
 
-						/* If the previous char is a ' we don't have to autocomplete */
-						if (*prev_char != '\'')
+						next = ianjuta_iterable_clone (iter, NULL);
+						ianjuta_iterable_next (next, NULL);
+						next_end = ianjuta_iterable_clone (next, NULL);
+						ianjuta_iterable_next (next_end, NULL);
+						next_char = ianjuta_editor_get_text (editor, next, next_end, NULL);
+
+						/* If the previous char is a ' we don't have to autocomplete,
+						   also we only autocomplete if the next character is white-space
+						   a closing bracket, "," or ";" */
+						if (*prev_char != '\'' &&
+						    (g_ascii_isspace(*next_char) || is_closing_bracket (*next_char) ||
+							 *next_char == ',' || *next_char == ';'|| *next_char == '\0'))
 						{
 							ianjuta_document_begin_undo_action (IANJUTA_DOCUMENT (editor), NULL);
 							ianjuta_iterable_next (iter, NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]