LanguageManager#

class LanguageManager(**properties: Any)#

Superclasses: Object

Provides access to Languages.

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

Use get_default to retrieve the default instance of GtkSourceLanguageManager, and guess_language to get a Language for given file name and content type.

Constructors#

class LanguageManager
classmethod new() LanguageManager#

Creates a new language manager.

If you do not need more than one language manager or a private language manager instance then use get_default instead.

Methods#

class LanguageManager
append_search_path(path: str) None#

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

See set_search_path for details.

Added in version 5.4.

Parameters:

path – a directory or a filename.

classmethod get_default() LanguageManager#

Returns the default LanguageManager instance.

get_language(id: str) Language | None#

Gets the Language identified by the given id in the language manager.

Parameters:

id – a language id.

get_language_ids() list[str] | None#

Returns the ids of the available languages.

get_search_path() list[str]#

Gets the list directories where lm looks for language files.

guess_language(filename: str | None = None, content_type: str | None = None) Language | None#

Picks a 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:

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 get_mime_types and get_globs if you need full control over file -> language mapping.

Parameters:
  • filename – a filename in Glib filename encoding, or None.

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

prepend_search_path(path: str) None#

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

See set_search_path for details.

Added in version 5.4.

Parameters:

path – a directory or a filename.

set_search_path(dirs: list[str] | None = None) None#

Sets the list of directories where the lm 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 GtkSourceView 5.4 this function will allow you to provide paths in the form of “resource:///” URIs to embedded GResources. They must contain the path of a directory within the GResource.

Parameters:

dirs – a None-terminated array of strings or None.

Properties#

class LanguageManager
props.language_ids: list[str]#

The type of the None singleton.

props.search_path: list[str]#

The type of the None singleton.