LanguageManager#
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_defaultinstead.
Methods#
- class LanguageManager
- append_search_path(path: str) None#
Appends
pathto the list of directories where themanagerlooks for language files.See
set_search_pathfor details.Added in version 5.4.
- Parameters:
path – a directory or a filename.
- classmethod get_default() LanguageManager#
Returns the default
LanguageManagerinstance.
- get_language(id: str) Language | None#
Gets the
Languageidentified by the givenidin the language manager.- Parameters:
id – a language id.
- guess_language(filename: str | None = None, content_type: str | None = None) Language | None#
Picks a
Languagefor given file name and content type, according to the information in lang files.Either
filenameorcontent_typemay beNone. 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_typesandget_globsif 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
pathto the list of directories where themanagerlooks for language files.See
set_search_pathfor 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
lmlooks for language files.If
dirsisNone, 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 theGResource.- Parameters:
dirs – a
None-terminated array of strings orNone.