### Method

# GtkSource LanguageManager guess_language

#### Declaration [src]

    GtkSourceLanguage*
    gtk_source_language_manager_guess_language (
      GtkSourceLanguageManager* lm,
      const gchar* filename,
      const gchar* content_type
    )

#### Description [src]

Picks a `GtkSourceLanguage` for given file name and content type, according to the information in lang files.

Either `filename` or `content_type` may be `NULL`. This function can be used as follows:

    GtkSourceLanguage *lang;
    GtkSourceLanguageManager *manager;
    lm = gtk_source_language_manager_get_default ();
    lang = gtk_source_language_manager_guess_language (manager, filename, NULL);
    gtk_source_buffer_set_language (buffer, lang);

    manager = GtkSource.LanguageManager.get_default()
    language = manager.guess_language(filename=filename, content_type=None)
    buffer.set_language(language=language)

or

    GtkSourceLanguage *lang = NULL;
    GtkSourceLanguageManager *manager;
    gboolean result_uncertain;
    gchar *content_type;

    content_type = g_content_type_guess (filename, NULL, 0, &result_uncertain);
    if (result_uncertain)
      {
        g_free (content_type);
        content_type = NULL;
      }

    manager = gtk_source_language_manager_get_default ();
    lang = gtk_source_language_manager_guess_language (manager, filename, content_type);
    gtk_source_buffer_set_language (buffer, lang);

    g_free (content_type);

    content_type, uncertain = Gio.content_type_guess(filename=filename, data=None)
    if uncertain:
        content_type = None

    manager = GtkSource.LanguageManager.get_default()
    language = manager.guess_language(filename=filename, content_type=content_type)
    buffer.set_language(language=language)

etc. Use `gtk_source_language_get_mime_types()` and `gtk_source_language_get_globs()` if you need full control over file -> language mapping.

#### Parameters

`filename`

  Type: `const gchar*`

  A filename in Glib filename encoding, or `NULL`.

  The argument can be `NULL`.
  The data is owned by the caller of the method.
  The value is a platform-native string, using the preferred OS encoding on Unix and UTF-8 on Windows.

`content_type`

  Type: `const gchar*`

  A content type (as in GIO API), or `NULL`.

  The argument can be `NULL`.
  The data is owned by the caller of the method.
  The value is a NUL terminated UTF-8 string.

#### Return value

Type: `GtkSourceLanguage`

A `GtkSourceLanguage`, or `NULL` if there is no suitable language for given `filename` and/or `content_type`. Return value is owned by `lm` and should not be freed.

The returned data is owned by the instance.
The return value can be `NULL`.