Sublime Forum

A lot of problems with improving minimalfortran

#1

first:
I want to add support for openMP in fortran with sublime text3.

The lines I want to match is:

!$OMP some key words

I got a package named minimalfortran, copied MinimalFortran.JSON-tmLanguage to my packages/user folder, add these lines to the end of it.

  {
      "comment": "openMP controls",
      "match": "!\\$OMP .+",
      "name": "keyword.control.openMP.fortran"
  },

It does not work, I thought it may because of these lines:

 {
      "begin": "!]",
      "beginCaptures": {
          "0": {
              "name": "punctuation.definition.comment.fortran"
          }
      },
      "end": "$\\n?",
      "name": "comment.line.asterisk.fortran",
      "patterns": 
          {
              "match": "\\\\\\s*\\n"
          }
      ]
  },

It seems I can not overwrite it, or something wrong with my tmlanguage syntax.

second:
I want to add a shortcut for comment / uncomment in Fortran, how can I do this?

0 Likes

#2

Hi,
Quite old post, but still no answer. I advice you to change the behavior of the comment match to prevent it matching !$OMP (i.e., don’t match ! if it is followed by $OMP) like this :

{ "begin": "!](?!\\$OMP)", // by the way, the brakets ] around ! seems to be useless. Anyone can explain this ? "beginCaptures": { "0": { "name": "punctuation.definition.comment.fortran" } }, "end": "$\\n?", "name": "comment.line.exclamation.fortran", // they kept 'asterix' that I replaced by 'exclamation' for naming consitency "patterns": { "match": "\\\\\\s*\\n" } ] },
then you can add a similar behaviour for mathing !$OMP :

{ "begin": "!]\\$OMP)", "beginCaptures": { "0": { "name": "keyword.control.openMP.fortran" // hilight the !$OMP keyword only ... } }, "end": "$\\n?", "name": "comment.control.openMP.fortran", // and the rest of the line differently, if desired "patterns": { "match": "\\\\\\s*\\n" } ] },
Peace

0 Likes

#3

Hi,
Did you manage to toggle comments ?

Thanks!

0 Likes

#4

Regarding the initial requestion, usually it is better to just insert your more specific pattern before the more general pattern that matches more cases. The reason for this is that ST will chose the rule that comes first in the “patterns” list if two or more match at the same character. So, you want the more specific rules to override the more general ones.

For comment toggling, see docs.sublimetext.info/en/latest/ … ments.html

0 Likes