SF.net SVN: geany:[5900] trunk/src/editor.c

colombanw at users.sourceforge.net colombanw at xxxxx
Thu Aug 25 20:12:37 UTC 2011


Revision: 5900
          http://geany.svn.sourceforge.net/geany/?rev=5900&view=rev
Author:   colombanw
Date:     2011-08-25 20:12:36 +0000 (Thu, 25 Aug 2011)
Log Message:
-----------
Cleanup code duplication in editor_start_auto_complete()

Use read_current_word() in editor_start_auto_complete() not to
duplicate some code.  This also brings non-ASCII characters as
part of a word, first step for non-ASCII word completions.

Modified Paths:
--------------
    trunk/src/editor.c

Modified: trunk/src/editor.c
===================================================================
--- trunk/src/editor.c	2011-08-25 20:12:20 UTC (rev 5899)
+++ trunk/src/editor.c	2011-08-25 20:12:36 UTC (rev 5900)
@@ -2144,18 +2144,19 @@
 
 gboolean editor_start_auto_complete(GeanyEditor *editor, gint pos, gboolean force)
 {
-	gint line, line_start, current, rootlen, startword, lexer, style;
-	gchar *linebuf, *root;
+	gint rootlen, lexer, style;
+	gchar *root;
+	gchar cword[GEANY_MAX_WORD_LENGTH];
 	ScintillaObject *sci;
 	gboolean ret = FALSE;
 	const gchar *wordchars;
 	GeanyFiletype *ft;
 
+	g_return_val_if_fail(editor != NULL, FALSE);
+
 	if (! editor_prefs.auto_complete_symbols && ! force)
 		return FALSE;
 
-	g_return_val_if_fail(editor != NULL, FALSE);
-
 	/* If we are at the beginning of the document, we skip autocompletion as we can't determine the
 	 * necessary styling information */
 	if (G_UNLIKELY(pos < 2))
@@ -2164,10 +2165,6 @@
 	sci = editor->sci;
 	ft = editor->document->file_type;
 
-	line = sci_get_line_from_position(sci, pos);
-	line_start = sci_get_position_from_line(sci, line);
-	current = pos - line_start;
-	startword = current;
 	lexer = sci_get_lexer(sci);
 	style = sci_get_style_at(sci, pos - 2);
 
@@ -2177,8 +2174,6 @@
 
 	autocomplete_scope(editor);
 
-	linebuf = sci_get_line(sci, line);
-
 	if (ft->id == GEANY_FILETYPES_LATEX)
 		wordchars = GEANY_WORDCHARS"\\"; /* add \ to word chars if we are in a LaTeX file */
 	else if (ft->id == GEANY_FILETYPES_HTML || ft->id == GEANY_FILETYPES_PHP)
@@ -2186,12 +2181,9 @@
 	else
 		wordchars = GEANY_WORDCHARS;
 
-	/* find the start of the current word */
-	while ((startword > 0) && (strchr(wordchars, linebuf[startword - 1])))
-		startword--;
-	linebuf[current] = '\0';
-	root = linebuf + startword;
-	rootlen = current - startword;
+	read_current_word(editor, pos, cword, sizeof(cword), wordchars, TRUE);
+	root = cword;
+	rootlen = strlen(root);
 
 	if (rootlen > 0)
 	{
@@ -2209,7 +2201,8 @@
 			ret = autocomplete_html(sci, root, rootlen);
 		}
 		else if (ft->id == GEANY_FILETYPES_PHP && style == SCE_HPHP_DEFAULT &&
-				 startword >= 2 && rootlen == 3 && strcmp(&root[-2], "<?php") == 0)
+				 rootlen == 3 && strcmp(root, "php") == 0 && pos >= 5 &&
+				 sci_get_char_at(sci, pos - 5) == '<' && sci_get_char_at(sci, pos - 4) == '?')
 		{
 			/* nothing, don't complete PHP open tags */
 		}
@@ -2232,7 +2225,6 @@
 	if (!ret && force)
 		utils_beep();
 
-	g_free(linebuf);
 	return ret;
 }
 

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