[geany/geany] 770cda: Merge pull request #2166 from ntrel/user-ft-ext

Nick Treleaven git-noreply at xxxxx
Mon Jun 10 11:15:43 UTC 2019


Branch:      refs/heads/master
Author:      Nick Treleaven <n at trelsoft.com>
Committer:   GitHub <noreply at github.com>
Date:        Mon, 10 Jun 2019 11:15:43 UTC
Commit:      770cda40646e8ebfe6591df03356e2bcb71b875c
             https://github.com/geany/geany/commit/770cda40646e8ebfe6591df03356e2bcb71b875c

Log Message:
-----------
Merge pull request #2166 from ntrel/user-ft-ext

 Always allow user filetype extensions to override system config file


Modified Paths:
--------------
    src/filetypes.c
    src/filetypes.h
    src/filetypesprivate.h

Modified: src/filetypes.c
48 lines changed, 26 insertions(+), 22 deletions(-)
===================================================================
@@ -463,26 +463,8 @@ void filetypes_init(void)
 }
 
 
-/* Find a filetype that predicate returns TRUE for, otherwise return NULL. */
-GeanyFiletype *filetypes_find(GCompareFunc predicate, gpointer user_data)
+static gboolean match_basename(const GeanyFiletype *ft, const gchar *base_filename)
 {
-	guint i;
-
-	for (i = 0; i < filetypes_array->len; i++)
-	{
-		GeanyFiletype *ft = filetypes[i];
-
-		if (predicate(ft, user_data))
-			return ft;
-	}
-	return NULL;
-}
-
-
-static gboolean match_basename(gconstpointer pft, gconstpointer user_data)
-{
-	const GeanyFiletype *ft = pft;
-	const gchar *base_filename = user_data;
 	gint j;
 	gboolean ret = FALSE;
 
@@ -505,7 +487,7 @@ static gboolean match_basename(gconstpointer pft, gconstpointer user_data)
 }
 
 
-static GeanyFiletype *check_builtin_filenames(const gchar *utf8_filename)
+static GeanyFiletype *detect_filetype_conf_file(const gchar *utf8_filename)
 {
 	gchar *lfn = NULL;
 	gchar *path;
@@ -539,8 +521,9 @@ GeanyFiletype *filetypes_detect_from_extension(const gchar *utf8_filename)
 {
 	gchar *base_filename;
 	GeanyFiletype *ft;
+	guint i;
 
-	ft = check_builtin_filenames(utf8_filename);
+	ft = detect_filetype_conf_file(utf8_filename);
 	if (ft)
 		return ft;
 
@@ -551,7 +534,27 @@ GeanyFiletype *filetypes_detect_from_extension(const gchar *utf8_filename)
 	SETPTR(base_filename, g_utf8_strdown(base_filename, -1));
 #endif
 
-	ft = filetypes_find(match_basename, base_filename);
+	for (i = 0; i < filetypes_array->len; i++)
+	{
+		if (match_basename(filetypes[i], base_filename))
+		{
+			ft = filetypes[i];
+			break;
+		}
+	}
+	// check if user config overrides found ft
+	if (ft && !ft->priv->user_extensions)
+	{
+		for (i++; i < filetypes_array->len; i++)
+		{
+			if (filetypes[i]->priv->user_extensions &&
+				match_basename(filetypes[i], base_filename))
+			{
+				ft = filetypes[i];
+				break;
+			}
+		}
+	}
 	if (ft == NULL)
 		ft = filetypes[GEANY_FILETYPES_NONE];
 
@@ -1397,6 +1400,7 @@ static void read_extensions(GKeyFile *sysconfig, GKeyFile *userconfig)
 		gchar **list = g_key_file_get_string_list(
 			(userset) ? userconfig : sysconfig, "Extensions", filetypes[i]->name, &len, NULL);
 
+		filetypes[i]->priv->user_extensions = userset;
 		g_strfreev(filetypes[i]->pattern);
 		/* Note: we allow 'Foo=' to remove all patterns */
 		if (!list)


Modified: src/filetypes.h
3 lines changed, 0 insertions(+), 3 deletions(-)
===================================================================
@@ -196,9 +196,6 @@ extern GPtrArray *filetypes_array;
 extern GSList *filetypes_by_title;
 
 
-GeanyFiletype *filetypes_find(GCompareFunc predicate, gpointer user_data);
-
-
 void filetypes_init(void);
 
 void filetypes_init_types(void);


Modified: src/filetypesprivate.h
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -40,6 +40,7 @@ typedef struct GeanyFiletypePrivate
 	gboolean	xml_indent_tags; /* XML tag autoindentation, for HTML and XML filetypes */
 	GSList		*tag_files;
 	gboolean	warn_color_scheme;
+	gboolean	user_extensions;	// true if extensions were read from user config file
 
 	/* TODO: move to structure in build.h and only put a pointer here */
 	GeanyBuildCommand *filecmds;



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list