SF.net SVN: geany: [545] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Mon Jul 10 16:02:23 UTC 2006


Revision: 545
Author:   eht16
Date:     2006-07-10 09:02:17 -0700 (Mon, 10 Jul 2006)
ViewCVS:  http://svn.sourceforge.net/geany/?rev=545&view=rev

Log Message:
-----------
Autocompletion only works on blank lines.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/sci_cb.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-07-09 14:41:53 UTC (rev 544)
+++ trunk/ChangeLog	2006-07-10 16:02:17 UTC (rev 545)
@@ -1,3 +1,8 @@
+2006-07-10  Enrico Tröger  <enrico.troeger at uvena.de>
+
+ * src/sci_cb.c: Autocompletion only works on blank lines.
+
+
 2006-07-09  Enrico Tröger  <enrico.troeger at uvena.de>
 
  * tagmanager/d.c, tagmanager/Makefile.am, tagmanager/parsers.h,

Modified: trunk/src/sci_cb.c
===================================================================
--- trunk/src/sci_cb.c	2006-07-09 14:41:53 UTC (rev 544)
+++ trunk/src/sci_cb.c	2006-07-10 16:02:17 UTC (rev 545)
@@ -550,14 +550,17 @@
 
 void sci_cb_auto_forif(ScintillaObject *sci, gint pos, gint idx)
 {
-	static gchar buf[8];
+	static gchar buf[16];
 	gchar *eol;
 	gchar *construct;
-	gint lexer = SSM(sci, SCI_GETLEXER, 0, 0);
-	gint style = SSM(sci, SCI_GETSTYLEAT, pos - 2, 0);
-	//gint line = sci_get_line_from_position(sci, pos);
-	//gint start_style = SSM(sci, SCI_GETSTYLEAT, sci_get_position_from_line(sci, line), 0);
+	gint lexer, style;
+	gint i;
 
+	if (sci == NULL || idx == -1 || ! doc_list[idx].is_valid) return;
+
+	lexer = SSM(sci, SCI_GETLEXER, 0, 0);
+	style = SSM(sci, SCI_GETSTYLEAT, pos - 2, 0);
+
 	// only for C, C++, Java, Perl and PHP
 	if (lexer != SCLEX_CPP &&
 		lexer != SCLEX_HTML &&
@@ -571,6 +574,7 @@
 	    style == SCE_C_COMMENTDOC ||
 	    style == SCE_C_COMMENTLINEDOC ||
 		style == SCE_C_STRING ||
+		style == SCE_C_CHARACTER ||
 		style == SCE_C_PREPROCESSOR)) return;
 	if (lexer == SCLEX_HTML && ! (style >= 118 && style <= 127)) return;
 
@@ -583,21 +587,30 @@
 	// get the indention
 	if (doc_list[idx].use_auto_indention) sci_cb_get_indent(sci, pos, TRUE);
 	eol = g_strconcat(utils_get_eol_char(idx), indent, NULL);
-	sci_get_text_range(sci, pos - 8, pos - 1, buf);
-	// "pattern", buf + x, y -> x + y = 7, because buf is (pos - 8)...(pos - 1) = 7
-	if (! strncmp("if", buf + 5, 2))
+	sci_get_text_range(sci, pos - 16, pos - 1, buf);
+	// check the first 8 characters of buf for whitespace, but only in this line
+	i = 14;
+	while (isalpha(buf[i])) i--;	// find pos before keyword
+	while (i >= 0 && buf[i] != '\n' && buf[i] != '\r')	// we want to keep in this line('\n' check)
 	{
-		if (! isspace(*(buf + 4))) goto free_and_return;
+		if (! isspace(buf[i])) goto free_and_return;
+		i--;
+	}
 
+	// "pattern", buf + x, y -> x + y = 15, because buf is (pos - 16)...(pos - 1) = 15
+	if (! strncmp("if", buf + 13, 2))
+	{
+		if (! isspace(*(buf + 12))) goto free_and_return;
+
 		construct = g_strdup_printf("()%s{%s\t%s}%s", eol, eol, eol, eol);
 
 		SSM(sci, SCI_INSERTTEXT, pos, (sptr_t) construct);
 		sci_goto_pos(sci, pos + 1, TRUE);
 		g_free(construct);
 	}
-	else if (! strncmp("else", buf + 3, 4))
+	else if (! strncmp("else", buf + 11, 4))
 	{
-		if (! isspace(*(buf + 2))) goto free_and_return;
+		if (! isspace(*(buf + 10))) goto free_and_return;
 
 		construct = g_strdup_printf("%s{%s\t%s}%s", eol, eol, eol, eol);
 
@@ -605,12 +618,12 @@
 		sci_goto_pos(sci, pos + 4 + (2 * strlen(indent)), TRUE);
 		g_free(construct);
 	}
-	else if (! strncmp("for", buf + 4, 3))
+	else if (! strncmp("for", buf + 12, 3))
 	{
 		gchar *var;
 		gint contruct_len;
 
-		if (! isspace(*(buf + 3))) goto free_and_return;
+		if (! isspace(*(buf + 11))) goto free_and_return;
 
 		if (doc_list[idx].file_type->id == GEANY_FILETYPES_PHP)
 		{
@@ -634,9 +647,9 @@
 		g_free(var);
 		g_free(construct);
 	}
-	else if (! strncmp("while", buf + 2, 5))
+	else if (! strncmp("while", buf + 10, 5))
 	{
-		if (! isspace(*buf + 1)) goto free_and_return;
+		if (! isspace(*buf + 9)) goto free_and_return;
 
 		construct = g_strdup_printf("()%s{%s\t%s}%s", eol, eol, eol, eol);
 
@@ -644,9 +657,9 @@
 		sci_goto_pos(sci, pos + 1, TRUE);
 		g_free(construct);
 	}
-	else if (! strncmp("do", buf + 5, 2))
+	else if (! strncmp("do", buf + 13, 2))
 	{
-		if (! isspace(*(buf + 4))) goto free_and_return;
+		if (! isspace(*(buf + 12))) goto free_and_return;
 
 		construct = g_strdup_printf("%s{%s\t%s}%swhile ();%s", eol, eol, eol, eol, eol);
 
@@ -654,9 +667,9 @@
 		sci_goto_pos(sci, pos + 4 + (2 * strlen(indent)), TRUE);
 		g_free(construct);
 	}
-	else if (! strncmp("try", buf + 4, 3))
+	else if (! strncmp("try", buf + 12, 3))
 	{
-		if (! isspace(*(buf + 3))) goto free_and_return;
+		if (! isspace(*(buf + 11))) goto free_and_return;
 
 		construct = g_strdup_printf("%s{%s\t%s}%scatch ()%s{%s\t%s}%s",
 							eol, eol, eol, eol, eol, eol, eol, eol);
@@ -665,9 +678,9 @@
 		sci_goto_pos(sci, pos + 4 + (2 * strlen(indent)), TRUE);
 		g_free(construct);
 	}
-	else if (! strncmp("switch", buf + 1, 6))
+	else if (! strncmp("switch", buf + 9, 6))
 	{
-		if (! isspace(*buf)) goto free_and_return;
+		if (! isspace(*buf + 8)) goto free_and_return;
 
 		construct = g_strdup_printf("()%s{%s\tcase : break;%s\tdefault: %s}%s", eol, eol, eol, eol, eol);
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Commits mailing list