GtkSource.LanguageManager

g GObject.Object GObject.Object GtkSource.LanguageManager GtkSource.LanguageManager GObject.Object->GtkSource.LanguageManager

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

get_default ()

class

new ()

append_search_path (path)

get_language (id)

get_language_ids ()

get_search_path ()

guess_language (filename, content_type)

prepend_search_path (path)

set_search_path (dirs)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

language-ids

[str]

r/en

List of the ids of the available languages

search-path

[str]

r/w/en

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

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class GtkSource.LanguageManager(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

GtkSource.LanguageManagerClass

Provides access to [class`Language`]s.

GtkSourceLanguageManager is an object which processes language description files and creates and stores [class`Language`] objects, and provides API to access them.

Use [func`LanguageManager`.get_default] to retrieve the default instance of GtkSourceLanguageManager, and [method`LanguageManager`.guess_language] to get a [class`Language`] for given file name and content type.

classmethod get_default()
Returns:

a GtkSource.LanguageManager. Return value is owned by GtkSource.View library and must not be unref’ed.

Return type:

GtkSource.LanguageManager

Returns the default GtkSource.LanguageManager instance.

classmethod new()
Returns:

a new GtkSource.LanguageManager.

Return type:

GtkSource.LanguageManager

Creates a new language manager.

If you do not need more than one language manager or a private language manager instance then use [func`LanguageManager`.get_default] instead.

append_search_path(path)
Parameters:

path (str) – a directory or a filename.

Appends path to the list of directories where the manager looks for language files.

See [method`LanguageManager`.set_search_path] for details.

New in version 5.4.

get_language(id)
Parameters:

id (str) – a language id.

Returns:

a GtkSource.Language, or None if there is no language identified by the given id. Return value is owned by self and should not be freed.

Return type:

GtkSource.Language or None

Gets the [class`Language`] identified by the given id in the language manager.

get_language_ids()
Returns:

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

Return type:

[str] or None

Returns the ids of the available languages.

get_search_path()
Returns:

None-terminated array containing a list of language files directories. The array is owned by self and must not be modified.

Return type:

[str]

Gets the list directories where self looks for language files.

guess_language(filename, content_type)
Parameters:
  • filename (str or None) – a filename in Glib filename encoding, or None.

  • content_type (str or None) – a content type (as in GIO API), or None.

Returns:

a GtkSource.Language, or None if there is no suitable language for given filename and/or content_type. Return value is owned by self and should not be freed.

Return type:

GtkSource.Language or None

Picks a [class`Language`] for given file name and content type, according to the information in lang files.

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

``c 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

```c GtkSource.Language *lang = None; GtkSource.LanguageManager *manager; bool result_uncertain; str *content_type;

content_type = Gio.content_type_guess (filename, None, 0, &result_uncertain); if (result_uncertain) { GLib.free (content_type); content_type = None; }

manager = GtkSource.LanguageManager.get_default (); lang = GtkSource.LanguageManager.guess_language (manager, filename, content_type); GtkSource.Buffer.set_language (buffer, lang);

GLib.free (content_type); ```

etc. Use [method`Language`.get_mime_types] and [method`Language`.get_globs] if you need full control over file -> language mapping.

prepend_search_path(path)
Parameters:

path (str) – a directory or a filename.

Prepends path to the list of directories where the manager looks for language files.

See [method`LanguageManager`.set_search_path] for details.

New in version 5.4.

set_search_path(dirs)
Parameters:

dirs ([str] or None) – a None-terminated array of strings or None.

Sets the list of directories where the self looks for language files.

If dirs is None, 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.

Since GtkSource.View 5.4 this function will allow you to provide paths in the form of “resource:///” URIs to embedded GResource``s. They must contain the path of a directory within the ``GResource.

Property Details

GtkSource.LanguageManager.props.language_ids
Name:

language-ids

Type:

[str]

Default Value:

[]

Flags:

READABLE, EXPLICIT_NOTIFY

List of the ids of the available languages

GtkSource.LanguageManager.props.search_path
Name:

search-path

Type:

[str]

Default Value:

[]

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

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