Ken & Mike on the MATLAB Desktop

September 4th, 2007

Editor syntax colors for non-M file types

I recently had a customer ask me how to make his mex files have correct syntax highlighting. He had a file type that was not specified in our default preferences. This is very easy to fix using preferences.

Here is an example. I have to edit info.xml files a lot because one of the things that I work on is the start button. But when I edit an xml file there is no syntax highlighting.

If the editor hightlights the file as html, it does a pretty good job of syntax highlighting. To make xml files syntax highlight as an html file, go to the Editor Language preference panel (File->Preferences->Editor->Language). Select “HTML” from the Language combobox.

This will open the html highlighting panel. Near the bottom of this panel is a File Extensions list that shows which files will be highlighted using this set of colors.

Click on the “Add” button and type “xml” into the dialog.

Hit OK to exit the dialog and OK to exit the preference panel.

Close the file and re-open it to see the changes.

From this point forward, all xml files will be colored as html files. You can associate any file type with M, C/C++, Java, or HTML highlighting sets.

And because I predict that you will ask, we are considering linking xml files to the html color set by default in a future release.

16 Responses to “Editor syntax colors for non-M file types”

  1. impf replied on :

    I often work with the RealTimeWorkshop for CodeGeneration. Therefore, I have to edit tlc (target language compiler) files from time to time. Unfortunately, there is no syntax highlighting and I don’t want to have all tlc files colored as html files.
    To work around this issue I use a custom text editor… see Preferences–>Editor/Debugger–>Text editor
    Maybe this is useful for others. Moreover, it would be nice if you could add a tlc color set in a future release.

  2. Ken replied on :

    We hope to support TLC soon (we’re actively working on it). Though our syntax highlighting won’t fully highlight all C code, it should really help to visually distinguish between comments, macros and C code.

    Also note that we are actively working on full XML support - so hopefully you won’t need to follow these steps in the future!

    -Ken

  3. Mansour replied on :

    Hello Ken,
    Is there any news on TLC highlighting? Can we get it as an add on for older version of Matlab ( I am working with matlab R 2007b) or should we wait till next release of matlab (R2008a).

    Best regards
    Mansour

  4. Ken replied on :

    Hi Mansour,

    TLC Syntax highlighting will be part of the next release (R2008a) scheduled for release sometime in March (check out our release schedule here). There won’t be any way to get this new functionality in earlier releases of MATLAB, so you’ll definitely need the new version.

    Let us know how it works out for you!

    -Ken

  5. Ken replied on :

    @Mansour (comment 3299): R2008a has been released! The MATLAB Editor now supports syntax highlighting for TLC files. See the Real-Time Workshop 7.1 feature summary for a list of all RTW’s new features.

    Check out the full release notes here.

    -Ken

  6. hUser replied on :

    With regards to the editor and colors, am I the only one who can barely see the faint red right size column limit? I wish there was a way to change the color. I can barely see it and I find it very useful. Thanks.

  7. Michael Katz replied on :

    That is an excellent point. I’ll enter an enhancement request for us to consider in a future release.

  8. Bjoern replied on :

    Hi,

    As all the other matlab users out there who have to work with different programming languages - I would really appreciate if you could add syntax highlighting for more languages in the matlab editor. For me syntax highlighting for fortran (90 and 77), shell-scripts and make files would already very useful - so that I do not need to split my screen in parts for matlab and emacs so often :-).

    Bjoern

  9. Ken replied on :

    Hi Bjoern,

    We’re currently working hard to make it easier to add support for additional languages in the MATLAB Editor.

    Thanks for the feedback!
    -Ken

  10. junziyang replied on :

    I also think that Fortran Syntax highlighting is very useful.

  11. Scott replied on :

    Is there any way to modify which keywords are highlighted in which color in the various editor language profiles? If not, perhaps opening this up would allow developers to create custom schemes for their particular preferences.

    The one thing I am most interested in being able to do is have parentheses and braces appear in different colors as they are often very hard to distinguish (particularly on monitors set to high resolutions).

  12. Ken replied on :

    Hi Scott,

    You can’t change which words are highlighted, though you can change the color of the highlighted words. The brace colors are not changeable either. Please submit an enhancement request here.

    -Ken

  13. Igal replied on :

    Hi All,

    Does any one know how I can add an additional language and a custom syntax coloring for that language? Something similar to what is usually done in Crimson Editor?

    I really miss Verilog and VHDL syntax highlighting, especially since both can be generated in SImulink HDL Coder, but require 3rd party editor to be conviniently readable.
    I don’t mind making such syntax highliting script myslef, and posting it at Matlab Central, provided I knew its fromat how to add it to the Matlab Editor.

    Igal.

  14. Ken replied on :

    Hi Igal,

    The MATLAB Editor doesn’t currently support pluginging in custom syntax highlighting. We are currently working to make this possible.

    -Ken

  15. Igal replied on :

    Hi Ken,

    Great. Just don’t forget to note it in the release details :) So I could start making my HDL syntax highlight script.

    Regards,
    Igal.

  16. Tom Clark replied on :

    junziyang and others,

    I agree FORTRAN syntax in the matlab editor would be really good, but in the meantime you can customise editors like gedit to fortran highlighting specific to mex files.

    I’ve published an example on the file exchange:
    http://www.mathworks.com/matlabcentral/fileexchange/24332

    Cheers!

    Tom

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Ken & Mike work on the MATLAB Desktop team.
  • DP: Hi i have a problem with ezplot3, i want to plot more than i curve in the same graph but hold on command...
  • Ken: Hi Arsalan, Unfortunately there is no way to get the new Editor API in older versions of MATLAB. -Ken
  • Arsalan: Hi, I am very excited about the MATLAB API for editor because right now i am working on a project and i need...
  • Johannes: Since I started using matlab-emacs some days ago I never experienced Emacslink. But I experienced some...
  • Francisco J. Beron-Vera: Hi all, I have recently learned about ViEmu (http://www.vimemu.c om) which, for Vi/Vim...
  • OysterEngineer: When I first learned of the Publish feature in MatLab, I thought it might be useful to help to...
  • Ken: Hi Herve, I’m not quite sure what you mean by “stand-alone&# 8221; mode? -Ken
  • Herve: I wonder when the publish fonction will be supported in standalone mode.
  • Mike: Ravi, What you described should work as far I understand it. Please follow up with technical support. With a...
  • Mike: @Daniel, Thanks for that note.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.