gedit syntax highlighting for the Google Go language
Since I am writing lot’s of Go code lately I have configured a syntax highlighting description file for gedit. I am pretty sure, that it is not only for gedit, but for all of the gtk apps in gnome. To install it, just copy the go.lang file to your /usr/share/gtksourceview-2.0/language-specs/ directory.
Actually I have tested it only for a debian 5.04 installation - but I am pretty sure it will work on Ubuntu, too.
Download:
go.lang
I f you don’t have a /usr/share/gtksourceview-2.0/language-specs/ directory, check where your gnome is based and search for similar files like java.lang or c.lang. Then install go.lang and restart gedit - (more about this on gnome.org)
Please report any bugs here! Thanks.
NOTE: I am sure willing to contribute this file to the gnome base distribution, but don’t know how… so please feel free to do that - and please keep me informed. Thanks.
To have gedit detect automatically which highlighting to apply to go files, it is necessary to map a mime type. If go doesn’t yet have a mime type specified then you need to create a new one. It is good practice to also put the custom user mime types in a local user directory. For the mime type database this is: ~/.local/share/mime. You will need to add a new mime type specification file in the directory ~/.local/share/mime/packages (create it if it doesn’t exist yet). Add a file go.xml in that directory which looks like this:
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="text/x-go">
<comment>Go Source</comment>
<!-- more translated comment elements -->
<glob pattern="*.go"/>
</mime-type>
</mime-info>
Important here is to specify a type (text/x-go) and the glob pattern to match the file to the mime type. Once you’ve created the file, go to the directory ~/.local/share and run: update-mime-database mime. The mime types should now be registered and after a restart of gedit your language should automatically be mapped to the correct files.










June 17th, 2010 at 12:47 pm
Have you looked at http://go-lang.cat-v.org/text-editors/gedit/ for al the other Gedit language files? It would be good if someone could merge all teh efforts into a single official offering.
June 21st, 2010 at 3:27 pm
Thanks Russel for the hint. I’ll check if I can do the merge.
October 3rd, 2010 at 6:31 pm
I just read this entry now – thank you for committing this! I searched for possible Go editors with integrated highlighting, but of course it’s pretty much easier to use gedit with your syntax definitions (particularly because I love gedit and prefer it to all other editors I have tested so far).
Thanks a lot – if I find some syntax highlighting bugs, I’ll post them here.