Top |
GtkSourceLanguageManager is an object which processes language description
files and creates and stores GtkSourceLanguage objects, and provides API to
access them.
Use gtk_source_language_manager_get_default()
to retrieve the default
instance of GtkSourceLanguageManager, and
gtk_source_language_manager_guess_language()
to get a GtkSourceLanguage for
given file name and content type.
GtkSourceLanguageManager *
gtk_source_language_manager_new (void
);
Creates a new language manager. If you do not need more than one language
manager or a private language manager instance then use
gtk_source_language_manager_get_default()
instead.
GtkSourceLanguageManager *
gtk_source_language_manager_get_default
(void
);
Returns the default GtkSourceLanguageManager instance.
a GtkSourceLanguageManager. Return value is owned by GtkSourceView library and must not be unref'ed.
[transfer none]
void gtk_source_language_manager_set_search_path (GtkSourceLanguageManager *lm
,gchar **dirs
);
Sets the list of directories where the lm
looks for
language files.
If dirs
is NULL
, 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.
const gchar * const *
gtk_source_language_manager_get_search_path
(GtkSourceLanguageManager *lm
);
Gets the list directories where lm
looks for language files.
NULL
-terminated array
containg a list of language files directories.
The array is owned by lm
and must not be modified.
[array zero-terminated=1][transfer none]
const gchar * const *
gtk_source_language_manager_get_language_ids
(GtkSourceLanguageManager *lm
);
Returns the ids of the available languages.
GtkSourceLanguage * gtk_source_language_manager_get_language (GtkSourceLanguageManager *lm
,const gchar *id
);
Gets the GtkSourceLanguage identified by the given id
in the language
manager.
a GtkSourceLanguage, or NULL
if there is no language identified by the given id
. Return value is
owned by lm
and should not be freed.
[nullable][transfer none]
GtkSourceLanguage * gtk_source_language_manager_guess_language (GtkSourceLanguageManager *lm
,const gchar *filename
,const gchar *content_type
);
Picks a GtkSourceLanguage for given file name and content type,
according to the information in lang files. Either filename
or
content_type
may be NULL
. This function can be used as follows:
1 2 3 |
GtkSourceLanguage *lang; lang = gtk_source_language_manager_guess_language (filename, NULL); gtk_source_buffer_set_language (buffer, lang); |
or
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
GtkSourceLanguage *lang = NULL; 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; } lang = gtk_source_language_manager_guess_language (manager, filename, content_type); gtk_source_buffer_set_language (buffer, lang); g_free (content_type); |
etc. Use gtk_source_language_get_mime_types()
and gtk_source_language_get_globs()
if you need full control over file -> language mapping.
a GtkSourceLanguage, or NULL
if there
is no suitable language for given filename
and/or content_type
. Return
value is owned by lm
and should not be freed.
[nullable][transfer none]
Since: 2.4
“language-ids”
property“language-ids” GStrv
List of the ids of the available languages.
Owner: GtkSourceLanguageManager
Flags: Read
“search-path”
property“search-path” GStrv
List of directories where the language specification files (.lang) are located.
Owner: GtkSourceLanguageManager
Flags: Read / Write