Syntax highlighting of Oberon code (Imperative Programming)
... using the Gnome text editor
There are many text editors that you might use in the lab sessions and in your own programming, but the Gnome text editor
gedit is simple and convenient. However, if you open a file of Oberon code that ends in
.m, the editor by default chooses a seemingly random set of rules for syntax highlighting.
The problem is that the rules built into Gnome identify files with names ending in
.m as containing code written in Objective C, a completely different language. To fix this, we need to add a new rule that identifies these files as containing Oberon code, and add to the text editor a language description that tells it how to highlight the syntax of Oberon.
Of course, you can solve the problem another way by turning off syntax highlighting and work in monochrome; to do this, just choose the menu item View/Highlight mode/None.
Alternatively, follow the instructions below, which assume that the editor is an up-to-date version based on
- Create the directory
~/.local/share/gtksourceview-2.0/language-specs, and in it place this file
- Create the directory
~/.local/share/mime/packages, and in it place this file
Overrides.xml. If the file already exists, then you may need to edit it and incorporate the contents of the
Overrides.xmlfile that is provided here.
- Run the command
update-mime-database ~/.local/share/mime. This will compile the
Overrides.xmlfile into a form that Gnome and the editor can use.
- To my eyes, the default highlighting colours look rather garish. For a more subtle effect, create the directory
~/.local/share/gtksourceview-2.0/styles, and in it place this file
In these instructions,
~ refers to your home directory; if this is
/home/mike, then the first directory mentioned is actually
/home/mike/.local/share/gtksourceview-2.0/language-specs. Note also that by a common unix convention, files and directories whose names start with a dot do not show up in directory listings. Use
ls -a to see them, or choose View/Show hidden files in a browser window.
When you have followed these instructions, you may find that double-clicking on a
.m file shows a dialog box where you must choose to open these files with the Text Editor application. In the editor, you should see the file with appropriate syntax highlighting. If you installed
sober.xml you should see that a new colour scheme named 'Sober' has appeared in the list under Edit/Preferences/Fonts & Colors.
... using Notepad++
[This section was contributed by Merlyn, a former student].
Syntax highlighting can be obtained using the Oberon-2 Lexer plugin, and limited autocompletion using the Obide plugin, both part of the Oberon Revival Project hosted on SourceForge.You need to use Notepad++ v5.7 or earlier, rather than the latest (v5.9 as of time of writing).
Once both plugins have been installed as dictated by the PluginName.txt file in each archive, simply restart Notepad++.
Spivey's preferred style is that Oberon files end with the extension
.m. To configure Notepad++ to automatically recognise
.m files as Oberon files (rather than Matlab ones):
- Launch Notepad++.
- Go to Settings > Style Configurator...
- In the dialog that appears, scroll down the Languages list until you find Oberon-2. (Because it's a plugin, it'll be after all the built-in languages - so unless you really like plugins, it'll be at the very bottom.)
- Select Oberon-2, and note the appearance of the Default ext: and User ext: boxes underneath the LanguageIn the theory of syntax, a set of strings over a specified alphabet.: and Style: selectors.
- Change User ext: from
OB2 Ob2 oB2to
OB2 Ob2 oB2 m
- To check this, run the command
ldd /usr/bin/gedit | grep gtksourceviewand check that it refers to a library with a name like
libgtksourceview-2.0.so.0and not one like
- This creates an entry in
- To fix the plugin's Ctrl-Space function, go to Settings > Shortcut Mapper... and change the other non-plugin function that normally uses Ctrl-Space to something else.
- Short version:
(substituting C:\Program Files (x86)\ for C:\Program Files\ on 64-bit Windows installs, and whatever your system drive letter actually is for C)
- Quit Notepad++
ObideU.dllfrom their respective archives to