Note: The mercurial server is disabled at the moment while I investigate whether it can run with an acceptably low CPU load – Mike.
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 gtksourceview-2.0
[1]
- Create the directory
~/.local/share/gtksourceview-2.0/language-specs
, and in it place this fileoberon.lang
. - Create the directory
~/.local/share/mime/packages
, and in it place this fileOverrides.xml
. If the file already exists, then you may need to edit it and incorporate the contents of theOverrides.xml
file that is provided here. - Run the command
update-mime-database ~/.local/share/mime
. This will compile theOverrides.xml
file 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 filesober.xml
.
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.[2] 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[3] using the Obide plugin, both part of the Oberon Revival Project hosted on SourceForge.[4]
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[5], 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 Language: and Style: selectors.
- Change User ext: from
OB2 Ob2 oB2
toOB2 Ob2 oB2 m
- ↑ To check this, run the command
ldd /usr/bin/gedit | grep gtksourceview
and check that it refers to a library with a name likelibgtksourceview-2.0.so.0
and not one likelibgtksourceview-1.0.so.0
- ↑ This creates an entry in
~/.local/share/applications/mimeapps.list
- ↑ 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.
- ↑ http://sf.net/projects/oberonrevival/files
- ↑ 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++
- Extract
Oberon2LexerU.dll
andObideU.dll
from their respective archives toC:\Program Files\Notepad++\Plugins\
. - Extract
Config/Oberon2LexerU.xml
andConfig/Obide.ini
toC:\Program Files\Notepad++\Plugins\Config\
. - Done!