[geany/geany] 9db124: Cleanup HTML entity checks and fix HTML/PHP autocompletion

Nick Treleaven git-noreply at xxxxx
Fri Apr 13 16:41:50 UTC 2012


Branch:      refs/heads/master
Author:      Nick Treleaven <nick.treleaven at btinternet.com>
Committer:   Nick Treleaven <nick.treleaven at btinternet.com>
Date:        Fri, 13 Apr 2012 16:41:50
Commit:      9db1247b96d3815ff470cb02f40eb71eb881c0b6
             https://github.com/geany/geany/commit/9db1247b96d3815ff470cb02f40eb71eb881c0b6

Log Message:
-----------
Cleanup HTML entity checks and fix HTML/PHP autocompletion


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

Modified: src/editor.c
56 files changed, 29 insertions(+), 27 deletions(-)
===================================================================
@@ -1976,7 +1976,7 @@ gboolean editor_show_calltip(GeanyEditor *editor, gint pos)
 static gboolean
 autocomplete_html(ScintillaObject *sci, const gchar *root, gsize rootlen)
 {
-	guint i, j = 0;
+	guint i;
 	gboolean found = FALSE;
 	GString *words;
 	const gchar **entities = symbols_get_html_entities();
@@ -1994,8 +1994,9 @@ gboolean editor_show_calltip(GeanyEditor *editor, gint pos)
 
 		if (! strncmp(entities[i], root, rootlen))
 		{
-			if (j++ > 0)
+			if (words->len)
 				g_string_append_c(words, '\n');
+
 			g_string_append(words, entities[i]);
 			found = TRUE;
 		}
@@ -2030,23 +2031,35 @@ gboolean editor_show_calltip(GeanyEditor *editor, gint pos)
 }
 
 
-/* Check whether to use entity autocompletion:
- * - always in a HTML file except when inside embedded JavaScript, Python, ASP, ...
- * - in a PHP file only when we are outside of <? ?> */
-static gboolean autocomplete_check_for_html(gint ft_id, gint style)
+static gboolean autocomplete_check_html(GeanyEditor *editor, gint style,
+		const gchar *root, gint rootlen)
 {
+	GeanyFiletype *ft = editor->document->file_type;
+	gboolean try = FALSE;
+
 	/* use entity completion when style is not JavaScript, ASP, Python, PHP, ...
 	 * (everything after SCE_HJ_START is for embedded scripting languages) */
-	if (ft_id == GEANY_FILETYPES_HTML && style < SCE_HJ_START)
-		return TRUE;
-
-	if (ft_id == GEANY_FILETYPES_PHP)
+	if (ft->id == GEANY_FILETYPES_HTML && style < SCE_HJ_START)
+		try = TRUE;
+	else if (ft->id == GEANY_FILETYPES_PHP)
 	{
 		/* use entity completion when style is outside of PHP styles */
 		if (! is_style_php(style))
-			return TRUE;
+			try = TRUE;
 	}
+	if (try)
+	{
+		/* Allow something like ""some text"".
+		 * for entity completion we want to have completion for '&' within words. */
+		gchar *tmp = strchr(root, '&');
 
+		if (tmp != NULL)
+		{
+			root = tmp;
+			rootlen = strlen(tmp);
+			return autocomplete_html(editor->sci, root, rootlen);
+		}
+	}
 	return FALSE;
 }
 
@@ -2186,22 +2199,11 @@ gboolean editor_start_auto_complete(GeanyEditor *editor, gint pos, gboolean forc
 
 	if (rootlen > 0)
 	{
-		if (autocomplete_check_for_html(ft->id, style))
-		{
-			/* Allow something like ""some text"". The above startword calculation
-			 * only works on words but for HTML entity completion we also want to have completion
-			 * based on '&' within words. */
-			gchar *tmp = strchr(root, '&');
-			if (tmp != NULL)
-			{
-				root = tmp;
-				rootlen = strlen(tmp);
-			}
-			ret = autocomplete_html(sci, root, rootlen);
-		}
-		else if (ft->id == GEANY_FILETYPES_PHP && style == SCE_HPHP_DEFAULT &&
-				 rootlen == 3 && strcmp(root, "php") == 0 && pos >= 5 &&
-				 sci_get_char_at(sci, pos - 5) == '<' && sci_get_char_at(sci, pos - 4) == '?')
+		ret = autocomplete_check_html(editor, style, root, rootlen);
+		if (ret || (ft->id == GEANY_FILETYPES_PHP && style == SCE_HPHP_DEFAULT &&
+			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 */
 		}


@@ Diff output truncated at 100000 characters. @@


--------------
This E-Mail was brought to you by github_commit_mail.py (Source: TBD).



More information about the Commits mailing list