[gnome-builder] buffers: remove trailing ".in" when guessing language
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] buffers: remove trailing ".in" when guessing language
- Date: Tue, 23 Oct 2018 20:15:41 +0000 (UTC)
commit 59e1a00e9a00796036cb1add76b031cdbdca36f3
Author: Christian Hergert <chergert redhat com>
Date: Tue Oct 23 13:14:24 2018 -0700
buffers: remove trailing ".in" when guessing language
When guessing the language from GtkSourceView, we can remove the trailing
.in so that we are more likely to get the proper language type. This is
useful because rarely are people simply caring about the template expansion
and more interested in the underlying language syntax.
Fixes #681
src/libide/buffers/ide-buffer-manager.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/src/libide/buffers/ide-buffer-manager.c b/src/libide/buffers/ide-buffer-manager.c
index 2f37d38e9..a83d6c858 100644
--- a/src/libide/buffers/ide-buffer-manager.c
+++ b/src/libide/buffers/ide-buffer-manager.c
@@ -456,9 +456,11 @@ ide_buffer_manager_load_file__load_cb (GObject *object,
g_autoptr(IdeTask) task = user_data;
g_autofree gchar *guess_contents = NULL;
g_autofree gchar *content_type = NULL;
+ g_autofree gchar *truncated = NULL;
GtkSourceFileLoader *loader = (GtkSourceFileLoader *)object;
IdeBufferManager *self;
const gchar *path;
+ const gchar *dot;
IdeContext *context;
LoadState *state;
GtkTextIter iter;
@@ -540,8 +542,15 @@ ide_buffer_manager_load_file__load_cb (GObject *object,
gtk_text_iter_forward_chars (&end, 1024);
guess_contents = gtk_text_iter_get_slice (&iter, &end);
path = ide_file_get_path (state->file);
- content_type = g_content_type_guess (path, (const guchar *)guess_contents,
- strlen (guess_contents), &uncertain);
+
+ /* Remove the ".in" suffix for files that are expanded at build time. */
+ if ((dot = strrchr (path, '.')))
+ path = truncated = g_strndup (path, dot - path);
+
+ content_type = g_content_type_guess (path,
+ (const guchar *)guess_contents,
+ strlen (guess_contents),
+ &uncertain);
if (content_type && !uncertain)
_ide_file_set_content_type (state->file, content_type);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]