GtkSourceLanguageManager

## GtkSourceLanguageManager GtkSourceLanguageManager — Object which provides access to GtkSourceLanguages |

## Synopsis

    #include <gtksourceview/gtksourcelanguagemanager.h>

    struct              GtkSourceLanguageManager;
    GtkSourceLanguageManager * gtk_source_language_manager_new
                                                            (void);
    GtkSourceLanguageManager * gtk_source_language_manager_get_default
                                                            (void);
    void                gtk_source_language_manager_set_search_path
                                                            (GtkSourceLanguageManager *lm,
                                                             gchar **dirs);
    const gchar * const * gtk_source_language_manager_get_search_path
                                                            (GtkSourceLanguageManager *lm);
    const gchar * const * gtk_source_language_manager_get_language_ids
                                                            (GtkSourceLanguageManager *lm);
    GtkSourceLanguage * gtk_source_language_manager_get_language
                                                            (GtkSourceLanguageManager *lm,
                                                             const gchar *id);
    GtkSourceLanguage * gtk_source_language_manager_guess_language
                                                            (GtkSourceLanguageManager *lm,
                                                             const gchar *filename,
                                                             const gchar *content_type);

## Object Hierarchy

      GObject
       +----GtkSourceLanguageManager

## Properties

      "language-ids"             GStrv                 : Read
      "search-path"              GStrv                 : Read / Write

## Description

GtkSourceLanguageManager is an object which processes language description files and creates and stores GtkSourceLanguage objects, and provides API to access them. Use `gtk_source_language_manager_get_default()` to retrieve the default instance of GtkSourceLanguageManager, and `gtk_source_language_manager_guess_language()` to get a GtkSourceLanguage for given file name and content type.

## Details

### struct GtkSourceLanguageManager

    struct GtkSourceLanguageManager;

### gtk_source_language_manager_new ()

    GtkSourceLanguageManager * gtk_source_language_manager_new
                                                            (void);

Creates a new language manager. If you do not need more than one language manager or a private language manager instance then use `gtk_source_language_manager_get_default()` instead.

Returns : | a new GtkSourceLanguageManager.

### gtk_source_language_manager_get_default ()

    GtkSourceLanguageManager * gtk_source_language_manager_get_default
                                                            (void);

Returns the default GtkSourceLanguageManager instance.

Returns : | a GtkSourceLanguageManager. Return value is owned by GtkSourceView library and must not be unref'ed. [transfer none]

### gtk_source_language_manager_set_search_path ()

    void                gtk_source_language_manager_set_search_path
                                                            (GtkSourceLanguageManager *lm,
                                                             gchar **dirs);

Sets the list of directories where the `lm` looks for language files. If `dirs` is `NULL`, the search path is reset to default.

### Note

At the moment this function can be called only before the language files are loaded for the first time. In practice to set a custom search path for a GtkSourceLanguageManager, you have to call this function right after creating it.

`lm` : | a GtkSourceLanguageManager.
`dirs` : | a `NULL`-terminated array of strings or `NULL`. [allow-none][array zero-terminated=1]

### gtk_source_language_manager_get_search_path ()

    const gchar * const * gtk_source_language_manager_get_search_path
                                                            (GtkSourceLanguageManager *lm);

Gets the list directories where `lm` looks for language files.

`lm` : | a GtkSourceLanguageManager.
Returns : | `NULL`-terminated array containg a list of language files directories. The array is owned by `lm` and must not be modified. [array zero-terminated=1][transfer none]

### gtk_source_language_manager_get_language_ids ()

    const gchar * const * gtk_source_language_manager_get_language_ids
                                                            (GtkSourceLanguageManager *lm);

Returns the ids of the available languages.

`lm` : | a GtkSourceLanguageManager.
Returns : | a `NULL`-terminated array of string containing the ids of the available languages or `NULL` if no language is available. The array is owned by `lm` and must not be modified. [transfer none]

### gtk_source_language_manager_get_language ()

    GtkSourceLanguage * gtk_source_language_manager_get_language
                                                            (GtkSourceLanguageManager *lm,
                                                             const gchar *id);

Gets the GtkSourceLanguage identified by the given `id` in the language manager.

`lm` : | a GtkSourceLanguageManager.
`id` : | a language id.
Returns : | a GtkSourceLanguage, or `NULL` if there is no language identified by the given `id`. Return value is owned by `lm` and should not be freed. [transfer none]

### gtk_source_language_manager_guess_language ()

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

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:

    1
    2
    3
    GtkSourceLanguage *lang;
    lang = gtk_source_language_manager_guess_language (filename, NULL);
    gtk_source_buffer_set_language (buffer, lang);

or

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    GtkSourceLanguage *lang = NULL;
    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;
      }

    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.

`lm` : | a GtkSourceLanguageManager.
`filename` : | a filename in Glib filename encoding, or `NULL`. [allow-none]
`content_type` : | a content type (as in GIO API), or `NULL`. [allow-none]
Returns : | 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. [transfer none]

Since 2.4

## Property Details

### The `"language-ids"` property

      "language-ids"             GStrv                 : Read

List of the ids of the available languages.

### The `"search-path"` property

      "search-path"              GStrv                 : Read / Write

List of directories where the language specification files (.lang) are located.

## See Also

GtkSourceLanguage