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.
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.