Help with adding a custom .lang GtkSourceView language definition file for use with GNOME Text Editor

I’ve been trying to add a language file to a Fedora 43 setup in order to have syntax highlighting on files when viewing them in GNOME Text Editor. Some of the advice from the GTKSourceView documentation ( GtkSource – 5: Language Definition v2.0 Introduction ) suggests one can do this by placing an appropriate .lang file in a user-specific directory like ~/.local/share/gtksourceview-5/language-specs/ assuming you have the directory parent of gtksourceview-5 listed in either $XDG_DATA_HOME or $XDG_DATA_DIRS.

With this in mind I’ve tried the following:

  1. Create a folder named gtksourceview-5 in ~/.local/share/ (i.e. mkdir ~/.local/share/gtksourceview-5/ ) if there isn’t already one. (NOTE: I have also tried this with the name libgedit-gtksourceview-300 instead too.)
  2. Create a subfolder named language-specs (i.e. mkdir ~/.local/share/gtksourceview-5/language-specs).
  3. Copy in your .lang file (in my specific scenario I was trying to play with one called 1. beancount.lang )
  4. We need a consistent way for the ~/.local/share/ folder to be in the environment variable $XDG_DATA_DIRS. Some other posts out there suggest putting in an export line in ~/.xsessionrc, but that applies to X11 setups, not Wayland. Some also suggest putting it in ~/.profile, but I personally haven’t observed that to work in practice. I’ve found myself creating a link to the user-specific folder via a system-wide (i.e. need sudo) script by creating a xdg.sh file in /etc/profile.d based on the advice here, with the following line in it:
    export XDG_DATA_DIRS=$HOME"/.local/share/:"$XDG_DATA_DIRS
    (NOTE: I have also tried setting the $XDG_DATA_HOME environment variable with export XDG_DATA_HOME=$HOME"/.local/share/")
  5. Okay, with the folder created, the lang file installed, and the script to set the environment variable setup, try logging out of your gnome session or rebooting your machine. Then log back in and:
    1. Check that $XDG_DATA_DIRS is set by running echo $XDG_DATA_DIRS.
    2. Try opening up Text Editor in GNOME, clicking the circle-i icon in the upper right, select ‘Document Type’ and see if your desired language appears. This is where I’m having issues - I don’t seem to ever see my custom language file here, despite seeing the directory set in $XDG_DATA_DIRS, and trying other directory name variations (e.g. libgedit-sourceview-300), etc.

Any idea what might be going wrong?

This works for me:

mkdir -p -Z ~/.local/share/gtksourceview-5/language-specs
wget -P ~/.local/share/gtksourceview-5/language-specs \
https://gitlab.gnome.org/GNOME/gtksourceview/-/\
raw/880cc80a1af0486b0925e306fcceb000215d124c/\
data/language-specs/beancount.lang

wget https://github.com/beancount/beancount/\
raw/refs/heads/master/examples/simple/basic.beancount

gnome-text-editor basic.beancount

If the issue persists, test it under a new user with default settings.

Thanks for the testing this out. Surprisingly it does work under a different user account on the same machine.

EDIT: This was likely due to me using a flatpak-installed version of gnome-text-editor which likely had some sandboxing limitations. Ended up uninstalling the flatpak version, then running sudo dnf reinstall gnome-text-editor to reinstall gnome-text-editor to make sure the Desktop entry gets refreshed, and things work now.