Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get proper text-color-highlighting for Fortran 90 in Sublime Text 2?

There are a couple of links on sublime forum, on how to get Sublime Text 2 to work with Fortran 90 here http://www.sublimetext.com/forum/viewtopic.php?f=4&t=770, but they don't quite seem to work as the comment identifier "!" is not treated well.

I quickly assembled a solution using the original suggested Punchcard.tmLanguage file and modifying the first block in dictionary to treat "!" as comment (available here: https://gist.github.com/4209445).

Sublime Text 2 is a great text editor and having it support Fortran might be helpful for many people in Theoretical physics and Finance. So if anyone knows a better solution, please let me know.

Thanks!

like image 761
Timur B Avatar asked Dec 04 '12 23:12

Timur B


People also ask

How do you highlight text in Sublime Text?

đź–Ť Text Marker (Highlighter) Simply use Alt + Space to mark selected text.

Why is my code in Sublime Text not colored?

If you are just opening new files and pasting text in, the default syntax is “Plain Text”, thus no highlighting. You can set the syntax in the buffer by opening the command palette and searching for "Set Syntax: ".

Does Sublime Text support Fortran?

Modern-Fortran syntaxModern-Fortran is a Sublime Text language syntax for highlighting of Fortran code. It highlights modern Fortran (Fortran 90 and newer) and incorporates features introduced in Fortran 2003, 2008, and 2018.


2 Answers

The plugin at the fortran.tmBundle works for me. I created a Fortran subfolder in Packages and put all the files in the tmBundle there (not just the .tmLanguage files). It selects Fortran - Punchcard as the default type for .for and Fortran - Modern for .f90 files. These both treat ! just fine on my system - what problem are you having?

like image 197
bananafish Avatar answered Sep 19 '22 21:09

bananafish


I also use Fortran (Modern) with Sublime Text (now I'm using version 3) and there was just a little glitch handling comments. Look at this example:

As you can see, the second line starts with an exclamation mark, but it's not recognized. But if I start the first line with "! " (including a space), then everything works:

If I put a dash after the ! of the second line, it reconizes it as a comment, but the problem goes to the third line:

I don't understand the language of the syntax file, but I've looked at the MinimalFortran package to fix this (this package works great and can be installed using Package Control, but it misses lots of syntaxes). I just changed the

<string>!-</string> 

to

<string>[!]</string> 

on the "Fortran - Modern.tmLanguage" file and it all worked:

like image 37
Filipe Avatar answered Sep 18 '22 21:09

Filipe