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 the- managerlooks 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 given- idin 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 - filenameor- content_typemay 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_typesand- get_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 the- managerlooks 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 - dirsis- 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.