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

get_language (id)

get_language_ids ()

get_search_path ()

guess_language (filename, content_type)

set_search_path (dirs)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

language-ids

[str]

r

List of the ids of the available languages

search-path

[str]

r/w

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

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class GtkSource.LanguageManager(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

GtkSource.LanguageManagerClass

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 GtkSource.LanguageManager.get_default() instead.

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 GtkSource.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 containg 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 GtkSource.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:

<informalexample><programlisting> GtkSource.Language *lang; lang = GtkSource.LanguageManager.guess_language (filename, None); GtkSource.Buffer.set_language (buffer, lang); </programlisting></informalexample>

or

<informalexample><programlisting> GtkSource.Language *lang = None; 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; }

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

GLib.free (content_type); </programlisting></informalexample>

etc. Use GtkSource.Language.get_mime_types() and GtkSource.Language.get_globs() if you need full control over file -> language mapping.

New in version 2.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 GtkSource.LanguageManager, you have to call this function right after creating it.

Property Details

GtkSource.LanguageManager.props.language_ids
Name:

language-ids

Type:

[str]

Default Value:

[]

Flags:

READABLE

List of the ids of the available languages

GtkSource.LanguageManager.props.search_path
Name:

search-path

Type:

[str]

Default Value:

[]

Flags:

READABLE, WRITABLE

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