LanguageManager
Superclasses: Object
Provides access to Language
’s.
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 themanager
looks for language files.See
set_search_path
for details.Added in version 5.4.
- Parameters:
path – a directory or a filename.
- get_default() LanguageManager
Returns the default
LanguageManager
instance.
- get_language(id: str) Language | None
Gets the
Language
identified by the givenid
in the language manager.- Parameters:
id – a language id.
- 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
orcontent_type
may 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_types
andget_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 themanager
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: Sequence[str] | None = None) None
Sets the list of directories where the
lm
looks for language files.If
dirs
isNone
, 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
GResource
’s. They must contain the path of a directory within theGResource
.- Parameters:
dirs – a
None
-terminated array of strings orNone
.