[gnome-builder] buffer: add language id helper



commit 6460f009adfcdec91267b7fa74174a2eae2a1b26
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jun 19 20:35:20 2018 -0700

    buffer: add language id helper
    
    I'm sort of tired of writing the get language, get language id
    dance.

 src/libide/buffers/ide-buffer.c | 21 +++++++++++++++++++++
 src/libide/buffers/ide-buffer.h |  2 ++
 2 files changed, 23 insertions(+)
---
diff --git a/src/libide/buffers/ide-buffer.c b/src/libide/buffers/ide-buffer.c
index 8d2fb5906..c6c7e966d 100644
--- a/src/libide/buffers/ide-buffer.c
+++ b/src/libide/buffers/ide-buffer.c
@@ -3489,3 +3489,24 @@ ide_buffer_get_build_flags_finish (IdeBuffer     *self,
 
   return ide_task_propagate_pointer (IDE_TASK (result), error);
 }
+
+/**
+ * ide_buffer_get_language_id:
+ * @self: a #IdeBuffer
+ *
+ * A helper to get the language identifier of the buffers current language.
+ *
+ * Returns: (nullable): a string containing the language id, or %NULL
+ */
+const gchar *
+ide_buffer_get_language_id (IdeBuffer *self)
+{
+  GtkSourceLanguage *lang;
+
+  g_return_val_if_fail (IDE_IS_BUFFER (self), NULL);
+
+  if ((lang = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (self))))
+    return gtk_source_language_get_id (lang);
+
+  return NULL;
+}
diff --git a/src/libide/buffers/ide-buffer.h b/src/libide/buffers/ide-buffer.h
index ac439d595..06bd0637c 100644
--- a/src/libide/buffers/ide-buffer.h
+++ b/src/libide/buffers/ide-buffer.h
@@ -170,5 +170,7 @@ IDE_AVAILABLE_IN_3_30
 gchar                   **ide_buffer_get_build_flags_finish        (IdeBuffer            *self,
                                                                     GAsyncResult         *result,
                                                                     GError              **error);
+IDE_AVAILABLE_IN_3_30
+const gchar              *ide_buffer_get_language_id               (IdeBuffer            *self);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]