View Poll Results: Do you think this syntax highlight for octave works good?

Voters
4. You may not vote on this poll
  • Yes

    4 100.00%
  • No (please tell me what's wrong so I can try to change it)

    0 0%
Results 1 to 10 of 10

Thread: Call for gedit and octave users

  1. #1
    Join Date
    Dec 2007
    Location
    In the lab
    Beans
    122

    Call for gedit and octave users

    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
    Attached Files Attached Files
    Last edited by carandraug; May 28th, 2011 at 06:06 PM. Reason: Added lang file octave 3.4

  2. #2
    Join Date
    Dec 2007
    Location
    In the lab
    Beans
    122

    Re: Call for gedit and octave users

    *bump*

  3. #3
    Join Date
    Dec 2007
    Location
    In the lab
    Beans
    122

    Re: Call for gedit and octave users

    Made a few more changes, including highlight data type functions and function handles. Also if a struct field that has the same name of a function, will no longer be highlighted as function.

  4. #4
    Join Date
    Jan 2008
    Location
    Auckland, New Zealand
    Beans
    3,129
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Call for gedit and octave users

    It works really well for me thanks, I couldn't find any problems with it. I don't think I do anything very advanced though.

  5. #5
    Join Date
    Dec 2009
    Beans
    3

    Re: Call for gedit and octave users

    I moved the untar-ed file in the specified folder, and nothing changed. Still no highlighting for octave .m files.

    gvim works great with octave after following the instructions here:
    http://www.vim.org/scripts/script.php?script_id=1591
    However, I was looking something for gedit?

    N.

  6. #6
    Join Date
    Dec 2007
    Location
    In the lab
    Beans
    122

    Re: Call for gedit and octave users

    Quote Originally Posted by nadeem.ansari View Post
    I moved the untar-ed file in the specified folder, and nothing changed. Still no highlighting for octave .m files.

    gvim works great with octave after following the instructions here:
    http://www.vim.org/scripts/script.php?script_id=1591
    However, I was looking something for gedit?

    N.
    Make sure you have gtksourceview installed
    Code:
    sudo apt-get install libgtksourceview2.0-0
    Then, untar this file in the mentioned directory

    Code:
    /usr/share/gtksourceview-2.0/language-specs
    Finally, open an octave file in gedit and if it's not highlighted (or incorrectly highlighted), go to the menu

    View --> Highlight mode --> Scientific --> Octave

  7. #7
    Join Date
    Jul 2010
    Beans
    7

    Re: Call for gedit and octave users

    Thank you carandraug, I'm using your file, much better than the one suited with ubuntu. I use also qtoctave and it's editor, but there is sometihng wrong, cause the blank space is not as large as the monospace character in that, and sometimes it has a strange behavior! How do you use octave? Simply terminal + gedit?

  8. #8
    Join Date
    Dec 2007
    Location
    In the lab
    Beans
    122

    Re: Call for gedit and octave users

    Quote Originally Posted by liviogasp View Post
    Thank you carandraug, I'm using your file, much better than the one suited with ubuntu.
    The one suited with Ubuntu is the one that the gtksourceview developers have available. I already submitted the patch but they haven't act on it yet. Could you consider comment on this bug report saying that you approve of the patch? Just to try and get some attention from the developers.

    Quote Originally Posted by liviogasp View Post
    How do you use octave? Simply terminal + gedit?
    Yes. I find gedit to be a great text editor, no matter what the CLI purists may say. You can use the embedded terminal plugin if you don't want to keep Alt-Tab between the octave console and the text editor.

  9. #9
    Join Date
    Dec 2007
    Location
    In the lab
    Beans
    122

    Re: Call for gedit and octave users

    I've changed the attachment. This new octave.lang file has support for classes (which among other things, allows the spell checker to be active only on strings). It also fixes a small bug where '' in single quotes was identified has end a start of a new string instead of an escaped single quote.

    Hopefully it will also be useful for other users.

  10. #10
    Join Date
    Dec 2007
    Location
    In the lab
    Beans
    122

    Re: Call for gedit and octave users

    Added a new lang file for the new octave 3.4. It highlights some of the new functions
    • curl
    • daspect
    • divergence
    • erfcx
    • fileread
    • fminbnd
    • merge
    • onCleanup
    • pbaspect
    • pie3
    • randi
    • reset
    • rsf2csf
    • saveas
    • strread
    • textread
    • uigetdir
    • uigetfile
    • uimenu
    • uiputfile
    • whitebg


    Also removed the following functions from highlight since they have been removed or deprecated (will be removed on 3.6 or 3.8).
    • setstr
    • str2mat
    • values


    I also added the class keyword to the keywords group.
    Last edited by carandraug; April 1st, 2011 at 04:14 PM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •