Trait sourceview4::prelude::LanguageManagerExt
source · pub trait LanguageManagerExt: IsA<LanguageManager> + Sealed + 'static {
// Provided methods
fn language(&self, id: &str) -> Option<Language> { ... }
fn language_ids(&self) -> Vec<GString> { ... }
fn search_path(&self) -> Vec<GString> { ... }
fn guess_language(
&self,
filename: Option<impl AsRef<Path>>,
content_type: Option<&str>
) -> Option<Language> { ... }
fn set_search_path(&self, dirs: &[&str]) { ... }
fn connect_language_ids_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId { ... }
fn connect_search_path_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId { ... }
}
Expand description
Provided Methods§
sourcefn language_ids(&self) -> Vec<GString>
fn language_ids(&self) -> Vec<GString>
sourcefn search_path(&self) -> Vec<GString>
fn search_path(&self) -> Vec<GString>
sourcefn guess_language(
&self,
filename: Option<impl AsRef<Path>>,
content_type: Option<&str>
) -> Option<Language>
fn guess_language( &self, filename: Option<impl AsRef<Path>>, content_type: Option<&str> ) -> Option<Language>
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:
<informalexample>``<programlisting>
GtkSourceLanguage *lang;
lang = gtk_source_language_manager_guess_language (filename, NULL);
gtk_source_buffer_set_language (buffer, lang);
</programlisting>``</informalexample>
or
<informalexample>``<programlisting>
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);
</programlisting>``</informalexample>
etc. Use LanguageExt::mime_types()
and LanguageExt::globs()
if you need full control over file -> language mapping.
filename
a filename in Glib filename encoding, or None
.
content_type
a content type (as in GIO API), or None
.
Returns
a Language
, or None
if there
is no suitable language for given filename
and/or content_type
. Return
value is owned by self
and should not be freed.
sourcefn set_search_path(&self, dirs: &[&str])
fn set_search_path(&self, dirs: &[&str])
Sets the list of directories where the self
looks for
language files.
If dirs
is None
, the search path is reset to default.
<note>
<para>
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 LanguageManager
,
you have to call this function right after creating it.
</para>
</note>