24

How can I add in the regular expressions for an additional syntax language?

belacqua
  • 22,880
  • 23
  • 88
  • 108
700 Software
  • 2,187
  • 4
  • 23
  • 29
  • 1
    Be more specific, what text editor are you talking about? Gedit? – enzotib Aug 02 '11 at 12:43
  • You should tell us, which editor you use; gedit, mcedit, scite? And if you tell us the language, maybe we know, where to get a syntax file. – user unknown Aug 02 '11 at 12:46
  • 1
    The language is actually a highlighting scheme for a text file. We invented it so it does not exist anywhere. The editor is the default editor that comes with Ubuntu. It just says Text Editor, but in Help About it says **gedit**. – 700 Software Aug 02 '11 at 13:56

2 Answers2

28

Gedit (the default text editor) using GTKSourceView for it's syntax highlighting. It uses XML files to define how to highlight different syntax.

There is a tutorial and a reference document on the GTKSourceView site. Finished source file definitions are stored in /usr/share/gtksourceview-2.0/language-specs/ or /usr/share/gtksourceview-3.0/language-specs/, you might want to check them out to learn by example.

There is also a less in depth tutorial on the Gedit site.

After you create your new language spec, restart gedit and it will automatically add it to its list of languages.

Erel Segal-Halevi
  • 2,201
  • 8
  • 38
  • 57
David Futcher
  • 663
  • 4
  • 6
  • 2
    Editors running in up-to-date versions of Ubuntu will probably be using *gtksourcceview-3.0* .. so look for a directory with *3.0*, not *2.0* as in the answer above. – Eyal Aug 09 '14 at 15:53
  • All of the links are broken :-/ A redirect is super helpful for people researching this topic years later... – VasyaNovikov Jul 30 '23 at 08:44
3

I assume you are talking about gedit (labeled as "text editor" in the ubuntu menu).

Gedit is using GtkSourceView for syntax highlighting. You have to create a language definition for GtkSourceView.

Here is a tutorial: https://developer.gnome.org/gtksourceview/stable/lang-tutorial.html

update 2021: link dead. now here: https://developer-old.gnome.org/gtksourceview/stable/lang-tutorial.html

i do not know why it is "developer-old" now. maybe deprecated. i was not able to find a new tutorial. but i did not search much.

here is the new gnome developer tutorials: https://developer.gnome.org/documentation/tutorials.html

i did not find a gedit syntax highlight tutorial there.

Lesmana
  • 18,126
  • 8
  • 52
  • 49