## GtkSourceLanguageManager

GtkSourceLanguageManager — Provides access to GtkSourceLanguages

## Functions

GtkSourceLanguageManager * | gtk_source_language_manager_new ()
GtkSourceLanguageManager * | gtk_source_language_manager_get_default ()
void | gtk_source_language_manager_set_search_path ()
const gchar * const * | gtk_source_language_manager_get_search_path ()
const gchar * const * | gtk_source_language_manager_get_language_ids ()
GtkSourceLanguage * | gtk_source_language_manager_get_language ()
GtkSourceLanguage * | gtk_source_language_manager_guess_language ()

## Properties

GStrv | language-ids | Read
GStrv | search-path | Read / Write

## Types and Values

| GtkSourceLanguageManager

## Object Hierarchy

        GObject
        ╰── GtkSourceLanguageManager

## Includes

    #include <gtksourceview/gtksource.h>

## 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.

## Functions

### 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.

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.

#### Parameters

lm | a GtkSourceLanguageManager. |
dirs | a `NULL`-terminated array of strings or `NULL`. | [nullable][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.

#### Parameters

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.

#### Parameters

lm | a GtkSourceLanguageManager. |

#### Returns

a `NULL`-terminated array of strings containing the ids of the available languages or `NULL` if no language is available. The array is sorted alphabetically according to the language name. The array is owned by `lm` and must not be modified.

[nullable][array zero-terminated=1][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.

#### Parameters

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.

[nullable][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.

#### Parameters

lm | a GtkSourceLanguageManager. |
filename | a filename in Glib filename encoding, or `NULL`. | [nullable]
content_type | a content type (as in GIO API), or `NULL`. | [nullable]

#### 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.

[nullable][transfer none]

Since: 2.4

## Types and Values

### GtkSourceLanguageManager

    typedef struct _GtkSourceLanguageManager GtkSourceLanguageManager;

## Property Details

### The `“language-ids”` property

      “language-ids”             GStrv

List of the ids of the available languages.

Flags: Read

### The `“search-path”` property

      “search-path”              GStrv

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

Flags: Read / Write

## See Also

GtkSourceLanguage