Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

improve autocompletion for C/C++

  • Loading branch information...
commit 6563d848777d90826c4df70e80e0d3e75d6d5775 1 parent 84c3957
Moritz Lüdecke authored June 21, 2012

Showing 1 changed file with 41 additions and 21 deletions. Show diff stats Hide diff stats

  1. 62  plugins/parser-cxx/assist.c
62  plugins/parser-cxx/assist.c
@@ -69,7 +69,7 @@ struct _ParserCxxAssistPriv {
69 69
 	IAnjutaEditorAssist* iassist;
70 70
 	IAnjutaEditorTip* itip;
71 71
 	IAnjutaParser* parser;
72  
-
  72
+	
73 73
 	GCompletion *completion_cache;
74 74
 
75 75
 	/* Calltips */
@@ -846,15 +846,13 @@ parser_cxx_assist_populate (IAnjutaProvider* self, IAnjutaIterable* cursor, GErr
846 846
 
847 847
 /**
848 848
  * parser_cxx_assist_find_next_brace:
849  
- * @self: ParserCxxAssist object
850 849
  * @iter: Iter to start searching at
851 850
  *
852  
- * Returns: TRUE if the next non-whitespace character is a opening brace,
853  
- * FALSE otherwise
  851
+ * Returns: The position of the brace, if the next non-whitespace character is a opening brace,
  852
+ * NULL otherwise
854 853
  */
855  
-static gboolean
856  
-parser_cxx_assist_find_next_brace (ParserCxxAssist* assist,
857  
-                                 IAnjutaIterable* iter)
  854
+static IAnjutaIterable*
  855
+parser_cxx_assist_find_next_brace (IAnjutaIterable* iter)
858 856
 {
859 857
 	IAnjutaIterable* my_iter = ianjuta_iterable_clone (iter, NULL);
860 858
 	char ch;
@@ -862,14 +860,29 @@ parser_cxx_assist_find_next_brace (ParserCxxAssist* assist,
862 860
 	{
863 861
 		ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (my_iter), 0, NULL);
864 862
 		if (ch == '(')
865  
-		{
866  
-			g_object_unref (my_iter);
867  
-		    return TRUE;
868  
-		}
  863
+			return my_iter;
869 864
 	}
870 865
 	while (g_ascii_isspace (ch) && ianjuta_iterable_next (my_iter, NULL));
871 866
 	
872  
-	return FALSE;
  867
+	g_object_unref (my_iter);
  868
+	return NULL;
  869
+}
  870
+
  871
+/**
  872
+ * parser_cxx_assist_find_whitespace:
  873
+ * @iter: Iter to start searching at
  874
+ *
  875
+ * Returns: TRUE if the next character is a whitespace character,
  876
+ * FALSE otherwise
  877
+ */
  878
+static gboolean
  879
+parser_cxx_assist_find_whitespace (IAnjutaIterable* iter)
  880
+{
  881
+	char ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (iter), 0, NULL);
  882
+	if (g_ascii_isspace (ch) && ch != '\n' && parser_cxx_assist_find_next_brace(iter))
  883
+		return TRUE;
  884
+	else
  885
+		return FALSE;
873 886
 }
874 887
 
875 888
 /**
@@ -898,6 +911,7 @@ parser_cxx_assist_activate (IAnjutaProvider* self, IAnjutaIterable* iter, gpoint
898 911
 	
899 912
 	if (prop_data->is_func)
900 913
 	{
  914
+		IAnjutaIterable* next_brace = parser_cxx_assist_find_next_brace (iter);
901 915
 		add_space_after_func =
902 916
 			g_settings_get_boolean (assist->priv->settings,
903 917
 			                        PREF_AUTOCOMPLETE_SPACE_AFTER_FUNC);
@@ -908,20 +922,19 @@ parser_cxx_assist_activate (IAnjutaProvider* self, IAnjutaIterable* iter, gpoint
908 922
 			g_settings_get_boolean (assist->priv->settings,
909 923
 			                        PREF_AUTOCOMPLETE_CLOSEBRACE_AFTER_FUNC);
910 924
 
911  
-		if (!parser_cxx_assist_find_next_brace (assist, iter))
912  
-		{
913  
-			if (add_space_after_func)
914  
-				g_string_append (assistance, " ");
915  
-			if (add_brace_after_func)
916  
-				g_string_append (assistance, "(");
917  
-		}
  925
+		if (add_space_after_func && !parser_cxx_assist_find_whitespace (iter))
  926
+			g_string_append (assistance, " ");
  927
+		if (add_brace_after_func && !next_brace)
  928
+			g_string_append (assistance, "(");
  929
+		else
  930
+			g_object_unref (next_brace);
918 931
 	}
919 932
 	
920 933
 	te = IANJUTA_EDITOR (assist->priv->iassist);
921 934
 		
922 935
 	ianjuta_document_begin_undo_action (IANJUTA_DOCUMENT (te), NULL);
923 936
 	
924  
-	if (ianjuta_iterable_compare(iter, assist->priv->start_iter, NULL) != 0)
  937
+	if (ianjuta_iterable_compare (iter, assist->priv->start_iter, NULL) != 0)
925 938
 	{
926 939
 		ianjuta_editor_selection_set (IANJUTA_EDITOR_SELECTION (te),
927 940
 									  assist->priv->start_iter, iter, FALSE, NULL);
@@ -941,7 +954,14 @@ parser_cxx_assist_activate (IAnjutaProvider* self, IAnjutaIterable* iter, gpoint
941 954
 									   ianjuta_iterable_get_position (assist->priv->start_iter, NULL)
942 955
 									   + strlen (assistance->str),
943 956
 									   NULL);
944  
-		ianjuta_editor_insert (te, pos, ")", -1, NULL);
  957
+		if (!parser_cxx_assist_find_next_brace (pos))
  958
+			ianjuta_editor_insert (te, pos, ")", -1, NULL);
  959
+		else
  960
+		{
  961
+			pos = parser_cxx_assist_find_next_brace (pos);
  962
+			ianjuta_iterable_next (pos, NULL);
  963
+		}
  964
+		
945 965
 		ianjuta_editor_goto_position (te, pos, NULL);
946 966
 
947 967
 		ianjuta_iterable_previous (pos, NULL);

0 notes on commit 6563d84

Please sign in to comment.
Something went wrong with that request. Please try again.