GtkSource.LanguageManager.guess_language

### Method

# GtkSource LanguageManagerguess_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);

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);

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` | `const gchar*`
| A filename in Glib filename encoding, or `NULL`.
| The argument can be `NULL`.
| The data is owned by the caller of the function.
| The value is a file system path, using the OS encoding.
`content_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 function.
| The value is a NUL terminated UTF-8 string.

#### Return value

Returns: | `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 data is owned by the instance.
| The return value can be `NULL`.