:right-sidebar: True LanguageManager =================================================================== .. currentmodule:: gi.repository.GtkSource .. class:: LanguageManager(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Provides access to :obj:`~gi.repository.GtkSource.Language`\s. ``GtkSourceLanguageManager`` is an object which processes language description files and creates and stores :obj:`~gi.repository.GtkSource.Language` objects, and provides API to access them. Use :obj:`~gi.repository.LanguageManager.get_default` to retrieve the default instance of ``GtkSourceLanguageManager``\, and :obj:`~gi.repository.LanguageManager.guess_language` to get a :obj:`~gi.repository.GtkSource.Language` for given file name and content type. Constructors ------------ .. rst-class:: interim-class .. class:: LanguageManager :no-index: .. classmethod:: new() -> ~gi.repository.GtkSource.LanguageManager Creates a new language manager. If you do not need more than one language manager or a private language manager instance then use :obj:`~gi.repository.LanguageManager.get_default` instead. Methods ------- .. rst-class:: interim-class .. class:: LanguageManager :no-index: .. method:: append_search_path(path: str) -> None Appends ``path`` to the list of directories where the ``manager`` looks for language files. See :obj:`~gi.repository.LanguageManager.set_search_path` for details. .. versionadded:: 5.4 :param path: a directory or a filename. .. classmethod:: get_default() -> ~gi.repository.GtkSource.LanguageManager Returns the default :obj:`~gi.repository.GtkSource.LanguageManager` instance. .. method:: get_language(id: str) -> ~gi.repository.GtkSource.Language | None Gets the :obj:`~gi.repository.GtkSource.Language` identified by the given ``id`` in the language manager. :param id: a language id. .. method:: get_language_ids() -> list[str] | None Returns the ids of the available languages. .. method:: get_search_path() -> list[str] Gets the list directories where ``lm`` looks for language files. .. method:: guess_language(filename: str | None = None, content_type: str | None = None) -> ~gi.repository.GtkSource.Language | None Picks a :obj:`~gi.repository.GtkSource.Language` for given file name and content type, according to the information in lang files. Either ``filename`` or ``content_type`` may be :const:`None`. This function can be used as follows: .. code-block:: c :dedent: 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 .. code-block:: c :dedent: 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 :obj:`~gi.repository.Language.get_mime_types` and :obj:`~gi.repository.Language.get_globs` if you need full control over file -> language mapping. :param filename: a filename in Glib filename encoding, or :const:`None`. :param content_type: a content type (as in GIO API), or :const:`None`. .. method:: prepend_search_path(path: str) -> None Prepends ``path`` to the list of directories where the ``manager`` looks for language files. See :obj:`~gi.repository.LanguageManager.set_search_path` for details. .. versionadded:: 5.4 :param path: a directory or a filename. .. method:: set_search_path(dirs: list[str] | None = None) -> None Sets the list of directories where the ``lm`` looks for language files. If ``dirs`` is :const:`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 ``GResource``\s. They must contain the path of a directory within the ``GResource``\. :param dirs: a :const:`None`-terminated array of strings or :const:`None`. Properties ---------- .. rst-class:: interim-class .. class:: LanguageManager :no-index: .. attribute:: props.language_ids :type: list[str] The type of the None singleton. .. attribute:: props.search_path :type: list[str] The type of the None singleton.