EDIT -- This is now part of gtksourceview so future versions of gedit will have it
Hi
I've been changing the file that takes care of octave syntax highlight in gedit (syntax highlight is taken care by gtksourceview so I'm guessing other text editors may also use it) and I plan on giving it to the developers but I'd like have some opinions/test from other users too.
I am still but a basic user of octave (I only started a month ago) so I would appreciate if other users, that probably have much better code with all kind of tricks, could give it a go and say if everything still looks good when they try the strange things.
In gtksourceview, every file has its own 'lang' file which defines the syntax highlight of that language. It's basically a bunch of regular expressions, in a XML file, pointing to different styles of formatting.
The file is attached (I had to archive into a tar to upload into the forum). To give it a try, move it into the folder
Code:
/usr/share/gtksourceview-2.0/language-specs
You may want to backup up the old one first but if you don't, the file that is being distributed at any time, can be found here.
Here's a list of changes I made to the original file:
- comments and continuation line
- ... is now identified as a continuation line character
- comments after the continuation line character do not disrupt it's highlight
- continuation lines characters are ignored if they are between single quotes
- shebang line
- now it's defined by the default configuration as being such instead of just a comment
- block comments
- added #{ and #} to the list of possibilities for block comments
- highlights correctly when block comments are nested
- operators
- now are highlighted (not only simple arithmetic operators, this includes element by element, transpose operator, autoincrement, assignment and logical operators)
- functions
- added a bunch of functions (I was told by one of the previous developers of this file the reason why only a few functions were highlighted. The thing is that with time, some functions are deprecated and removed from octave. However, the gtksourceview developers won't remove them from the list of highlighted functions to maintain backward compatibility. That's understandable, so I only picked functions that also exist in Matlab which is already a much larger number than the before)
- just to make it look pretty I mixed some very similar functions into one such as "(a)?sin(d|h)?"
- removed 'ans' from the list of functions and highlighted it as a variable
- metadata (it's the block that tells the text editor what to do when you for example automatically comment a line)
- added start and end of block comments start to the list (can someone test this please? I don't know a text editor that uses this)
- changed default for line comment from % to # (as asked from one of octave developers)
- pkg as preprocessor
- if pkg is not called 'like a function' (i.e. pkg ("load",..)) it's highlighted as preprocessor (in similarity to the 'use' function in Perl)
- constants/functions
- functions such as Inf, pi, NaN which can be called with no arguments to return a constant value, are highlighted as constants in those situations but still as functions if followed by opening parenthesis
- data types
- the function handle character '@' is now highlighted
- true/false as functions
- are highlighted as boolean unless followed by opening parenthesis, in which case are highlighted as functions
- keywords
- added the keywords, persistent, replot, static, varargin, varargout
- removed the keywords assert, nargin, nargout and moved them to be highlighted as functions
- strings
- added a printf regexp that should identify its formatting (copied it from the C.lang file)
- added an escape regexp that should escape only some stuff, not whatever's right after an \ (also copied it from the C.lang file)
Note: some of the changes I made most likely won't have any impact visually. For example, previously, the shebang line was highlighted as just a comment. But the default file has a style specific for it so I changed. However, the style for the shebang line is sometimes the same as the style for comments so you may not see a difference (I know I don't).
Any opinion and testing will be most welcome. Please say something, even if just to say that it works good so I know it has been tested.
Thanks in advance
EDIT 1: Changed the attachment for my latest octave.lang file
EDIT 2: Changed the attachment again to support classes
EDIT 3: Added attachment for octave 3.4
EDIT 4: Added note that was finally added to gtksourceview trunk
Bookmarks